List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java
public ComponentIndexBean createIndexBean4Patch(File patchZipFile, Type type) { if (patchZipFile == null || !patchZipFile.exists() || patchZipFile.isDirectory() || !patchZipFile.getName().endsWith(FileExtensions.ZIP_FILE_SUFFIX) || type == null) { return null; }//from ww w . j av a2 s . c o m String name = StringUtils.removeEnd(patchZipFile.getName(), FileExtensions.ZIP_FILE_SUFFIX); String bundleId = null; String bundleVersion = null; String mvnUri = null; if (type == Type.PLAIN_ZIP) { bundleId = "org.talend.studio.patch.plainzip"; //$NON-NLS-1$ bundleVersion = name; } else if (type == Type.P2_PATCH) { bundleId = "org.talend.studio.patch.updatesite"; //$NON-NLS-1$ bundleVersion = P2Manager.getInstance().getP2Version(patchZipFile); } String artifactId = StringUtils.substringBeforeLast(name, "-"); //$NON-NLS-1$ String artifactVersion = StringUtils.substringAfterLast(name, "-"); //$NON-NLS-1$ mvnUri = MavenUrlHelper.generateMvnUrl(bundleId, artifactId, artifactVersion, FileExtensions.ZIP_EXTENSION, null); if (name != null && bundleId != null && bundleVersion != null && mvnUri != null) { ComponentIndexBean indexBean = new ComponentIndexBean(); boolean set = indexBean.setRequiredFieldsValue(name, bundleId, bundleVersion, mvnUri); indexBean.setValue(ComponentIndexNames.types, PathUtils.convert2StringTypes(Arrays.asList(type))); if (set) { return indexBean; } } return null; }
From source file:org.tdwg.dwca.wikipedia.taxonbox.TaxonInfoBase.java
/** * Expand abbreviated names like://w w w . jav a2 s . c o m * V[ipera]. a[mmodytes]. transcaucasiana - Bruno, 1985 * * @param name * @return */ private String expandName(String name) { if (name == null) return null; if (!Strings.isNullOrEmpty(getGenus())) { Pattern gen = Pattern.compile("^ *" + genus.charAt(0) + "\\. *"); Matcher m = gen.matcher(getScientificName()); if (m.find()) { String expandedName = m.replaceFirst(genus + " "); String epithet = null; if (!Strings.isNullOrEmpty(speciesEpithet)) { epithet = speciesEpithet; } else if (!Strings.isNullOrEmpty(species)) { epithet = StringUtils.substringAfterLast(species, " "); } if (!Strings.isNullOrEmpty(epithet)) { Pattern specEpi = Pattern.compile("^" + genus + " " + epithet.charAt(0) + "\\. *"); m = specEpi.matcher(expandedName); if (m.find()) { expandedName = m.replaceFirst(getGenus() + " " + epithet + " "); } } log.debug("Expanding abbreviated name {} with {}", getScientificName(), expandedName); return expandedName; } } return name; }
From source file:org.uberfire.backend.server.plugin.GwtRuntimePluginLoader.java
String processPluginJar(String jarFileName) { String pluginScriptFileName = null; try (JarFile jar = new JarFile(jarFileName)) { final Enumeration<?> enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { final JarEntry file = (JarEntry) enumEntries.nextElement(); String fileName = StringUtils.substringAfterLast(file.getName(), File.separator); if (fileName.endsWith("cache.js")) { final File f = new File(pluginDeploymentDir + File.separator + fileName); try (InputStream is = jar.getInputStream(file); FileOutputStream fos = new FileOutputStream(f)) { while (is.available() > 0) { fos.write(is.read()); }/* w w w .ja v a2 s . c o m*/ } if (file.getName().endsWith("nocache.js")) { pluginScriptFileName = fileName; } } } } catch (IOException e) { throw new RuntimeException(e); } return pluginScriptFileName; }
From source file:org.uberfire.backend.server.plugins.engine.PluginJarProcessor.java
List<String> extractFilesFromPluginsJar(String jarFileName) { List<String> pluginsFiles = new ArrayList<>(); try (JarFile jar = new JarFile(jarFileName)) { final Enumeration<?> enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { final JarEntry file = (JarEntry) enumEntries.nextElement(); String fileName = StringUtils.substringAfterLast(file.getName(), File.separator); if (PluginProcessor.isAValidPluginFileExtension(fileName)) { final File f = new File(pluginsDeploymentDir + File.separator + fileName); try (InputStream is = jar.getInputStream(file); FileOutputStream fos = new FileOutputStream(f)) { while (is.available() > 0) { fos.write(is.read()); }/* w ww . j a v a 2s .c o m*/ } pluginsFiles.add(fileName); } } } catch (IOException e) { throw new RuntimeException(e); } return pluginsFiles; }
From source file:org.whispersystems.textsecuregcm.auth.AuthorizationHeader.java
public static AuthorizationHeader fromUserAndPassword(String user, String password) throws InvalidAuthorizationHeaderException { try {//from www . j ava 2s .co m final String id = StringUtils.substringAfterLast(user, "."); if (StringUtils.isNumeric(id)) { return new AuthorizationHeader(StringUtils.substringBeforeLast(user, "."), Long.parseLong(id), password); } else { return new AuthorizationHeader(user, 1, password); } } catch (NumberFormatException nfe) { throw new InvalidAuthorizationHeaderException(nfe); } }
From source file:org.wrml.runtime.rest.RestUtils.java
public static final String getLastPathElement(final URI uri) { final String path = uri.getPath(); if (StringUtils.isEmpty(path)) { return path; }/*from w w w. j av a 2s. co m*/ String lastPathElement = StringUtils.substringAfterLast(path, "/"); lastPathElement = StringUtils.substringBefore(lastPathElement, "?"); return lastPathElement; }
From source file:org.xlrnet.metadict.engines.leo.LeoEngine.java
/** * Extracts the domain information from a given representation string. * <p>// w w w . ja va2 s . c o m * Example: * If the input is "drive-in restaurant [cook.]", then the domain is "cook." * * @param representation * The input string. * @return the domain string or null if none could be found */ @Nullable private String extractDomainString(String representation) { String substring = StringUtils.substringAfterLast(representation, "["); if (substring != null) return StringUtils.substringBefore(substring, "]"); return null; }
From source file:org.xwiki.extension.test.po.ExtensionPane.java
/** * Clicks on the specified tab and returns the corresponding section if it's available. * /*w w w. j a v a 2 s .c o m*/ * @param label the tab label * @return the element that wraps the section corresponding to the specified tab */ private WebElement clickTab(String label) { By tabXPath = By.xpath(".//*[@class = 'innerMenu']//a[normalize-space(.) = '" + label + "']"); List<WebElement> found = getUtil().findElementsWithoutWaiting(getDriver(), container, tabXPath); if (found.size() == 0) { return null; } String sectionAnchor = StringUtils.substringAfterLast(found.get(0).getAttribute("href"), "#"); found.get(0).click(); By sectionXPath = By .xpath(".//div[contains(@class, 'extension-body-section') and preceding-sibling::*[1][@id = '" + sectionAnchor + "']]"); return getUtil().findElementWithoutWaiting(getDriver(), container, sectionXPath); }
From source file:org.xwiki.filter.instance.internal.output.XWikiDocumentOutputFilterStream.java
@Override public void beginWikiClassProperty(String name, String type, FilterEventParameters parameters) throws FilterException { ComponentManager componentManager = this.componentManagerProvider.get(); PropertyClassProvider provider;/*from w ww .j a va 2s . c om*/ // First try to use the specified class type as hint. try { if (componentManager.hasComponent(PropertyClassProvider.class, type)) { provider = componentManager.getInstance(PropertyClassProvider.class, type); } else { // In previous versions the class type was the full Java class name of the property class // implementation. Extract the hint by removing the Java package prefix and the Class suffix. String classType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class"); provider = componentManager.getInstance(PropertyClassProvider.class, classType); } } catch (ComponentLookupException e) { throw new FilterException( String.format("Failed to get instance of the property class provider for type [%s]", type), e); } this.currentClassPropertyMeta = provider.getDefinition(); // We should use PropertyClassInterface (instead of PropertyClass, its default implementation) but it // doesn't have the set methods and adding them would breaks the backwards compatibility. We make the // assumption that all property classes extend PropertyClass. this.currentClassProperty = (PropertyClass) provider.getInstance(); this.currentClassProperty.setName(name); this.currentClassProperty.setObject(this.currentXClass); this.currentXClass.safeput(name, this.currentClassProperty); }
From source file:org.xwiki.office.viewer.internal.DefaultOfficeResourceViewer.java
private XDOMOfficeDocument createXDOM(DocumentReference ownerDocument, ResourceReference resourceReference, Map<String, ?> parameters) throws Exception { InputStream officeFileStream; String officeFileName;/*from w ww . j a v a 2s.c om*/ if (resourceReference.getType().equals(ResourceType.URL)) { URL url = new URL(resourceReference.getReference()); officeFileStream = url.openStream(); officeFileName = StringUtils.substringAfterLast(url.getPath(), "/"); } else { throw new Exception(String.format("Unsupported resource type [%s].", resourceReference.getType())); } return createXDOM(ownerDocument, officeFileStream, officeFileName, parameters); }