List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:net.vershinin.flashmind.FlashExportWizard.java
protected void saveHtml(IMindMap mindMap) { VelocityEngine engine = initVelocityEngine(); Template template = engine.getTemplate(TEMPLATE_NAME); VelocityContext context = new VelocityContext(); context.put(KEY_TITLE, mindMap.getCentralTopic().getTitleText()); context.put(KEY_JS_FILE, FilenameUtils.concat(resourcesDirectory, JS_FILE_NAME)); String mindmapFile = FilenameUtils.concat(resourcesDirectory, mindmapFilename); context.put(KEY_MINDMAP_FILE, FilenameUtils.separatorsToUnix(mindmapFile)); String swfFilename = FilenameUtils.concat(resourcesDirectory, SWF_FILE_NAME); context.put(KEY_SWF_FILE, FilenameUtils.separatorsToUnix(swfFilename)); StringWriter writer = new StringWriter(); template.merge(context, writer);/*from ww w . ja v a 2 s . c o m*/ try { FileWriter fw = new FileWriter(getTargetPath()); fw.write(writer.toString()); fw.close(); } catch (IOException e) { handleExportException(e); } }
From source file:nl.geodienstencentrum.maven.plugin.sass.AbstractSassMojo.java
/** * Builds the basic sass script./*from ww w .ja v a 2s. c o m*/ * * @param sassScript * the sass script * @throws MojoExecutionException * the mojo execution exception */ protected void buildBasicSassScript(final StringBuilder sassScript) throws MojoExecutionException { final Log log = this.getLog(); sassScript.append("require 'rubygems'\n"); if (this.gemPaths.length > 0) { sassScript.append("env = { 'GEM_PATH' => [\n"); for (final String gemPath : this.gemPaths) { sassScript.append(" '").append(gemPath).append("',\n"); } final String gemPath = System.getenv("GEM_PATH"); if (gemPath != null) { for (final String p : gemPath.split(File.pathSeparator)) { sassScript.append(" '").append(p).append("',\n"); } } /* remove trailing comma+\n */ sassScript.setLength(sassScript.length() - 2); sassScript.append("\n] }\n"); sassScript.append("Gem.paths = env\n"); } for (final String gem : this.gems) { sassScript.append("require '").append(gem).append("'\n"); } sassScript.append("require 'sass/plugin'\n"); sassScript.append("require 'java'\n"); if (this.useCompass) { log.info("Running with Compass enabled."); log.warn( "Compass support is deprecated, it will be removed in version 3.0, see https://github.com/GeoDienstenCentrum/sass-maven-plugin/issues/77"); sassScript.append("require 'compass'\n"); sassScript.append("require 'compass/exec'\n"); sassScript.append("require 'compass/core'\n"); sassScript.append("require 'compass/import-once'\n"); if (compassConfigFile != null) { sassScript.append("Compass.add_project_configuration '").append(compassConfigFile.getAbsolutePath()) .append("'\n"); } else { sassScript.append("Compass.add_project_configuration \n"); } this.sassOptions.put("load_paths", "Compass.configuration.sass_load_paths"); } // Get all template locations from resources and set option // 'template_location' and // 'css_location' (to override default "./public/stylesheets/sass", // "./public/stylesheets") // remaining locations are added later with 'add_template_location' final Iterator<Entry<String, String>> templateLocations = this.getTemplateLocations(); if (templateLocations.hasNext()) { final Entry<String, String> location = templateLocations.next(); this.sassOptions.put("template_location", "'" + location.getKey() + "'"); this.sassOptions.put("css_location", "'" + location.getValue() + "'"); } // If not explicitly set place the cache location in the target dir if (!this.sassOptions.containsKey("cache_location")) { final File sassCacheDir = new File(this.buildDirectory, "sass_cache"); final String sassCacheDirStr = sassCacheDir.toString(); this.sassOptions.put("cache_location", "'" + FilenameUtils.separatorsToUnix(sassCacheDirStr) + "'"); } // Add the plugin configuration options sassScript.append("Sass::Plugin.options.merge!(\n"); for (final Iterator<Entry<String, String>> entryItr = this.sassOptions.entrySet().iterator(); entryItr .hasNext();) { final Entry<String, String> optEntry = entryItr.next(); final String opt = optEntry.getKey(); final String value = optEntry.getValue(); sassScript.append(" :").append(opt).append(" => ").append(value); if (entryItr.hasNext()) { sassScript.append(","); } sassScript.append('\n'); } sassScript.append(")\n"); // add remaining template locations with 'add_template_location' (need // to be done after options.merge) while (templateLocations.hasNext()) { final Entry<String, String> location = templateLocations.next(); sassScript.append("Sass::Plugin.add_template_location('").append(location.getKey()).append("', '") .append(location.getValue()).append("')\n"); } if (this.useBourbon) { log.info("Running with Bourbon enabled."); final String bDest = this.buildDirectory + "/bourbon"; this.extractBourbonResources(bDest); // sassScript.append("require 'bourbon'\n"); sassScript.append("Sass::Plugin.add_template_location('").append(bDest) .append("/app/assets/stylesheets', '").append(destination).append("')\n"); } // set up sass compiler callback for reporting sassScript.append( "Sass::Plugin.on_compilation_error {|error, template, css| $compiler_callback.compilationError(error.message, template, css) }\n"); sassScript.append( "Sass::Plugin.on_updated_stylesheet {|template, css| $compiler_callback.updatedStylesheeet(template, css) }\n"); sassScript.append( "Sass::Plugin.on_template_modified {|template| $compiler_callback.templateModified(template) }\n"); sassScript.append( "Sass::Plugin.on_template_created {|template| $compiler_callback.templateCreated(template) }\n"); sassScript.append( "Sass::Plugin.on_template_deleted {|template| $compiler_callback.templateDeleted(template) }\n"); // make ruby give use some debugging info when requested if (log.isDebugEnabled()) { sassScript.append("require 'pp'\n"); sassScript.append("pp Sass::Plugin.options\n"); if (this.useCompass) { sassScript.append("pp Compass.base_directory\n"); sassScript.append("pp Compass::Core.base_directory\n"); sassScript.append("pp Compass::configuration\n"); } } }
From source file:nl.geodienstencentrum.maven.plugin.sass.Resource.java
/** * Gets the source directories and target destinations. * * @param log//w w w . java 2 s .c om * the maven logging instance to use for messages * @return the directories and destinations, may be an empty map if the * source does not exist. */ public Map<String, String> getDirectoriesAndDestinations(final Log log) { final File sourceDirectory = new File(this.source.getDirectory()); final Map<String, String> result = new LinkedHashMap<>(); if (!sourceDirectory.exists()) { log.error("Specified sourcedirectory (" + sourceDirectory + ") does not exist."); return result; } // Scan for directories final DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(sourceDirectory); scanner.setIncludes(this.source.getIncludes().toArray(new String[this.source.getIncludes().size()])); scanner.setExcludes(this.source.getExcludes().toArray(new String[this.source.getExcludes().size()])); scanner.addDefaultExcludes(); scanner.scan(); result.put(FilenameUtils.separatorsToUnix(sourceDirectory.toString()), FilenameUtils.separatorsToUnix(this.destination.toString())); for (final String included : scanner.getIncludedDirectories()) { if (!included.isEmpty()) { final String subdir = StringUtils.difference(sourceDirectory.toString(), included); final File sourceDir = new File(sourceDirectory, included); File destDir = new File(this.destination, subdir); if (this.relativeOutputDirectory != null && !this.relativeOutputDirectory.isEmpty()) { destDir = new File(destDir, this.relativeOutputDirectory); } result.put(FilenameUtils.separatorsToUnix(sourceDir.toString()), FilenameUtils.separatorsToUnix(destDir.toString())); } } return result; }
From source file:nl.mvdr.umvc3replayanalyser.controller.FileUtils.java
/** * Get the relative path from one file to another, specifying the directory separator. If one of the provided * resources does not exist, it is assumed to be a file unless it ends with '/' or '\'. * //from ww w. j a v a 2 s . co m * @param targetPath * targetPath is calculated to this file * @param basePath * basePath is calculated from this file * @param pathSeparator * directory separator; the platform default is not assumed so that we can test Unix behaviour when * running on Windows (for example) * @return relative path * @throws PathResolutionException * in case the paths are not related at all */ static String getRelativePath(String targetPath, String basePath, String pathSeparator) throws PathResolutionException { // Normalize the paths String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath); String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath); // Undo the changes to the separators made by normalization if (pathSeparator.equals("/")) { normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath); } else if (pathSeparator.equals("\\")) { normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath); } else { throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'"); } String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator)); String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator)); // First get all the common elements. Store them as a string, // and also count how many of them there are. StringBuffer common = new StringBuffer(); int commonIndex = 0; while (commonIndex < target.length && commonIndex < base.length && target[commonIndex].equals(base[commonIndex])) { common.append(target[commonIndex] + pathSeparator); commonIndex++; } if (commonIndex == 0) { // No single common path element. This most // likely indicates differing drive letters, like C: and D:. // These paths cannot be relativized. throw new PathResolutionException("No common path element found for '" + normalizedTargetPath + "' and '" + normalizedBasePath + "'"); } // The number of directories we have to backtrack depends on whether the base is a file or a dir // For example, the relative path from // // /foo/bar/baz/gg/ff to /foo/bar/baz // // ".." if ff is a file // "../.." if ff is a directory // // The following is a heuristic to figure out if the base refers to a file or dir. It's not perfect, because // the resource referred to by this path may not actually exist, but it's the best I can do boolean baseIsFile = true; File baseResource = new File(normalizedBasePath); if (baseResource.exists()) { baseIsFile = baseResource.isFile(); } else if (basePath.endsWith(pathSeparator)) { baseIsFile = false; } StringBuffer relative = new StringBuffer(); if (base.length != commonIndex) { int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex; for (int i = 0; i < numDirsUp; i++) { relative.append(".." + pathSeparator); } } relative.append(normalizedTargetPath.substring(common.length())); return relative.toString(); }
From source file:ome.formats.importer.targets.TemplateImportTarget.java
@Override public IObject load(OMEROMetadataStoreClient client, ImportContainer ic) throws Exception { // Now we create an annotation for delaying parsing of the template // until we can receive server-side pre-processed paths. IUpdatePrx update = client.getServiceFactory().getUpdateService(); CommentAnnotation ca = new CommentAnnotationI(); ca.setNs(omero.rtypes.rstring(NSTARGETTEMPLATE.value)); ca.setTextValue(omero.rtypes.rstring(this.target)); // Here we save the unix-styled path to the directory that the target // file was stored in. Server-side, further directories should be // stripped from this based on the pattern and *that* will be // run against the regex "template". File dir = ic.getFile().getParentFile(); String desc = FilenameUtils.separatorsToUnix(dir.toString()); ca.setDescription(omero.rtypes.rstring(desc)); ca = (CommentAnnotation) update.saveAndReturnObject(ca); log.debug("Created annotation {}", ca.getId().getValue()); return ca;/*from ww w . j av a 2s. c om*/ }
From source file:org.abstracthorizon.proximity.impl.AbstractProximity.java
public void copyItem(ProximityRequest source, ProximityRequest target) throws ItemNotFoundException, AccessDeniedException, NoSuchRepositoryException, RepositoryNotAvailableException { logger.debug("Got copyItem with {} -> {}", source, target); Item item = retrieveItem(source);/*from w w w . j a v a 2s .c o m*/ ItemProperties itemProps = item.getProperties(); itemProps.setDirectoryPath( FilenameUtils.separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(target.getPath()))); itemProps.setName(FilenameUtils.getName(target.getPath())); itemProps.setRepositoryId(target.getTargetedReposId()); itemProps.setRepositoryGroupId(target.getTargetedReposGroupId()); storeItem(target, item); }
From source file:org.abstracthorizon.proximity.impl.AbstractProximity.java
public void storeItem(ProximityRequest request, Item item) throws AccessDeniedException, NoSuchRepositoryException, RepositoryNotAvailableException { logger.debug("Got storeItem for {}", request); String targetRepoId = request.getTargetedReposId(); List pathList = ProximityUtils.explodePathToList(request.getPath()); if (targetRepoId == null) { // first repo if not targeted and store if (isEmergeRepositoryGroups()) { if (pathList.size() == 0) { // cannot store on root if emergeGroups, error throw new AccessDeniedException(request, "Cannot store item on the root when emergeRepositoryGroups are enabled!"); }/* w ww. j ava 2 s . c o m*/ // get group, get first repo of the group and store String groupId = (String) pathList.get(0); if (repositoryGroups.containsKey(groupId)) { List repositoryGroupOrder = (List) repositoryGroups.get(groupId); targetRepoId = (String) repositoryGroupOrder.get(0); } else { throw new NoSuchRepositoryException("group " + request.getTargetedReposGroupId()); } } else { // get first repo and store targetRepoId = (String) repositoryOrder.get(0); } } if (repositories.containsKey(targetRepoId)) { Repository repo = (Repository) repositories.get(targetRepoId); ProximityRequest mangledRequest = mangleItemRequest(request); ItemProperties itemProperties = item.getProperties(); // set the mangled path for store itemProperties.setDirectoryPath(FilenameUtils .separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(mangledRequest.getPath()))); repo.storeItem(mangledRequest, item); } else { throw new NoSuchRepositoryException(targetRepoId); } }
From source file:org.abstracthorizon.proximity.impl.ProximityUtils.java
/** * Mangle item paths for emerge groups./* ww w . jav a2s . c o m*/ * * @param items the items */ public static void mangleItemPathsForEmergeGroups(List items) { for (Iterator i = items.iterator(); i.hasNext();) { ItemProperties ip = (ItemProperties) i.next(); if (ip.getDirectoryPath().equals(ItemProperties.PATH_ROOT)) { // make /groupId as path ip.setDirectoryPath(ItemProperties.PATH_ROOT + ip.getRepositoryGroupId()); } else { // make /groupId/... as path WITHOUT trailing / ip.setDirectoryPath(FilenameUtils.separatorsToUnix(FilenameUtils.normalizeNoEndSeparator( ItemProperties.PATH_ROOT + ip.getRepositoryGroupId() + ip.getDirectoryPath()))); } } }
From source file:org.abstracthorizon.proximity.metadata.AbstractProxiedItemPropertiesFactory.java
/** * Expand default item properties.// w ww . j ava2s. c o m * * @param path the path * @param ip the ip * @param file the file */ protected final void expandDefaultItemProperties(String path, ItemProperties ip, File file) { ip.setDirectoryPath(FilenameUtils.separatorsToUnix(FilenameUtils.getFullPathNoEndSeparator(path))); if ("".equals(ip.getDirectoryPath())) { ip.setDirectoryPath(ItemProperties.PATH_ROOT); } ip.setName(FilenameUtils.getName(path)); ip.setDirectory(file.isDirectory()); ip.setFile(file.isFile()); ip.setLastModified(new Date(file.lastModified())); if (file.isFile()) { String ext = FilenameUtils.getExtension(path); if (ext != null) { ip.setExtension(ext); } ip.setSize(file.length()); } else { ip.setSize(0); } ip.setLastScanned(new Date()); }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java
/** * Concat paths.// ww w . java 2s . c om * * @param path1 the path1 * @param path2 the path2 * * @return the string */ protected String concatPaths(String path1, String path2) { String result = FilenameUtils.concat(path1, path2); return FilenameUtils.separatorsToUnix(result); }