List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:com.conversantmedia.mapreduce.tool.RunJob.java
public static void main(String[] args) throws ToolException, IOException { // Get the base packages from the classpath resource String[] scanPackages = getBasePackagesToScanForDrivers(); // Initialize the reflections object Reflections reflections = initReflections((Object[]) scanPackages); // Search the classpath for Tool and Driver annotations Map<String, DriverMeta> idMap = findAllDrivers(reflections); if (idMap.isEmpty()) { System.out.printf("No drivers found in package(s) [%s]\n", StringUtils.join(scanPackages, ",")); System.exit(0);/*from w w w . j a va2s . c o m*/ } // Expects the first argument to be the id of the // tool to run. Otherwise list them all: if (args.length < 1) { outputDriversTable(idMap); System.exit(0); } // Shift off the first (driver id) argument String id = args[0]; args = ArrayUtils.subarray(args, 1, args.length); DriverMeta driverMeta = idMap.get(id); if (driverMeta == null) { if (StringUtils.isNotBlank(id) && !StringUtils.startsWith(id, "-")) { // don't output message if no driver was specified // or if the first arg is an argument such as --conf (from runjob script) System.out.println("No Tool or Driver class found with id [" + id + "]"); } outputDriversTable(idMap); System.exit(1); } // Finally, run the tool runDriver(driverMeta, args); }
From source file:fi.foyt.fni.utils.licenses.CreativeCommonsUtils.java
public static CreativeCommonsLicense parseLicenseUrl(String url) { if (StringUtils.isNotBlank(url)) { boolean secure = url.startsWith("https:"); url = url.substring(secure ? 6 : 5); if (StringUtils.startsWith(url, CreativeCommonsLicense.URL_PREFIX)) { String[] parts = StringUtils.substring(url, CreativeCommonsLicense.URL_PREFIX.length()).split("/"); if (parts.length == 1) { // Public domain ? if (StringUtils.equals(parts[0], "publicdomain")) { return new CreativeCommonsLicense(secure, new String[] { "publicdomain" }, "", ""); } else { // Without jurisdiction and version return new CreativeCommonsLicense(secure, parts[0].split("-"), "3.0", ""); }// ww w .j av a2s . c om } else if (parts.length == 2) { // Without jurisdiction return new CreativeCommonsLicense(secure, parts[0].split("-"), parts[1], ""); } else if (parts.length == 3) { // With jurisdiction return new CreativeCommonsLicense(secure, parts[0].split("-"), parts[1], parts[2]); } } } return null; }
From source file:com.mb.framework.util.StringUtil.java
/** * This method is used for checking string start with prefix * /*from ww w . ja v a2s . c om*/ * @param str * @param prefix * @return */ public static boolean startWith(String str, String prefix) { return StringUtils.startsWith(str, prefix); }
From source file:com.yevster.spdxtra.Validate.java
public static void spdxLicenseId(String spdxId) { boolean valid = StringUtils.isNotBlank(spdxId) && !StringUtils.containsAny(spdxId, '#', ':') && StringUtils.startsWith(spdxId, "LicenseRef-"); if (!valid)/*from www . j a va 2 s .c o m*/ throw exceptionFactory.apply(spdxId + " is not a valid SPDX License ID."); }
From source file:io.wcm.devops.conga.plugins.aem.crypto.CryptoString.java
/** * Checks if the given string contains an encrypted string. * @param text String to check// w w w. j a v a 2s . c om * @return true if string is assumed to be encrypted */ public static boolean isCryptoString(final String text) { // very simplified check - just check for start and end of curly braces. return text != null && text.length() > 2 && StringUtils.startsWith(text, "{") && StringUtils.endsWith(text, "}"); }
From source file:ch.cyberduck.core.URIEncoder.java
/** * URL encode a path// w w w . jav a2 s . c o m * * @param p Path * @return URI encoded * @see java.net.URLEncoder#encode(String, String) */ public static String encode(final String p) { try { final StringBuilder b = new StringBuilder(); final StringTokenizer t = new StringTokenizer(p, "/"); if (!t.hasMoreTokens()) { return p; } if (StringUtils.startsWith(p, String.valueOf(Path.DELIMITER))) { b.append(Path.DELIMITER); } while (t.hasMoreTokens()) { b.append(URLEncoder.encode(t.nextToken(), "UTF-8")); if (t.hasMoreTokens()) { b.append(Path.DELIMITER); } } if (StringUtils.endsWith(p, String.valueOf(Path.DELIMITER))) { b.append(Path.DELIMITER); } // Because URLEncoder uses <code>application/x-www-form-urlencoded</code> we have to replace these // for proper URI percented encoding. return b.toString().replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } catch (UnsupportedEncodingException e) { return p; } }
From source file:com.yevster.spdxtra.Validate.java
public static void spdxElementId(String spdxId) { boolean valid = StringUtils.isNotBlank(spdxId) && !StringUtils.containsAny(spdxId, '#', ':') && StringUtils.startsWith(spdxId, "SPDXRef-"); if (!valid)//from w w w .j av a 2 s . c om throw exceptionFactory.apply(spdxId + " is not a valid SPDX Element ID."); }
From source file:com.omnigon.aem.common.utils.url.SlingUrlBuilder.java
public static SlingUrlBuilder create(final String uri) { if (StringUtils.isNotBlank(uri)) { try {// w w w .j a v a 2 s .c o m URI u = URLUtils.createURI(uri); String path = u.getPath(); if (u.isAbsolute() || StringUtils.isBlank(path)) { return new AbsoluteUrlBuilder(u.toASCIIString()); } else { if (!StringUtils.startsWith(path, "/")) { path = "/" + path; } return create(new PathInfo(path)); } } catch (Exception e) { LOG.error(e.getMessage(), e); } } return new NullUrlBuilder(); }
From source file:io.wcm.sling.commons.resource.ResourceType.java
/** * Converts the resource type to an absolute path. If it does not start with "/" the resource is resolved * via search paths using resource resolver. If not matching resource is found it is returned unchanged. * @param resourceType Resource type/*from w w w . j av a 2s. c o m*/ * @return Absolute resource type */ public static String makeAbsolute(String resourceType, ResourceResolver resourceResolver) { if (StringUtils.isEmpty(resourceType) || StringUtils.startsWith(resourceType, "/")) { return resourceType; } // first try to resolve path via component manager - because on publish instance the original resource may not accessible ComponentManager componentManager = resourceResolver.adaptTo(ComponentManager.class); if (componentManager != null) { Component component = componentManager.getComponent(resourceType); if (component != null) { return component.getPath(); } else { return resourceType; } } // otherwise use resource resolver directly Resource resource = resourceResolver.getResource(resourceType); if (resource != null) { return resource.getPath(); } else { return resourceType; } }
From source file:com.github.juanmf.java2plant.util.CanonicalName.java
public static CanonicalName forCode(String code) { for (CanonicalName c : CanonicalName.values()) { if (StringUtils.startsWith(code, c.code)) { return c; }/*w ww. j a v a2 s . c o m*/ } throw new IllegalArgumentException("Not an enum constant name: " + code); }