List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:org.wso2.carbon.registry.resource.ui.clients.ResourceServiceClient.java
public String getExternalURL(HttpServletRequest request) throws Exception { String path = (String) request.getAttribute("path"); if (path != null && path.contains("..")) { path = FilenameUtils.normalize(path); }/*w w w.j a v a 2 s. c om*/ String url = null; try { url = stub.getTextContent(path); } catch (Exception e) { String msg = "Failed get content of the resource " + path + ". " + e.getMessage(); log.error(msg, e); throw e; } return url; }
From source file:piecework.content.concrete.GridFSContentProviderReceiver.java
@Override public ContentResource findByLocation(ContentProfileProvider modelProvider, String location) throws PieceworkException { if (StringUtils.isEmpty(location)) throw new MisconfiguredProcessException("Unable to find content with an empty location"); String normalized = FilenameUtils.normalize(location); String basePath = basePath(modelProvider); if (!normalized.startsWith(basePath)) { accessTracker.alarm(AlarmSeverity.MINOR, "Attempt to access path " + normalized + " outside of " + basePath + " forbidden", modelProvider.principal()); throw new ForbiddenError(); }//from w w w .j a v a 2s . co m return gridFsContentResource(null, location); }
From source file:prototypes.ws.proxy.soap.commons.io.ZipOut.java
public void addDirToZipStream(String paramDirPath, String[] extensions) { String dirPath = FilenameUtils.normalize(paramDirPath); // Files entries File dir = new File(dirPath); if (!dir.exists()) { LOGGER.warn("Directory {} to zip doesn't exist", dirPath); return;// ww w . ja v a 2 s . co m } LOGGER.debug("Add directory {} to zip", dirPath); ZipParameters parameters = new ZipParameters(); parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); InputStream inputStream = null; String filename = ""; try { List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true); for (File file : files) { filename = file.getCanonicalPath().replace(dirPath, ""); //Initialize inputstream inputStream = new FileInputStream(file); byte[] readBuff = new byte[4096]; int readLen = -1; parameters.setSourceExternalStream(false); String folderInZip = file.getParent().replace(dirPath, ""); if (!"".equals(folderInZip) && folderInZip.startsWith(File.separator)) { folderInZip = folderInZip.substring(1); } LOGGER.debug("Folder in zip {}", folderInZip); parameters.setRootFolderInZip(folderInZip); zipOut.putNextEntry(file, parameters); while ((readLen = inputStream.read(readBuff)) != -1) { zipOut.write(readBuff, 0, readLen); } zipOut.closeEntry(); inputStream.close(); } } catch (ZipException ex) { LOGGER.warn("Error while adding file {} : {}", filename, ex); } catch (IOException ex) { LOGGER.warn("Error while opening file {} : {}", filename, ex); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ex) { LOGGER.error("Error on inputStream close : {} ", ex); } } } }
From source file:pt.ua.tm.neji.ml.MLModel.java
public MLModel(final String modelName, final File propertiesFile) { Properties prop = new Properties(); try {//from w w w .j a v a2 s . com prop.load(new FileReader(propertiesFile)); } catch (IOException e) { throw new RuntimeException("There was a problem loading the model properties file.", e); } String folderPath = propertiesFile.getParent() + File.separator; this.modelName = modelName; this.modelFile = FilenameUtils.normalize(folderPath + prop.getProperty("file")); this.configFile = FilenameUtils.normalize(folderPath + prop.getProperty("config")); this.parsing = Parsing.valueOf(prop.getProperty("parsing")); this.semanticGroup = prop.getProperty("group"); this.dictionariesPath = prop.getProperty("dictionaries"); if (dictionariesPath == null) { this.normalizationDictionariesFolder = null; } else { this.normalizationDictionariesFolder = FilenameUtils.normalize(folderPath + dictionariesPath); } this.models = new LinkedBlockingQueue<>(); this.readyForMultiThreading = false; this.isInitialized = false; }
From source file:pt.ua.tm.trigner.annotate.MLModel.java
public MLModel(final File propertiesFile) { Properties prop = new Properties(); try {/*w ww . j a va2 s. co m*/ prop.load(new FileReader(propertiesFile)); } catch (IOException e) { throw new RuntimeException("There was a problem loading the model properties file.", e); } String folderPath = propertiesFile.getParent() + File.separator; this.modelFile = FilenameUtils.normalize(folderPath + prop.getProperty("file")); this.configFile = FilenameUtils.normalize(folderPath + prop.getProperty("config")); this.parsing = Parsing.valueOf(prop.getProperty("parsing")); this.semanticGroup = prop.getProperty("group"); if (prop.getProperty("dictionaries") == null) { this.normalizationDictionariesFolder = null; } else { this.normalizationDictionariesFolder = FilenameUtils .normalize(folderPath + prop.getProperty("dictionaries")); } this.models = new LinkedBlockingQueue<>(); this.readyForMultiThreading = false; this.isInitialized = false; }
From source file:pt.webdetails.cdb.util.PackageResolver.java
@Override public InputStream getFileInputStream(String path) throws IOException { path = FilenameUtils.normalize(RepositoryHelper.appendPath(basePath, path)); URL url = RepositoryHelper.getClosestResource(classLoader, path); if (url != null) { return url.openStream(); } else {//from ww w. jav a 2 s. co m return null; } }
From source file:pt.webdetails.cdb.util.PackageResolver.java
@Override public boolean fileExists(String path) { path = FilenameUtils.normalize(RepositoryHelper.appendPath(basePath, path)); return RepositoryHelper.getClosestResource(classLoader, path) != null; }
From source file:pt.webdetails.cpf.localization.MessageBundlesHelper.java
public String getMessageFilesCacheUrl() { return FilenameUtils.separatorsToUnix(FilenameUtils.normalize(Util.joinPath(getPluginStaticBaseContentUrl(), BASE_CACHE_DIR, getDashboardFolderPath(), Util.SEPARATOR))); }
From source file:pt.webdetails.cpf.persistence.PersistenceEngine.java
private String getOrientPath() { return (this.getClass().getClassLoader() instanceof PluginClassLoader) ? FilenameUtils.normalize(FilenameUtils .separatorsToUnix(PentahoSystem.getApplicationContext().getSolutionPath("/system/.orient"))) : "."; }
From source file:pt.webdetails.cpf.repository.pentaho.SystemPluginResourceAccess.java
@Override public boolean fileExists(String path) { if (super.fileExists(path)) { String normPath = FilenameUtils.normalize(this.getFile(path).getAbsolutePath()); return normPath != null && normPath.startsWith(FilenameUtils.normalize(basePath.getAbsolutePath())); }//w ww .j a v a 2 s . c om return false; }