List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:org.jamwiki.parser.image.ImageUtil.java
/** * Given a file URL and a maximum dimension, return a relative path for the file. *//*from w ww . j ava2 s . c om*/ private static String buildImagePath(String currentUrl, int originalWidth, int scaledWidth) { if (originalWidth <= scaledWidth) { // no resizing necessary, return the original URL return currentUrl; } String path = FilenameUtils.normalize(RESIZED_IMAGE_SUBFOLDER + "/" + currentUrl); String dimensionInfo = "-" + scaledWidth + "px"; int pos = path.lastIndexOf('.'); if (pos != -1) { path = path.substring(0, pos) + dimensionInfo + path.substring(pos); } else { path += dimensionInfo; } return path; }
From source file:org.jasig.resourceserver.utils.aggr.ResourcesElementsProviderImpl.java
protected <T extends BasicInclude> String getElementPath(HttpServletRequest request, T basicInclude, String relativeRoot) {/*from w w w . j a va 2s . c o m*/ String path = basicInclude.getValue(); if (!resourcesDao.isAbsolute(basicInclude)) { path = FilenameUtils.normalize(relativeRoot + path); path = FilenameUtils.separatorsToUnix(path); if (logger.isDebugEnabled()) { logger.debug("translated relative path {} to {}", basicInclude.getValue(), path); } } else if (basicInclude.isResource()) { path = this.resolveResourceUrl(request, path); } return path; }
From source file:org.jboss.windup.interrogator.DirectoryInterrogationEngine.java
public DirectoryMetadata process(File outputDirectory, File targetDirectory) { //this will recurse all files from this directory; all but hidden directories. RecursiveDirectoryMetaFactory rdmf = new RecursiveDirectoryMetaFactory(targetDirectory); List<DirectoryMetadata> directories = new LinkedList<DirectoryMetadata>(); DirectoryMetadata root = rdmf.recursivelyExtract(); unfoldRecursion(root, directories);//from ww w . jav a 2 s . c om int i = 1; int j = directories.size(); for (DirectoryMetadata directoryMeta : directories) { LOG.info("Interrogating (" + i + " of " + j + "): " + directoryMeta.getRelativePath()); Collection<File> files = FileUtils.listFiles(directoryMeta.getFilePointer(), TrueFileFilter.INSTANCE, null); if (LOG.isDebugEnabled()) { LOG.debug(" Processing " + files.size() + " files within directory."); } if (outputDirectory != null) { String dirOutput = FilenameUtils.normalize(FilenameUtils.separatorsToSystem( outputDirectory.getAbsolutePath() + File.separatorChar + directoryMeta.getRelativePath())); directoryMeta.setArchiveOutputDirectory(new File(dirOutput)); } for (Interrogator<?> interrogator : interrogators) { for (File file : files) { if (file.isFile()) { LOG.debug("Processing file: " + file.getAbsolutePath()); TempSourceMetadata fileMeta = new TempSourceMetadata(file); fileMeta.setArchiveMeta(directoryMeta); LOG.debug("Set archive as: " + directoryMeta); interrogator.processFile(fileMeta); } } } i++; } return root; }
From source file:org.jboss.windup.reporting.ReportUtil.java
public static String calculateRelativePathToRoot(File reportDirectory, File htmlOutputPath) { Validate.notNull(reportDirectory, "Report directory is null, but a required field."); Validate.notNull(htmlOutputPath, "HTML output directory is null, but a required field."); String archiveOutput = FilenameUtils.normalize(reportDirectory.getAbsolutePath()); String htmlOutput = FilenameUtils.normalize(htmlOutputPath.getAbsolutePath()); if (LOG.isDebugEnabled()) { LOG.debug("archiveOutput: " + archiveOutput); LOG.debug("htmlOutput: " + htmlOutput); }/*w ww . j a v a 2s.c o m*/ String relative = StringUtils.removeStart(htmlOutput, archiveOutput); relative = StringUtils.replace(relative, "\\", "/"); int dirCount = (StringUtils.countMatches(relative, "/") - 1); String relPath = ""; for (int i = 0; i < dirCount; i++) { relPath += "../"; } return relPath; }
From source file:org.jboss.windup.reporting.ReportUtil.java
public static String calculateRelativePathFromRoot(File reportDirectory, File relativeFile) { String relPath = StringUtils.removeStart(FilenameUtils.normalize(relativeFile.getAbsolutePath()), FilenameUtils.normalize(reportDirectory.getAbsolutePath())); relPath = StringUtils.replace(relPath, "\\", "/"); relPath = StringUtils.removeStart(relPath, "/"); return relPath; }
From source file:org.jboss.windup.test.helpers.WindupTestCase.java
/** * <p>// w ww. ja v a2 s. c om * Run a test on a single {@link ArchiveMetadata} * </p> * * @param archiveMeta * {@link ArchiveMetadata} to test * @param expectedArchiveDecorations * expected decorations on the archive * @param expectedArchiveEntryDecorations * map of file paths to their expected decorations */ private void runArchiveMetaTest(ArchiveMetadata archiveMeta, String[] expectedArchiveDecorations, Map<String, String[]> expectedArchiveEntryDecorations) { Assert.assertNotNull("ArchiveMetadata should not be null", archiveMeta); if (expectedArchiveDecorations == null) { expectedArchiveDecorations = new String[0]; } if (expectedArchiveEntryDecorations == null) { expectedArchiveEntryDecorations = new HashMap<String, String[]>(); } // search the archive for the expected decorations Collection<AbstractDecoration> archiveDecorations = new ArrayList<AbstractDecoration>( archiveMeta.getDecorations()); for (String expectedArchiveDecoration : expectedArchiveDecorations) { boolean foundExpectedArchiveDecoration = false; // check entry decorators for expected decorator Iterator<AbstractDecoration> decorationsIter = archiveDecorations.iterator(); while (decorationsIter.hasNext() && !foundExpectedArchiveDecoration) { AbstractDecoration decoration = decorationsIter.next(); if (decoration.getDescription().equals(expectedArchiveDecoration)) { foundExpectedArchiveDecoration = true; // remove the matched decoration decorationsIter.remove(); } } Assert.assertTrue("Did not find expected archive decoration: '" + expectedArchiveDecoration + "' in '" + archiveMeta.getName() + "'", foundExpectedArchiveDecoration); } //remove all "hash" decorators becuase they are always expected Iterator<AbstractDecoration> unexpecedDecorationsIter = archiveDecorations.iterator(); while (unexpecedDecorationsIter.hasNext()) { if (unexpecedDecorationsIter.next() instanceof Hash) { unexpecedDecorationsIter.remove(); } } // error if found any unexpected decorations on the archive if (!archiveDecorations.isEmpty()) { StringBuffer unexpectedArchiveDecorators = new StringBuffer(); unexpectedArchiveDecorators .append("The archive '" + archiveMeta.getName() + "' has unexpected decorators:\n"); for (AbstractDecoration unexpectedDecoration : archiveDecorations) { unexpectedArchiveDecorators.append("\t"); unexpectedArchiveDecorators.append(unexpectedDecoration); unexpectedArchiveDecorators.append("\n"); } Assert.fail(unexpectedArchiveDecorators.toString()); } Set<FileMetadata> entries = new HashSet<FileMetadata>(archiveMeta.getEntries()); Set<String> expectedEntryPaths = expectedArchiveEntryDecorations.keySet(); for (String expectedEntryFilePath : expectedEntryPaths) { boolean foundEntry = false; // search entries for expected entry Iterator<FileMetadata> entriesIter = entries.iterator(); while (entriesIter.hasNext()) { FileMetadata entry = entriesIter.next(); // if entry matches expected entry path search for expected // decorators on that entry String relativeEntrypath = FilenameUtils.normalize(entry.getPathRelativeToArchive()); if (relativeEntrypath.equals(FilenameUtils.normalize(expectedEntryFilePath))) { foundEntry = true; // remove this entry since it has matched entriesIter.remove(); // for each expected entry decorator see if it exists String[] expectedEntryDecorators = expectedArchiveEntryDecorations.get(expectedEntryFilePath); Collection<AbstractDecoration> entryDecorations = new ArrayList<AbstractDecoration>( entry.getDecorations()); for (String expectedEntryDecorator : expectedEntryDecorators) { boolean foundExpectedEntryDecorator = false; // check entry decorators for expected decorator Iterator<AbstractDecoration> decorationsIter = entryDecorations.iterator(); while (decorationsIter.hasNext() && !foundExpectedEntryDecorator) { AbstractDecoration decoration = decorationsIter.next(); if (decoration.getDescription().equals(expectedEntryDecorator)) { foundExpectedEntryDecorator = true; // remove the matched decoration decorationsIter.remove(); } } Assert.assertTrue( "Did not find expected archive entry decoration '" + expectedEntryDecorator + "' on '" + expectedEntryFilePath + "' in '" + archiveMeta.getName() + "'", foundExpectedEntryDecorator); } // error if found any unexpected decorations on the expected // entry if (!entryDecorations.isEmpty()) { StringBuffer unexpectedEntryDecorators = new StringBuffer(); unexpectedEntryDecorators.append("The entry '" + expectedEntryFilePath + "' in '" + archiveMeta.getName() + "' contained unexpected entries:\n"); for (AbstractDecoration unexpectedDecoration : entryDecorations) { unexpectedEntryDecorators.append("\t"); unexpectedEntryDecorators.append(unexpectedDecoration.getDescription()); unexpectedEntryDecorators.append("\n"); } Assert.fail(unexpectedEntryDecorators.toString()); } } } Assert.assertTrue("Did not find expected archive entry in '" + archiveMeta.getName() + "' for '" + expectedEntryFilePath + "'", foundEntry); } // error if found any unexpected entries if (!entries.isEmpty()) { StringBuffer unexpectedEntries = new StringBuffer(); unexpectedEntries.append("The archive '" + archiveMeta.getName() + "' contained unexpected entries:\n"); for (FileMetadata entry : entries) { unexpectedEntries.append("\t"); unexpectedEntries.append(entry); unexpectedEntries.append("\n"); } Assert.fail(unexpectedEntries.toString()); } }
From source file:org.jenkinsci.plugins.vssj.VssChangeLogEntry.java
public Object getFilenameForUrl() { String s = FilenameUtils.normalize(this.logEntry.getFilename()); return s; }
From source file:org.jmecsoftware.plugins.tests.utils.ReportUtils.java
public static List<File> getReports(Configuration settings, final File moduleBaseDir, String reportPathPropertyKey) { List<File> reports = new ArrayList<>(); List<String> reportPaths = Arrays.asList(settings.getStringArray(reportPathPropertyKey)); if (!reportPaths.isEmpty()) { List<String> includes = new ArrayList<>(); for (String reportPath : reportPaths) { // Normalization can return null if path is null, is invalid, or is a path with back-ticks outside known directory structure String normalizedPath = FilenameUtils.normalize(reportPath); if (normalizedPath != null && new File(normalizedPath).isAbsolute()) { includes.add(normalizedPath); continue; }//from w ww. jav a 2s.c o m // Prefix with absolute module base dir, attempt normalization again -- can still get null here normalizedPath = FilenameUtils .normalize(moduleBaseDir.getAbsolutePath() + File.separator + reportPath); if (normalizedPath != null) { includes.add(normalizedPath); continue; } LOG.debug("Not a valid report path '{}'", reportPath); } LOG.debug("Normalized report includes to '{}'", includes); // Includes array cannot contain null elements DirectoryScanner directoryScanner = new DirectoryScanner(); directoryScanner.setIncludes(includes.toArray(new String[includes.size()])); directoryScanner.scan(); String[] includeFiles = directoryScanner.getIncludedFiles(); LOG.info("Scanner found '{}' report files", includeFiles.length); for (String found : includeFiles) { reports.add(new File(found)); } if (reports.isEmpty()) { LOG.warn("Cannot find a report for '{}'", reportPathPropertyKey); } else { LOG.info("Parser will parse '{}' report files", reports.size()); } } else { LOG.info("Undefined report path value for key '{}'", reportPathPropertyKey); } return reports; }
From source file:org.jwebsocket.config.JWebSocketConfig.java
/** * @return the jWebSocketHome (environment variable or command line option) *//*ww w.ja v a 2 s . c om*/ public static String findJWebSocketHome() { // check Java property first // check if instance mJWebSocketHome is still null (not yet set) if (null == mJWebSocketHome) { mJWebSocketHome = System.getProperty(JWebSocketServerConstants.JWEBSOCKET_HOME); if (null != mJWebSocketHome) { System.out.println(JWebSocketServerConstants.JWEBSOCKET_HOME + ": Using property " + JWebSocketServerConstants.JWEBSOCKET_HOME + ": " + mJWebSocketHome); } } // if no Java property check environment variable if (null == mJWebSocketHome) { mJWebSocketHome = System.getenv(JWebSocketServerConstants.JWEBSOCKET_HOME); if (null != mJWebSocketHome) { System.out.println(JWebSocketServerConstants.JWEBSOCKET_HOME + ": Using environment variable " + JWebSocketServerConstants.JWEBSOCKET_HOME + ": " + mJWebSocketHome); } } // check current folders (only if not Web Application) if (!isWebApp() && null == mJWebSocketHome) { IOFileFilter lFileFilter = new WildcardFileFilter("jWebSocketServer*.jar"); IOFileFilter lDirFilter; lDirFilter = FileFilterUtils.directoryFileFilter(); Collection<File> lFiles; File lDir; // we are in development mode (NetBeans)? try { lDir = new File("../../../rte/jWebSocket-1.0/libs"); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (null != lFiles && !lFiles.isEmpty()) { lDir = new File("../../../rte/jWebSocket-1.0"); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } else { // we are in the /libs folder? try { lDir = new File("."); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (null != lFiles && !lFiles.isEmpty()) { lDir = new File("../"); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } else { // we are in the /bin folder? try { lDir = new File("../libs"); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (null != lFiles && !lFiles.isEmpty()) { lDir = new File("../"); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } else { // we are in the base folder? try { lDir = new File("libs"); lFiles = FileUtils.listFiles(lDir, lFileFilter, lDirFilter); } catch (Exception lEx) { lFiles = null; } if (lFiles != null && !lFiles.isEmpty()) { lDir = new File("."); mJWebSocketHome = FilenameUtils.normalize(lDir.getAbsolutePath()); } } } } } // ensure that we get at least an empty string to avoid null pointer exceptions if (null == mJWebSocketHome) { mJWebSocketHome = ""; } adjustJWebSocketHome(); System.setProperty(JWebSocketServerConstants.JWEBSOCKET_HOME, mJWebSocketHome); return mJWebSocketHome; }
From source file:org.jwebsocket.config.JWebSocketConfig.java
/** * * @param aFilename/*w ww. ja v a 2 s.c om*/ * @return */ private static String findConfigPath(String aFilename) { String lPath; if (null != mJWebSocketHome && null == mConfigPath && null != aFilename) { File lFile = new File(mJWebSocketHome + "conf" + File.separator + aFilename); lPath = FilenameUtils.normalize(lFile.getAbsolutePath()); mConfigPath = lPath; } return mConfigPath; }