List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java
/** * Searches for the source file of the given ruleset. This provides the information * for the "editme" link.//w w w .j ava 2 s . c o m * * @param ruleset the ruleset to search for. * @return * @throws IOException */ private String getRuleSetSourceFilepath(RuleSet ruleset) throws IOException { final String rulesetFilename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName())); final List<Path> foundPathResult = new LinkedList<>(); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String path = file.toString(); if (path.contains("src") && path.endsWith(rulesetFilename)) { foundPathResult.add(file); return FileVisitResult.TERMINATE; } return super.visitFile(file, attrs); } }); if (!foundPathResult.isEmpty()) { Path foundPath = foundPathResult.get(0); foundPath = root.relativize(foundPath); // Note: the path is normalized to unix path separators, so that the editme link // uses forward slashes return FilenameUtils.normalize(foundPath.toString(), true); } return StringUtils.chomp(ruleset.getFileName()); }
From source file:net.unicon.demetrius.fac.url.URLResourceFactory.java
public IResource getResource(String relativePath) throws DemetriusException { String cleanPath = FilenameUtils.normalize(relativePath); if (cleanPath == null || cleanPath.equals("")) { throw new IllegalArgumentException("Illegal path specified: " + relativePath); }/* w ww . ja v a 2s . c om*/ URLFile urlFile = null; try { URL res = new URL(baseURL, cleanPath); urlFile = new URLFile(this, cleanPath, res); if (log.isDebugEnabled()) { log.debug("Creating resource object for original path '" + relativePath + "' clean path '" + cleanPath + "' on URL: " + baseURL + " Result: " + res); } } catch (MalformedURLException e) { throw new DemetriusException(e.getMessage(), e); } return urlFile; }
From source file:ninja.AssetsControllerHelperTest.java
@Test public void testNormalizePathWithoutLeadingSlashCorrectFilnameUtilStaticMethodsCalled() { PowerMockito.mockStatic(FilenameUtils.class, Mockito.CALLS_REAL_METHODS); assetsControllerHelper.normalizePathWithoutLeadingSlash("/dir1/test.test", false); PowerMockito.verifyStatic();/*from www . j a v a2 s.c o m*/ FilenameUtils.normalize("/dir1/test.test"); assetsControllerHelper.normalizePathWithoutLeadingSlash("/dir1/test.test", true); PowerMockito.verifyStatic(); FilenameUtils.normalize("/dir1/test.test", true); }
From source file:nl.armatiek.xslweb.configuration.WebApp.java
public XsltExecutable tryTemplatesCache(String transformationPath, ErrorListener errorListener) throws Exception { String key = FilenameUtils.normalize(transformationPath); XsltExecutable templates = templatesCache.get(key); if (templates == null) { logger.info("Compiling and caching stylesheet \"" + transformationPath + "\" ..."); try {//from w w w .jav a 2 s .c om SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setXIncludeAware(true); spf.setValidating(false); SAXParser parser = spf.newSAXParser(); XMLReader reader = parser.getXMLReader(); Source source = new SAXSource(reader, new InputSource(transformationPath)); XsltCompiler comp = processor.newXsltCompiler(); comp.setErrorListener(errorListener); templates = comp.compile(source); } catch (Exception e) { logger.error("Could not compile stylesheet \"" + transformationPath + "\"", e); throw e; } if (!developmentMode) { templatesCache.put(key, templates); } } return templates; }
From source file:nl.armatiek.xslweb.configuration.WebApp.java
public XsltExecutable trySchematronCache(String schematronPath, String phase, ErrorListener errorListener) throws Exception { String key = FilenameUtils.normalize(schematronPath) + (phase != null ? phase : ""); XsltExecutable templates = templatesCache.get(key); if (templates == null) { logger.info("Compiling and caching schematron schema \"" + schematronPath + "\" ..."); try {//w ww . jav a2 s . com Source source = new StreamSource(new File(schematronPath)); File schematronDir = new File(Context.getInstance().getHomeDir(), "common/xsl/system/schematron"); ErrorListener listener = new TransformationErrorListener(null, developmentMode); MessageWarner messageWarner = new MessageWarner(); Xslt30Transformer stage1 = tryTemplatesCache( new File(schematronDir, "iso_dsdl_include.xsl").getAbsolutePath(), errorListener).load30(); stage1.setErrorListener(listener); stage1.getUnderlyingController().setMessageEmitter(messageWarner); Xslt30Transformer stage2 = tryTemplatesCache( new File(schematronDir, "iso_abstract_expand.xsl").getAbsolutePath(), errorListener) .load30(); stage2.setErrorListener(listener); stage2.getUnderlyingController().setMessageEmitter(messageWarner); Xslt30Transformer stage3 = tryTemplatesCache( new File(schematronDir, "iso_svrl_for_xslt2.xsl").getAbsolutePath(), errorListener) .load30(); stage3.setErrorListener(listener); stage3.getUnderlyingController().setMessageEmitter(messageWarner); XdmDestination destStage1 = new XdmDestination(); XdmDestination destStage2 = new XdmDestination(); XdmDestination destStage3 = new XdmDestination(); stage1.applyTemplates(source, destStage1); stage2.applyTemplates(destStage1.getXdmNode().asSource(), destStage2); stage3.applyTemplates(destStage2.getXdmNode().asSource(), destStage3); Source generatedXsltSource = destStage3.getXdmNode().asSource(); if (this.developmentMode) { TransformerFactory factory = new TransformerFactoryImpl(); Transformer transformer = factory.newTransformer(); Properties props = new Properties(); props.put(OutputKeys.INDENT, "yes"); transformer.setOutputProperties(props); StringWriter sw = new StringWriter(); transformer.transform(generatedXsltSource, new StreamResult(sw)); logger.info("Generated Schematron XSLT for \"" + schematronPath + "\", phase \"" + (phase != null ? phase : "") + "\" [" + sw.toString() + "]"); } XsltCompiler comp = processor.newXsltCompiler(); comp.setErrorListener(errorListener); templates = comp.compile(generatedXsltSource); } catch (Exception e) { logger.error("Could not compile schematron schema \"" + schematronPath + "\"", e); throw e; } if (!developmentMode) { templatesCache.put(key, templates); } } return templates; }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.Utilities.java
/** * Get the placeholder image to be shown when the actual image is not available. * * @return the placeholder image./*from w ww .j av a 2 s .c o m*/ */ public static BufferedImage getNotAvailableImage() { if (notAvailableImage == null) { try { notAvailableImage = ImageIO.read(new File(FilenameUtils.normalize(NOT_AVAILABLE_ICON_FILE))); } catch (final IOException e) { logger.log(Level.SEVERE, e.getMessage(), e); } } return notAvailableImage; }
From source file:nl.mvdr.umvc3replayanalyser.controller.ReplaySaver.java
/** * Edits a replay.// w w w . j a v a2s.c om * * @param oldReplay * replay to be edited * @param newGame * game, containing the new replay details to be used * @return new replay * @throws IOException * in case saving the new replay fails */ Replay editReplay(Replay oldReplay, Game newGame) throws IOException { Replay result; if (oldReplay.getGame().equals(newGame)) { log.info("Replay remains unchanged."); result = oldReplay; } else { String oldBaseFilename = oldReplay.getGame().getBaseFilename(oldReplay.getCreationTime()); String videoFilePath = FilenameUtils.normalize(this.configuration.getDataDirectory().getAbsolutePath() + FileUtils.SEPARATOR + oldReplay.getVideoLocation()); File videoFile = new File(videoFilePath); Date creationTime = new Date(videoFile.lastModified()); String newBaseFilename = newGame.getBaseFilename(creationTime); String newPreviewImageFileLocation; if (this.configuration.isSavePreviewImageToDataDirectory()) { // Move preview image. String oldPreviewImageFileLocation = oldReplay.getPreviewImageLocation(); if (oldPreviewImageFileLocation.startsWith(FILE_URL_PREFIX)) { oldPreviewImageFileLocation = oldPreviewImageFileLocation.substring(FILE_URL_PREFIX.length()); } File oldPreviewImageFile = new File(oldPreviewImageFileLocation); String previewImageExtension; int index = oldPreviewImageFileLocation.lastIndexOf('.'); if (0 < index) { previewImageExtension = oldPreviewImageFileLocation.substring(index).toLowerCase(); } else { // No extension. previewImageExtension = ""; } File previewImageFile = new File(configuration.getDataDirectoryPath() + FileUtils.SEPARATOR + newBaseFilename + previewImageExtension); // Note that move will fail with an IOException if previewImageFile aleady exists, but that it will // succeed if the old and new paths are the same. Files.move(oldPreviewImageFile.toPath(), previewImageFile.toPath()); newPreviewImageFileLocation = FILE_URL_PREFIX + previewImageFile.getAbsolutePath(); log.info( String.format("Moved preview image from %s to %s.", oldPreviewImageFile, previewImageFile)); } else { // Leave preview image wherever it is. newPreviewImageFileLocation = oldReplay.getPreviewImageLocation(); } // Delete the old replay file. File oldReplayFile = new File(configuration.getDataDirectoryPath() + FileUtils.SEPARATOR + oldBaseFilename + REPLAY_EXTENSION); Files.delete(oldReplayFile.toPath()); log.info(String.format("Deleted old replay file: %s.", oldReplayFile)); result = saveReplay(videoFile, newGame, newPreviewImageFileLocation); } return result; }
From source file:nl.mvdr.umvc3replayanalyser.controller.Umvc3ReplayManagerController.java
/** Handles the case where the user clicks the Open video button. */ @FXML/* w ww. j a v a2 s . c o m*/ private void handleOpenVideoAction() { log.info("Open video button clicked."); Replay selectedReplay = replayTableView.getSelectionModel().getSelectedItem(); if (selectedReplay == null) { throw new IllegalStateException("No replay selected; open video button should have been disabled!"); } if (Desktop.isDesktopSupported()) { String videoFilePath = FilenameUtils.normalize(this.configuration.getDataDirectory().getAbsolutePath() + FileUtils.SEPARATOR + selectedReplay.getVideoLocation()); log.info("Playing video: " + videoFilePath); File videoFile = new File(videoFilePath); try { Desktop.getDesktop().open(videoFile); } catch (IOException | IllegalArgumentException e) { log.error("Unable to play video for replay: " + selectedReplay, e); // Show an error message to the user. String errorMessage = "Unable to play video for game: " + selectedReplay.getGame().getDescription(false); if (e.getMessage() != null) { errorMessage = errorMessage + " " + e.getMessage(); } ErrorMessagePopup.show("Unable to play video", errorMessage, e); } } else { log.error("Unable to play video, desktop not supported!"); // Show an error message to the user. ErrorMessagePopup.show("Unable to play video", "Unable to play video files.", null); } }
From source file:ome.services.scripts.RepoFile.java
/** * Both root and file are absolute paths to files. This constructor calculates * the relative part of the second argument based on the first. *///from ww w . jav a2s . co m public RepoFile(File root, File file) { this.fs = new FsFile(file); this.root = FilenameUtils.normalize(root.getAbsolutePath()); this.rel = fs.path.substring((int) this.root.length()); this.absPath = new File(root, rel).getAbsolutePath(); }
From source file:org.alfresco.repo.content.filestore.FileContentStore.java
private void ensureFileInContentStore(File file) { String fileNormalizedAbsoultePath = FilenameUtils.normalize(file.getAbsolutePath()); String rootNormalizedAbsolutePath = FilenameUtils.normalize(rootAbsolutePath); if (!fileNormalizedAbsoultePath.startsWith(rootNormalizedAbsolutePath)) { throw new ContentIOException("Access to files outside of content store root is not allowed: " + file); }/*ww w .java2s . c o m*/ }