List of usage examples for org.apache.commons.lang StringUtils chomp
public static String chomp(String str, String separator)
Removes separator
from the end of str
if it's there, otherwise leave it alone.
From source file:nl.knaw.huygens.timbuctoo.config.TypeRegistry.java
private Set<ClassInfo> getClassInfoSet(ClassPath classPath, String packageName) { if (packageName.endsWith(".*")) { return classPath.getTopLevelClassesRecursive(StringUtils.chomp(packageName, ".*")); } else {/*from w ww . j a va2s . c om*/ return classPath.getTopLevelClasses(packageName); } }
From source file:nl.tranquilizedquality.itest.cargo.AbstractInstalledContainerUtil.java
/** * Installs the container and the application configuration. It also sets * some system properties so the container can startup properly. Finally it * sets up additional configuration like jndi.proprties files etc. *///w w w. j a v a 2 s . co m protected void setupContainer() { if (LOGGER.isInfoEnabled()) { LOGGER.info("Cleaning up " + containerName + "..."); } // In windows the renaming causes problem when: // - The zip file has not the same name of the installed directory. // - The ZipURLInstaller fails. final String operatingSystem = System.getProperty("os.name"); if (operatingSystem != null && !operatingSystem.startsWith("Windows")) { try { new File(containerHome).mkdir(); } catch (final Exception exceptionOnMkDir) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Failed to create the directory: " + containerHome + ". Details: " + exceptionOnMkDir.getMessage(), exceptionOnMkDir); } throw new ConfigurationException("Failed to create the directory: " + containerHome + ". Details: " + exceptionOnMkDir.getMessage(), exceptionOnMkDir); } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Installing " + containerName + "..."); LOGGER.info("Downloading container from: " + remoteLocation); LOGGER.info("Container file: " + containerFile); } /* * Download and configure the container. */ final String installDir = StringUtils.substringBeforeLast(StringUtils.chomp(containerHome, "/"), "/"); if (StringUtils.contains(this.remoteLocation, "http")) { try { final URL remoteLocationUrl = new URL(this.remoteLocation + containerFile); final ZipURLInstaller installer = new ZipURLInstaller(remoteLocationUrl, installDir, installDir); installer.install(); } catch (final MalformedURLException e) { throw new DeployException("Failed to download container!", e); } /* * Rename the install directory to the container home directory so * it doesn't matter what the name is of the zip file and avoid case * sensitive issues on Linux. */ final String containerDir = StringUtils.stripEnd(containerFile, ".zip"); final File installedDir = new File(installDir + "/" + containerDir + "/"); final File destenationDir = new File(containerHome); if (LOGGER.isInfoEnabled()) { LOGGER.info("Renaming: " + installedDir.getPath()); LOGGER.info("To: " + destenationDir.getPath()); } final boolean renamed = installedDir.renameTo(destenationDir); if (!renamed) { final String msg = "Failed to rename container install directory to home directory name!"; if (LOGGER.isErrorEnabled()) { LOGGER.error(msg); } throw new ConfigurationException(msg); } } else { final Unzip unzipper = new Unzip(); unzipper.setSrc(new File(this.remoteLocation + containerFile)); unzipper.setDest(new File(containerHome)); unzipper.execute(); } /* * Setup the system properties. */ systemProperties.put("cargo.server.port", containerPort.toString()); }
From source file:opennlp.tools.apps.review_builder.MinedSentenceProcessor.java
public static String processSentence(String pageSentence) { if (pageSentence == null) return ""; pageSentence = Utils.fullStripHTML(pageSentence); pageSentence = StringUtils.chomp(pageSentence, ".."); pageSentence = StringUtils.chomp(pageSentence, ". ."); pageSentence = StringUtils.chomp(pageSentence, " ."); pageSentence = StringUtils.chomp(pageSentence, "."); pageSentence = StringUtils.chomp(pageSentence, "..."); pageSentence = StringUtils.chomp(pageSentence, " ...."); pageSentence = pageSentence.replace("::", ":").replace(".,", ". ").replace("(.)", ""); pageSentence = pageSentence.trim();//ww w . j a va2 s . c o m pageSentence = pageSentence.replaceAll("\\s+", " "); // make single // spaces // everywhere String[] pipes = StringUtils.split(pageSentence, '|'); // removed // shorter part // of sentence // at the end // after pipe if (pipes.length == 2 && ((float) pipes[0].length() / (float) pipes[1].length() > 3.0)) { int pipePos = pageSentence.indexOf("|"); if (pipePos > -1) pageSentence = pageSentence.substring(0, pipePos - 1).trim(); } if (!StringUtils.contains(pageSentence, '.') && !StringUtils.contains(pageSentence, '?') && !StringUtils.contains(pageSentence, '!')) pageSentence = pageSentence + ". "; pageSentence = pageSentence.replace(" .", ".").replace("..", ".").trim(); if (!pageSentence.endsWith(".")) pageSentence += ". "; return pageSentence; }
From source file:opennlp.tools.similarity.apps.GeneratedSentenceProcessor.java
public static String processSentence(String pageSentence) { if (acceptableMinedSentence(pageSentence) == null) { System.out.println("Rejected sentence by GenerSentProc.processSentence.acceptableMinedSentence()"); return ""; }/*from w ww .j a v a 2 s.co m*/ if (pageSentence == null) return ""; pageSentence = Utils.fullStripHTML(pageSentence); pageSentence = StringUtils.chomp(pageSentence, ".."); pageSentence = StringUtils.chomp(pageSentence, ". ."); pageSentence = StringUtils.chomp(pageSentence, " ."); pageSentence = StringUtils.chomp(pageSentence, "."); pageSentence = StringUtils.chomp(pageSentence, "..."); pageSentence = StringUtils.chomp(pageSentence, " ...."); pageSentence = pageSentence.replace("::", ":").replace(".,", ". ").replace("(.)", ""); pageSentence = pageSentence.trim(); pageSentence = pageSentence.replaceAll("\\s+", " "); // make single // spaces // everywhere String[] pipes = StringUtils.split(pageSentence, '|'); // removed // shorter part // of sentence // at the end // after pipe if (pipes.length == 2 && ((float) pipes[0].length() / (float) pipes[1].length() > 3.0)) { int pipePos = pageSentence.indexOf("|"); if (pipePos > -1) pageSentence = pageSentence.substring(0, pipePos - 1).trim(); } if (!StringUtils.contains(pageSentence, '.') && !StringUtils.contains(pageSentence, '?') && !StringUtils.contains(pageSentence, '!')) pageSentence = pageSentence + ". "; pageSentence = pageSentence.replace(" .", ".").replace("..", ".").trim(); if (!pageSentence.endsWith(".") && !pageSentence.endsWith(":") && !pageSentence.endsWith("!") && !pageSentence.endsWith(".")) pageSentence += ". "; return pageSentence; }
From source file:org.apache.oodt.cas.protocol.ProtocolFile.java
public ProtocolFile(ProtocolFile parent, String path, boolean isDir) { this.parent = parent; this.isDir = isDir; Validate.notNull(path, "ProtocolFile's path cannot be NULL"); this.path = path.length() > 0 && !path.equals(SEPARATOR) ? StringUtils.chomp(path, SEPARATOR) : path; }
From source file:org.apache.oodt.cas.protocol.ProtocolFile.java
/** * Get Absolute pathed {@link ProtocolFile} version of this {@link ProtocolFile}. * //from w ww .jav a 2 s .co m * @return the absolute pathed version of this {@link ProtocolFile} */ public ProtocolFile getAbsoluteFile() { if (this.isRelative()) { ProtocolFile parent = this.getParent(); if (parent != null) { return new ProtocolFile(StringUtils.chomp(parent.getAbsoluteFile().getPath(), SEPARATOR) + SEPARATOR + this.getPath(), this.isDir()); } } return this; }
From source file:org.apache.struts2.osgi.BaseOsgiHost.java
/** * Return a list of directories under a directory whose name is a number *//*from w ww . ja v a 2s.c o m*/ protected Map<String, String> getRunLevelDirs(String dir) { Map<String, String> dirs = new HashMap<String, String>(); try { ResourceFinder finder = new ResourceFinder(); URL url = finder.find("bundles"); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); String[] runLevelDirs = bundlesDir.list(new FilenameFilter() { public boolean accept(File file, String name) { try { return file.isDirectory() && Integer.valueOf(name) > 0; } catch (NumberFormatException ex) { //the name is not a number return false; } } }); if (runLevelDirs != null && runLevelDirs.length > 0) { //add all the dirs to the list for (String runLevel : runLevelDirs) dirs.put(runLevel, StringUtils.chomp(dir, "/") + "/" + runLevel); } else if (LOG.isDebugEnabled()) { LOG.debug("No run level directories found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) LOG.warn("Unable to read [#0] directory", dir); } else if (LOG.isWarnEnabled()) LOG.warn("The [#0] directory was not found", dir); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Unable load bundles from the [#0] directory", e, dir); } return dirs; }
From source file:org.apache.struts2.osgi.BaseOsgiHost.java
protected void addExportedPackages(Properties strutsConfigProps, Properties configProps) { String[] rootPackages = StringUtils.split((String) strutsConfigProps.get("scanning.package.includes"), ","); ResourceFinder finder = new ResourceFinder(StringUtils.EMPTY); List<String> exportedPackages = new ArrayList<String>(); //build a list of subpackages for (String rootPackage : rootPackages) { try {// w w w.j a v a 2s .c om String version = null; if (rootPackage.indexOf(";") > 0) { String[] splitted = rootPackage.split(";"); rootPackage = splitted[0]; version = splitted[1]; } Map<URL, Set<String>> subpackagesMap = finder .findPackagesMap(StringUtils.replace(rootPackage.trim(), ".", "/")); for (Map.Entry<URL, Set<String>> entry : subpackagesMap.entrySet()) { URL url = entry.getKey(); Set<String> packages = entry.getValue(); //get version if not set if (StringUtils.isBlank(version)) version = getVersion(url); if (packages != null) { for (String subpackage : packages) { exportedPackages.add(subpackage + "; version=" + version); } } } } catch (IOException e) { if (LOG.isErrorEnabled()) LOG.error("Unable to find subpackages of [#0]", e, rootPackage); } } //make a string with the exported packages and add it to the system properties if (!exportedPackages.isEmpty()) { String systemPackages = (String) configProps.get(Constants.FRAMEWORK_SYSTEMPACKAGES); systemPackages = StringUtils.chomp(systemPackages, ",") + "," + StringUtils.join(exportedPackages, ","); configProps.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); } }
From source file:org.apache.struts2.osgi.host.BaseOsgiHost.java
/** * Return a list of directories under a directory whose name is a number *///from w w w .j a v a2 s . c o m protected Map<String, String> getRunLevelDirs(String dir) { Map<String, String> dirs = new HashMap<String, String>(); try { ResourceFinder finder = new ResourceFinder(); URL url = finder.find("bundles"); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); String[] runLevelDirs = bundlesDir.list(new FilenameFilter() { public boolean accept(File file, String name) { try { return file.isDirectory() && Integer.valueOf(name) > 0; } catch (NumberFormatException ex) { //the name is not a number return false; } } }); if (runLevelDirs != null && runLevelDirs.length > 0) { //add all the dirs to the list for (String runLevel : runLevelDirs) { dirs.put(runLevel, StringUtils.chomp(dir, "/") + "/" + runLevel); } } else if (LOG.isDebugEnabled()) { LOG.debug("No run level directories found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) { LOG.warn("Unable to read [#0] directory", dir); } } else if (LOG.isWarnEnabled()) { LOG.warn("The [#0] directory was not found", dir); } } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Unable load bundles from the [#0] directory", e, dir); } } return dirs; }
From source file:org.apache.struts2.osgi.host.BaseOsgiHost.java
protected void addExportedPackages(Properties strutsConfigProps, Properties configProps) { String[] rootPackages = StringUtils.split((String) strutsConfigProps.get("scanning.package.includes"), ","); ResourceFinder finder = new ResourceFinder(StringUtils.EMPTY); List<String> exportedPackages = new ArrayList<String>(); //build a list of subpackages for (String rootPackage : rootPackages) { try {//from www . ja v a 2 s . co m String version = null; if (rootPackage.indexOf(";") > 0) { String[] splitted = rootPackage.split(";"); rootPackage = splitted[0]; version = splitted[1]; } Map<URL, Set<String>> subpackagesMap = finder .findPackagesMap(StringUtils.replace(rootPackage.trim(), ".", "/")); for (Map.Entry<URL, Set<String>> entry : subpackagesMap.entrySet()) { URL url = entry.getKey(); Set<String> packages = entry.getValue(); //get version if not set if (StringUtils.isBlank(version)) { version = getVersion(url); } if (packages != null) { for (String subpackage : packages) { exportedPackages.add(subpackage + "; version=" + version); } } } } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error("Unable to find subpackages of [#0]", e, rootPackage); } } } //make a string with the exported packages and add it to the system properties if (!exportedPackages.isEmpty()) { String systemPackages = (String) configProps.get(Constants.FRAMEWORK_SYSTEMPACKAGES); systemPackages = StringUtils.chomp(systemPackages, ",") + "," + StringUtils.join(exportedPackages, ","); configProps.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); } }