List of usage examples for org.apache.commons.io FilenameUtils getPrefix
public static String getPrefix(String filename)
C:/
or ~/
. From source file:org.pentaho.platform.repository.RepositoryFilenameUtils.java
/** * Gets the prefix from a full filename. * <p/>// w w w. j a v a 2 s . c om * The prefix includes the first slash in the full filename where applicable. * * <pre> * a/b/c.txt --> "" --> relative * /a/b/c.txt --> "/" --> absolute * </pre> * <p/> * * @param filename * the filename to query, null returns null * @return the prefix of the file, null if invalid */ public static String getPrefix(final String filename) { return FilenameUtils.getPrefix(filename); }
From source file:org.skb.kb.SKB.java
/** * Loads all available packages for the current site. * /*from w w w. j a v a 2 s.c om*/ * This function loads all available (installed) packages for the current site ($site_id). * This can be practical when loading individual packages is inconvenient. It is used for * viewing configuration by the Core.SkbConfig package. * @param additional */ public void loadAllSitePackages(ArrayList<String> additional) { String pkg_dir = this.configuration.get("path/repository").toString(); String site_id = this.configuration.get("skb/site-id").toString(); FindPackageDirectories fpd = new FindPackageDirectories(); fpd.siteID(site_id); List<String> files = fpd.getTxtFiles(pkg_dir); pkg_dir = pkg_dir.replace(FilenameUtils.getPrefix(pkg_dir), ""); for (int i = 0; i < files.size(); i++) { String fn = files.get(i); fn = fn.replace(FilenameUtils.getPrefix(fn), ""); fn = fn.replace(FilenameUtils.separatorsToUnix(pkg_dir), ""); fn = fn.replace("/", "."); this.requirePackage(fn); } // in_array(str_replace($pkg_dir,"",$pkg),$additional) }
From source file:org.tellervo.desktop.bulkdataentry.command.PopulateFromODKCommand.java
/** * Ensures a filename is unique by adding an index on the end if the file already exists * /*from ww w . j a v a2 s . c om*/ * @param file * @param i * @return */ private File getUniqueFilename(File file, int i) { String index = "(" + i + ")."; File originalfile = file; String filename = file.getAbsolutePath(); file = new File(FilenameUtils.getPrefix(filename) + FilenameUtils.getPath(filename) + FilenameUtils.removeExtension(file.getName()) + index + FilenameUtils.getExtension(filename)); if (file.exists()) { return getUniqueFilename(originalfile, i + 1); } return file; }
From source file:org.yamj.core.tools.CountryXmlTools.java
@PostConstruct public void init() { String countryFileName = PropertyTools.getProperty("yamj3.country.fileName"); if (StringUtils.isBlank(countryFileName)) { LOG.trace("No valid country file name configured"); return;/*from w w w . j a v a 2 s . c o m*/ } if (!StringUtils.endsWithIgnoreCase(countryFileName, "xml")) { LOG.warn("Invalid country file name specified: {}", countryFileName); return; } File xmlFile; if (StringUtils.isBlank(FilenameUtils.getPrefix(countryFileName))) { // relative path given String path = System.getProperty("yamj3.home"); if (StringUtils.isEmpty(path)) { path = "."; } xmlFile = new File(FilenameUtils.concat(path, countryFileName)); } else { // absolute path given xmlFile = new File(countryFileName); } if (!xmlFile.exists() || !xmlFile.isFile()) { LOG.warn("Countries file does not exist: {}", xmlFile.getPath()); return; } if (!xmlFile.canRead()) { LOG.warn("Countries file not readble: {}", xmlFile.getPath()); return; } LOG.debug("Initialize countries from file: {}", xmlFile.getPath()); try { XMLConfiguration c = new XMLConfiguration(xmlFile); List<HierarchicalConfiguration> countries = c.configurationsAt("country"); for (HierarchicalConfiguration country : countries) { String masterCountry = country.getString("[@name]"); List<Object> subCountries = country.getList("subcountry"); for (Object subCountry : subCountries) { LOG.debug("New genre added to map: {} -> {}", subCountry, masterCountry); COUNTRIES_MAP.put(((String) subCountry).toLowerCase(), masterCountry); } } try { this.commonStorageService.updateCountriesXml(COUNTRIES_MAP); } catch (Exception ex) { LOG.warn("Failed update countries xml in database", ex); } } catch (Exception ex) { LOG.error("Failed parsing country input file: " + xmlFile.getPath(), ex); } }
From source file:org.yamj.core.tools.GenreXmlTools.java
@PostConstruct public void init() { String genreFileName = PropertyTools.getProperty("yamj3.genre.fileName"); if (StringUtils.isBlank(genreFileName)) { LOG.trace("No valid genre file name configured"); return;/*www . j a v a 2s.c o m*/ } if (!StringUtils.endsWithIgnoreCase(genreFileName, "xml")) { LOG.warn("Invalid genre file name specified: {}", genreFileName); return; } File xmlFile; if (StringUtils.isBlank(FilenameUtils.getPrefix(genreFileName))) { // relative path given String path = System.getProperty("yamj3.home"); if (StringUtils.isEmpty(path)) { path = "."; } xmlFile = new File(FilenameUtils.concat(path, genreFileName)); } else { // absolute path given xmlFile = new File(genreFileName); } if (!xmlFile.exists() || !xmlFile.isFile()) { LOG.warn("Genres file does not exist: {}", xmlFile.getPath()); return; } if (!xmlFile.canRead()) { LOG.warn("Genres file not readble: {}", xmlFile.getPath()); return; } LOG.debug("Initialize genres from file: {}", xmlFile.getPath()); try { XMLConfiguration c = new XMLConfiguration(xmlFile); List<HierarchicalConfiguration> genres = c.configurationsAt("genre"); for (HierarchicalConfiguration genre : genres) { String masterGenre = genre.getString("[@name]"); List<Object> subGenres = genre.getList("subgenre"); for (Object subGenre : subGenres) { LOG.debug("New genre added to map: {} -> {}", subGenre, masterGenre); GENRES_MAP.put(((String) subGenre).toLowerCase(), masterGenre); } } try { this.commonStorageService.updateGenresXml(GENRES_MAP); } catch (Exception ex) { LOG.warn("Failed update genres xml in database", ex); } } catch (Exception ex) { LOG.error("Failed parsing genre input file: " + xmlFile.getPath(), ex); } }
From source file:se.trixon.toolbox.photokml.PhotoKmlTopComponent.java
private boolean validPathPrefix() { boolean result = true; String destPrefix = FilenameUtils.getPrefix(mDestination.getAbsolutePath()); for (String string : mOptions.getSourcePaths().split(SystemUtils.PATH_SEPARATOR)) { if (!destPrefix.equalsIgnoreCase(FilenameUtils.getPrefix(string))) { result = false;/* w ww .j ava 2s. co m*/ break; } } return result; }