List of usage examples for org.apache.commons.lang3 StringUtils removeEnd
public static String removeEnd(final String str, final String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null .
From source file:com.norconex.commons.lang.ClassFinder.java
private static String resolveName(ClassLoader loader, String rawName, Class<?> superClass) { String className = rawName;//from w ww. j a v a2 s . com if (!rawName.endsWith(".class") || className.contains("$")) { return null; } className = className.replaceAll("[\\\\/]", "."); className = StringUtils.removeStart(className, "."); className = StringUtils.removeEnd(className, ".class"); try { Class<?> clazz = loader.loadClass(className); // load only concrete implementations if (!clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers()) && superClass.isAssignableFrom(clazz)) { return clazz.getName(); } } catch (ClassNotFoundException e) { LOG.error("Invalid class: " + className, e); } catch (NoClassDefFoundError e) { LOG.debug("Invalid class: " + className, e); } return null; }
From source file:annis.libgui.AnnisBaseUI.java
protected Map<String, InstanceConfig> loadInstanceConfig() { TreeMap<String, InstanceConfig> result = new TreeMap<String, InstanceConfig>(); // get a list of all directories that contain instance informations List<File> locations = getAllConfigLocations("instances"); for (File root : locations) { if (root.isDirectory()) { // get all sub-files ending on ".json" File[] instanceFiles = root.listFiles((FilenameFilter) new SuffixFileFilter(".json")); for (File i : instanceFiles) { if (i.isFile() && i.canRead()) { try { InstanceConfig config = getJsonMapper().readValue(i, InstanceConfig.class); String name = StringUtils.removeEnd(i.getName(), ".json"); config.setInstanceName(name); result.put(name, config); } catch (IOException ex) { log.warn("could not parsing instance config: " + ex.getMessage()); }// w ww . j a v a 2s. c o m } } } } // always provide a default instance if (!result.containsKey("default")) { InstanceConfig cfgDefault = new InstanceConfig(); cfgDefault.setInstanceDisplayName("ANNIS"); result.put("default", cfgDefault); } return result; }
From source file:com.ewcms.site.model.Channel.java
private String removeStartAndEndPathSeparator(final String dir) { String path = dir;/* ww w . j a va2s.c o m*/ path = StringUtils.removeStart(path, PATH_SEPARATOR); path = StringUtils.removeEnd(path, PATH_SEPARATOR); return path; }
From source file:io.wcm.devops.maven.nodejsproxy.resource.MavenProxyResource.java
/** * Maps all requests to NPM binaries simulating a Maven 2 directory structure. *///from w w w. ja v a 2 s . c o m @GET @Path("{groupIdPath:[a-zA-Z0-9\\-\\_]+(/[a-zA-Z0-9\\-\\_]+)*}" + "/{artifactId:[a-zA-Z0-9\\-\\_\\.]+}" + "/{version:\\d+(\\.\\d+)*}" + "/{artifactIdFilename:[a-zA-Z0-9\\-\\_\\.]+}" + "-{versionFilename:\\d+(\\.\\d+)*}" + ".{type:[a-z]+(\\.[a-z]+)*(\\.sha1)?}") @Timed public Response getBinary(@PathParam("groupIdPath") String groupIdPath, @PathParam("artifactId") String artifactId, @PathParam("version") String version, @PathParam("artifactIdFilename") String artifactIdFilename, @PathParam("versionFilename") String versionFilename, @PathParam("type") String type) throws IOException { String groupId = mapGroupId(groupIdPath); if (!validateBasicParams(groupId, artifactId, version, artifactIdFilename, versionFilename)) { return Response.status(Response.Status.NOT_FOUND).build(); } ArtifactType artifactType = getArtifactType(artifactId); if (artifactType != ArtifactType.NPM) { return Response.status(Response.Status.NOT_FOUND).build(); } boolean getChecksum = false; if (StringUtils.endsWith(type, ".sha1")) { getChecksum = true; } String url = buildBinaryUrl(artifactType, version, null, null, StringUtils.removeEnd(type, ".sha1")); return getBinary(url, version, getChecksum, null); }
From source file:io.ecarf.core.term.TermUtils.java
License:asdf
/** * Split the provided term into 2 parts using the slash a separator. Uses some rules concerning : and ? * Some examples:/* w ww . ja va 2s. c o m*/ * <http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/PTO/srchnum.htm&r=1&f=G&l=50&s1=6348648.PN.&OS=PN/6348648&RS=PN/6348648/> [patft.uspto.gov/netacgi, nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/PTO/srchnum.htm&r=1&f=G&l=50&s1=6348648.PN.&OS=PN/6348648&RS=PN/6348648/] <http://www.honda.lv/> [www.honda.lv] <http://gmail.com> [gmail.com] <http://gmail.com:8080/Test?id=test> [gmail.com:8080, Test?id=test] <http://web.archive.org/web/20051031200142/http:/www.mkaz.com/ebeab/history/> [web.archive.org/web/20051031200142, http:/www.mkaz.com/ebeab/history/] <http://web.archive.org/web/20051031200142/?http:/www.mkaz.com/ebeab/history/> [web.archive.org/web/20051031200142, ?http:/www.mkaz.com/ebeab/history/] <http://web.archive.org/web/20051031200142/http:/www.mkaz.com?id=ebeab/history/> [web.archive.org/web/20051031200142, http:/www.mkaz.com?id=ebeab/history/] <http://www.hel.fi/wps/portal/Helsinki_en/?WCM_GLOBAL_CONTEXT=/en/Helsinki/> [www.hel.fi/wps/portal/Helsinki_en, ?WCM_GLOBAL_CONTEXT=/en/Helsinki/] <http://dbpedia.org/resource/Team_handball> [dbpedia.org/resource, Team_handball] <http://dbpedia.org/ontology/wikiPageExternalLink> [dbpedia.org/ontology, wikiPageExternalLink] <http://www.nfsa.gov.au/blog/2012/09/28/tasmanian-time-capsule/> [www.nfsa.gov.au/blog/2012/09/28/tasmanian-time-capsule] <http://www.whereis.com/whereis/mapping/renderMapAddress.do?name=&streetNumber=&street=City%20Center&streetType=&suburb=Hobart&state=Tasmania&latitude=-42.881&longitude=147.3265&navId=$01006046X0OL9$&brandId=1&advertiser Id=&requiredZoomLevel=3> [www.whereis.com/whereis/mapping, renderMapAddress.do?name=&streetNumber=&street=City%20Center&streetType=&suburb=Hobart&state=Tasmania&latitude=-42.881&longitude=147.3265&navId=$01006046X0OL9$&brandId=1&advertiserId=&re quiredZoomLevel=3] * @param term * @param splitLocation - the location of the slash * @return */ public static List<String> splitIntoTwo(String term, boolean hasProtocol, int splitLocation) { String path; if (hasProtocol) { String url = term.substring(1, term.length() - 1); path = StringUtils.removeStart(url, TermUtils.HTTP); if (path.length() == url.length()) { path = StringUtils.removeStart(path, TermUtils.HTTPS); } } else { path = term; } // remove trailing slash if (StringUtils.endsWith(path, URI_SEP_STR)) { path = StringUtils.removeEnd(path, URI_SEP_STR); } //System.out.println(path); List<String> parts = new ArrayList<>(); int slashIdx = path.indexOf(TermUtils.URI_SEP); ; switch (splitLocation) { case 0: // the first slash break; case 1: // the second slash slashIdx = path.indexOf(TermUtils.URI_SEP, slashIdx + 1); break; case -1: default: // the last slash slashIdx = path.lastIndexOf(TermUtils.URI_SEP); int colonIdx = path.indexOf(':'); int questionIdx = path.indexOf('?'); if (((colonIdx > -1) && (slashIdx > colonIdx)) || ((questionIdx > -1) && (slashIdx > questionIdx))) { int idx = -1; boolean colonAndQuestion = (colonIdx > -1) && (questionIdx > -1); if ((colonAndQuestion && (colonIdx < questionIdx)) || (colonIdx > -1)) { idx = getCharIdxBeforeOrAfterIdx(path, colonIdx, TermUtils.URI_SEP); } else if ((colonAndQuestion && (colonIdx > questionIdx)) || (questionIdx > -1)) { idx = getCharIdxBeforeOrAfterIdx(path, questionIdx, TermUtils.URI_SEP); } if (idx > -1) { slashIdx = idx; } } } if (slashIdx > -1) { String part = path.substring(0, slashIdx); if (part.length() > 0) { parts.add(part); } slashIdx++; if (slashIdx < path.length()) { parts.add(path.substring(slashIdx)); } } else { parts.add(path); } return parts; }
From source file:gobblin.data.management.conversion.hive.converter.HiveAvroToOrcConverter.java
private String getOrcDataLocation(WorkUnitState workUnit, String avroDataLocation, String orcTableName, Optional<String> postfix) { String orcDataLocation;//from ww w .j a v a 2 s . com // By default ORC table creates a new directory where Avro data resides with _orc postfix, but this can be // .. overridden by specifying this property String orcTableAlternateLocation = workUnit.getJobState().getProp(ORC_TABLE_ALTERNATE_LOCATION); if (StringUtils.isNotBlank(orcTableAlternateLocation)) { orcDataLocation = new Path(orcTableAlternateLocation, orcTableName).toString(); } else { orcDataLocation = StringUtils.removeEnd(avroDataLocation, Path.SEPARATOR) + "_orc"; } if (postfix.isPresent()) { orcDataLocation += postfix.get(); } // Each job execution further writes to a sub-directory within ORC data directory to support stagin use-case // .. ie for atomic swap orcDataLocation += Path.SEPARATOR + workUnit.getJobState().getId(); return orcDataLocation; }
From source file:de.blizzy.documentr.subscription.SubscriptionStore.java
public Set<String> getSubscriberEmails(String projectName, String branchName, String path) throws IOException { ILockedRepository repo = null;//from w w w .ja v a2 s .c om try { repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false); File workingDir = RepositoryUtil.getWorkingDir(repo.r()); FileFilter fileFilter = new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().endsWith(SUBSCRIPTIONS_SUFFIX); } }; List<File> files = Lists.newArrayList(workingDir.listFiles(fileFilter)); Function<File, String> loginNamesFunction = new Function<File, String>() { @Override public String apply(File file) { return StringUtils.removeEnd(file.getName(), SUBSCRIPTIONS_SUFFIX); } }; List<String> loginNames = Lists.transform(files, loginNamesFunction); Set<String> emails = Sets.newHashSet(); for (Iterator<String> iter = loginNames.iterator(); iter.hasNext();) { String loginName = iter.next(); User user = userStore.getUser(loginName); if (isSubscribed(projectName, branchName, path, user, repo)) { emails.add(user.getEmail()); } } log.debug("emails subscribed to {}/{}/{}: {}", projectName, branchName, Util.toUrlPagePath(path), //$NON-NLS-1$ emails); return emails; } finally { Closeables.closeQuietly(repo); } }
From source file:com.sonicle.webtop.core.versioning.SqlUpgradeScript.java
private void readFile(InputStreamReader readable, boolean flatNewLines) throws IOException { this.statements = new ArrayList<>(); StringBuilder sb = null, sbsql = null; String lines[] = null;/*from ww w . j a va 2 s. c o m*/ Scanner s = new Scanner(readable); s.useDelimiter("(;( )?(\r)?\n)"); //s.useDelimiter("(;( )?(\r)?\n)|(--\n)"); while (s.hasNext()) { String block = s.next(); block = StringUtils.replace(block, "\r", ""); if (!StringUtils.isEmpty(block)) { // Remove remaining ; at the end of the block (only if this block is the last one) if (!s.hasNext() && StringUtils.endsWith(block, ";")) block = StringUtils.left(block, block.length() - 1); sb = new StringBuilder(); sbsql = new StringBuilder(); lines = StringUtils.split(block, "\n"); for (String line : lines) { if (AnnotationLine.matches(line)) { if (DataSourceAnnotationLine.matches(line)) { statements.add(new DataSourceAnnotationLine(line)); } else if (IgnoreErrorsAnnotationLine.matches(line)) { statements.add(new IgnoreErrorsAnnotationLine(line)); } else if (RequireAdminAnnotationLine.matches(line)) { statements.add(new RequireAdminAnnotationLine(line)); } else { throw new IOException("Bad line: " + line); } } else if (CommentLine.matches(line)) { sb.append(line); sb.append("\n"); } else { sbsql.append(StringUtils.trim(line)); sbsql.append(" "); if (!flatNewLines) sbsql.append("\n"); } } if (sb.length() > 0) statements.add(new CommentLine(StringUtils.removeEnd(sb.toString(), "\n"))); if (sbsql.length() > 0) statements.add(new SqlLine(StringUtils.removeEnd(sbsql.toString(), "\n"))); } } }
From source file:com.amazonaws.service.apigateway.importer.impl.sdk.ApiGatewaySdkApiImporter.java
/** * Build the full resource path, including base path, add any missing leading '/', remove any trailing '/', * and remove any double '/'//w w w . j av a2s. c o m * @param basePath the base path * @param resourcePath the resource path * @return the full path */ protected String buildResourcePath(String basePath, String resourcePath) { if (basePath == null) { basePath = ""; } String base = trimSlashes(basePath); if (!base.equals("")) { base = "/" + base; } String result = StringUtils.removeEnd(base + "/" + trimSlashes(resourcePath), "/"); if (result.equals("")) { result = "/"; } return result; }
From source file:com.dell.asm.asmcore.asmmanager.util.deployment.HostnameUtil.java
String stripDnsSuffix(String hostname, String suffix) { // Strip trailing . hostname = StringUtils.removeEnd(hostname, "."); suffix = StringUtils.removeEnd(suffix, "."); // Remove suffix if (suffix != null) { if (hostname.endsWith(suffix)) { hostname = hostname.substring(0, hostname.length() - suffix.length()); }/*from w w w . ja v a2 s . c o m*/ } return StringUtils.removeEnd(hostname, "."); }