List of usage examples for org.apache.commons.io FilenameUtils getPathNoEndSeparator
public static String getPathNoEndSeparator(String filename)
From source file:org.pentaho.platform.repository.RepositoryFilenameUtils.java
/** * Gets the path from a full filename, which excludes the prefix, and also excluding the final directory * separator.//from w ww . jav a 2 s . c om * <p/> * The method is entirely text based, and returns the text before the last forward or backslash. * * <pre> * a.txt --> "" * a/b/c --> a/b * a/b/c/ --> a/b/c * /a.txt --> "" * /a/b/c --> a/b * /a/b/c/ --> a/b/c * </pre> * <p/> * This method drops the prefix from the result. See {@link #getFullPathNoEndSeparator(String)} for the method * that retains the prefix. * * @param filename * the filename to query, null returns null * @return the path of the file, an empty string if none exists, null if invalid */ public static String getPathNoEndSeparator(final String filename) { return FilenameUtils.getPathNoEndSeparator(filename); }
From source file:org.pentaho.platform.scheduler2.quartz.SchedulerOutputPathResolver.java
public SchedulerOutputPathResolver(final String outputPathPattern, final String actionUser) { this.jobName = FilenameUtils.getBaseName(outputPathPattern); this.outputDirectory = FilenameUtils.getPathNoEndSeparator(outputPathPattern); this.actionUser = actionUser; }
From source file:org.pentaho.platform.web.http.api.resources.SchedulerResourceUtil.java
public static HashMap<String, Serializable> handlePDIScheduling(RepositoryFile file, HashMap<String, Serializable> parameterMap) { if (file != null && isPdiFile(file)) { HashMap<String, Serializable> convertedParameterMap = new HashMap<String, Serializable>(); Map<String, String> pdiParameterMap = new HashMap<String, String>(); convertedParameterMap.put("directory", FilenameUtils.getPathNoEndSeparator(file.getPath())); String type = isTransformation(file) ? "transformation" : "job"; convertedParameterMap.put(type, FilenameUtils.getBaseName(file.getPath())); Iterator<String> it = parameterMap.keySet().iterator(); while (it.hasNext()) { String param = (String) it.next(); if (!StringUtils.isEmpty(param) && parameterMap.containsKey(param)) { pdiParameterMap.put(param, parameterMap.get(param).toString()); }/*w w w. ja va 2s .com*/ } convertedParameterMap.put("parameters", (Serializable) pdiParameterMap); return convertedParameterMap; } return parameterMap; }
From source file:org.retroduction.carma.reportgenerator.beanbuilder.ProjectSourceCodeFileListBeanBuilder.java
private String extractPackageName(URL sourceFolderUrl, URL sourceFileUrl) { String file = FilenameUtils.getPathNoEndSeparator(sourceFileUrl.toString()); String sourceFolder = FilenameUtils.getPathNoEndSeparator(sourceFolderUrl.toString()); return file.substring(sourceFolder.length() + 1).replaceAll("/", "."); }
From source file:org.yamj.core.service.file.FileStorageService.java
public String storeSkin(Skin skin) { String message = "Skin downloaded OK"; LOG.debug("Attempting to store skin URL: '{}'", skin.getSourceUrl()); if (StringUtils.isNotBlank(skin.getSourceUrl())) { String filename = FilenameUtils.getName(skin.getSourceUrl()).replaceAll("[^a-zA-Z0-9-_\\.]", "_"); LOG.debug("Storage filename is '{}'", filename); URL skinUrl;/* w ww .j a va2s . c o m*/ try { skinUrl = new URL(skin.getSourceUrl()); boolean downloadResult = store(StorageType.SKIN, filename, skinUrl); LOG.debug("Skin download {}", downloadResult ? "OK" : "Failed"); if (downloadResult) { String zipFilename = FilenameUtils.concat(skin.getSkinDir(), filename); LOG.debug("Unzipping skin file '{}'", zipFilename); try { ZipFile zf = new ZipFile(zipFilename); // Get a list of the files in the zip List<FileHeader> fileHeaderList = zf.getFileHeaders(); // Get the first file String tempFilename = fileHeaderList.get(0).getFileName(); // Get the directory name for the first file String tempDir = FilenameUtils .getBaseName(FilenameUtils.getPathNoEndSeparator(tempFilename)); // If the directory from the zip was empty, use the zip name to unpack to. String zipTargetDir; if (StringUtils.isBlank(tempDir)) { // There's no folder so add the zip filename zipTargetDir = FilenameUtils.concat(skin.getSkinDir(), zipFilename); skin.setPath(zipFilename); } else { // Use the skin folder plus what's in the zip zipTargetDir = skin.getSkinDir(); // Default unpack to skin folder // Set the skin path to the one in the zip file skin.setPath(tempDir); } // Unpack the files zf.extractAll(zipTargetDir); LOG.info("Unzipped zip file '{}' to '{}'", zipFilename, zipTargetDir); // Update the skin information skin.readSkinInformation(); } catch (ZipException ex) { LOG.warn("Failed to extract zip file '{}', error: {}", zipFilename, ex.getMessage()); message = "Failed to extract skin from zip file!"; } } else { message = "Skin download failed. Check log for details."; } } catch (MalformedURLException ex) { LOG.warn("Failed to encode URL '{}', error: {}", skin.getSourceUrl(), ex.getMessage()); message = "Failed to decode skin URL, please check and try again"; } catch (IOException ex) { LOG.warn("Failed to download '{}' from URL '{}', error: {}", filename, skin.getSourceUrl(), ex.getMessage()); message = "Failed to download skin zip from URL, error: " + ex.getMessage(); } } else { LOG.info("No URL found for skin: {}", skin.toString()); message = "No URL found for the skin"; } return message; }
From source file:pt.webdetails.cpf.repository.pentaho.unified.UnifiedRepositoryAccess.java
public boolean saveFile(IFileContent file) { IUnifiedRepository repo = getRepository(); InputStream is = null;/*from ww w. java2 s.co m*/ try { is = file.getContents(); } catch (IOException e) { logger.error(e); } IRepositoryFileData data = createFileData(is, MimeTypes.getMimeType(file.getPath())); RepositoryFile savedFile = null; if (fileExists(file.getPath())) { //yay, just update: no muss, no fuss! RepositoryFile repositoryFile = getRepositoryFile(file.getPath()); // TODO: preserve mimeType from file data savedFile = repo.updateFile(repositoryFile, data, null); // TODO: what happens here when things go wrong? } else { // keeps '/' RepositoryFile parentDir = getOrCreateFolder(repo, FilenameUtils.getPathNoEndSeparator(file.getPath())); if (parentDir == null) { logger.error("Unable to ensure parent folder for " + file.getPath() + ". Check permissions?"); } String name = !StringUtils.isEmpty(file.getName()) ? file.getName() : FilenameUtils.getName(file.getPath()); RepositoryFile.Builder fileBuilder = new RepositoryFile.Builder(name); Map<String, Properties> localePropertiesMap = new HashMap<String, Properties>(); String defaultLocale = "default"; // use default locale Properties props = new Properties(); if (!StringUtils.isEmpty(file.getTitle())) { fileBuilder = fileBuilder.title(file.getTitle()); props.put("file.title", file.getTitle()); } if (!StringUtils.isEmpty(file.getDescription())) { fileBuilder = fileBuilder.title(file.getDescription()); props.put("file.description", file.getDescription()); } localePropertiesMap.put(defaultLocale, props); fileBuilder = fileBuilder.localePropertiesMap(localePropertiesMap); savedFile = repo.createFile(parentDir.getId(), fileBuilder.build(), data, null); } return savedFile != null && savedFile.getId() != null; }