List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:com.cognifide.bdd.demo.aem.AemContentFinderTest.java
@Test public void shouldOpenCorrectTabs() { contentFinder.clickTab(TABS_NAMES[0]); assertThat(contentFinder.getCurrentTabName(), is(TABS_NAMES[0])); // Resize to make element TABS_NAMES[1] clickable contentFinder.resize(500);/*from www .ja va2 s . c om*/ contentFinder.clickTab(TABS_NAMES[1]); final String browseName = StringUtils.removeStart(contentFinder.getCurrentTabName(), "S7"); assertThat(browseName, is(TABS_NAMES[1])); contentFinder.clickTab(TABS_NAMES[2]); assertThat(contentFinder.getCurrentTabName(), is(TABS_NAMES[2])); }
From source file:com.technophobia.substeps.model.Arguments.java
public static String[] getArgs(final String patternString, final String sourceString, final String[] keywordPrecedence, Config cfg) { log.debug("Arguments getArgs String[] with pattern: " + patternString + " and sourceStr: " + sourceString); String[] rtn = null;/*from www. j a v a2 s.c o m*/ ArrayList<String> argsList = null; String patternCopy = patternString; if (keywordPrecedence != null && StringUtils.startsWithAny(patternString, keywordPrecedence)) { // for (String s : keywordPrecedence) { patternCopy = StringUtils.removeStart(patternCopy, s); } patternCopy = "(?:" + StringUtils.join(keywordPrecedence, "|") + ")" + patternCopy; } final Pattern pattern = Pattern.compile(patternCopy); final Matcher matcher = pattern.matcher(sourceString); final int groupCount = matcher.groupCount(); // TODO - this doesn't work if we're not doing strict matching if (matcher.find()) { for (int i = 1; i <= groupCount; i++) { final String arg = substituteValues(matcher.group(i), cfg); if (arg != null) { if (argsList == null) { argsList = new ArrayList<>(); } argsList.add(arg); } } } if (argsList != null) { rtn = argsList.toArray(new String[argsList.size()]); if (log.isDebugEnabled()) { final StringBuilder buf = new StringBuilder(); buf.append("returning args: "); for (final String s : argsList) { buf.append("[").append(s).append("] "); } log.debug(buf.toString()); } } return rtn; }
From source file:com.conversantmedia.mapreduce.mrunit.UnitTestDistributedResourceManager.java
@SuppressWarnings("unchecked") protected void addDistributedProperties(Class<?> clazz, List<String> properties) { Distribute distribute;//from w ww .j a va2 s. c om MaraAnnotationUtil util = MaraAnnotationUtil.INSTANCE; List<Field> fields = util.findAnnotatedFields(clazz, Distribute.class); for (Field field : fields) { distribute = field.getAnnotation(Distribute.class); String prop = StringUtils.isBlank(distribute.name()) ? field.getName() : distribute.name(); properties.add(prop); } List<Method> methods = util.findAnnotatedMethods(clazz, Distribute.class); for (Method method : methods) { distribute = AnnotationUtils.findAnnotation(method, Distribute.class); String defaultName = StringUtils.uncapitalize(StringUtils.removeStart(method.getName(), "get")); String prop = StringUtils.isBlank(distribute.name()) ? defaultName : distribute.name(); properties.add(prop); } }
From source file:com.nridge.connector.fs.con_fs.restlet.ResourceDocView.java
private DataBag loadDocument(String anId) { RestletApplication restletApplication = (RestletApplication) getApplication(); AppMgr appMgr = restletApplication.getAppMgr(); Logger appLogger = appMgr.getLogger(this, "loadDocument"); DataBag docBag = new DataBag(anId, "Solr Document Load"); appLogger.trace(appMgr.LOGMSG_TRACE_ENTER); String propertyName = Constants.CFG_PROPERTY_PREFIX + ".solr.request_uri"; String solrURI = appMgr.getString(propertyName); if (StringUtils.isNotEmpty(solrURI)) { propertyName = Constants.CFG_PROPERTY_PREFIX + ".solr.request_handler"; String propertyValue = appMgr.getString(propertyName, Constants.SOLR_REQUEST_HANDLER_DEFAULT); String requestHandler = StringUtils.removeStart(propertyValue, "/"); String solrURL = String.format("%s/%s?q=nsd_id%%3A%s&wt=xml&echoParams=none", solrURI, requestHandler, anId);//from w w w .j a v a 2 s .co m SolrDS solrDS = new SolrDS(appMgr); solrDS.setCfgPropertyPrefix(Constants.CFG_PROPERTY_PREFIX + ".solr"); DSCriteria dsCriteria = new DSCriteria("Solr Document Exists"); dsCriteria.add(Solr.FIELD_URL_NAME, Field.Operator.EQUAL, solrURL); try { Document solrDocument = solrDS.fetch(dsCriteria, 0, 1); Document responseDocument = solrDocument.getFirstRelatedDocument(Solr.RESPONSE_DOCUMENT); DataTable resultTable = responseDocument.getTable(); int rowCount = resultTable.rowCount(); appLogger.debug(String.format("[%d] %s", rowCount, solrURL)); if (rowCount > 0) docBag = resultTable.getRowAsBag(0); else { String msgStr = String.format("Cannot view document - document '%s' does not exist in Solr.", anId); docBag.addProperty(PROPERTY_ERROR_MESSAGE, msgStr); appLogger.error(msgStr); } } catch (DSException e) { appLogger.error(String.format("%s: %s", solrURL, e.getMessage())); } finally { solrDS.shutdown(); } } else { String msgStr = String.format("Cannot view document - '%s' is undefined.", propertyName); docBag.addProperty(PROPERTY_ERROR_MESSAGE, msgStr); appLogger.error(msgStr); } appLogger.trace(appMgr.LOGMSG_TRACE_DEPART); return docBag; }
From source file:blue.lapis.pore.ap.event.EventVerifierProcessor.java
private void verifyName(TypeElement type) { TypeElement bukkitEvent = (TypeElement) ((DeclaredType) type.getSuperclass()).asElement(); String poreName = StringUtils.removeStart(type.getQualifiedName().toString(), PORE_PREFIX); String porePackage = StringUtils.substringBeforeLast(poreName, "."); poreName = StringUtils.substringAfterLast(poreName, "."); String bukkitName = StringUtils.removeStart(bukkitEvent.getQualifiedName().toString(), BUKKIT_PREFIX); String bukkitPackage = StringUtils.substringBeforeLast(bukkitName, "."); bukkitName = StringUtils.substringAfterLast(bukkitName, "."); String expectedName = "Pore" + bukkitName; if (!poreName.equals(expectedName)) { processingEnv.getMessager().printMessage(SEVERITY, poreName + " should be called " + expectedName, type);/*from w w w . j a va 2 s . c o m*/ } if (!porePackage.equals(bukkitPackage)) { processingEnv.getMessager().printMessage(SEVERITY, poreName + " is in wrong package: should be in " + PORE_PREFIX + bukkitPackage, type); } }
From source file:io.ecarf.core.term.dictionary.TermDictionary.java
/** * Encode a term in the format <http://dbpedia.org/resource/Alexander_II_of_Russia> * @param term/*from w ww . java 2s. c o m*/ * @return */ public long encode(String term) { long value = 0; if (SchemaURIType.RDF_OWL_TERMS.contains(term)) { value = this.get(term); } else { // TODO why I'm using this code here instead of TermUtils.split? // because I need to efficiently check for https String url = term.substring(1, term.length() - 1); String path = StringUtils.removeStart(url, TermUtils.HTTP); boolean https = false; if (path.length() == url.length()) { path = StringUtils.removeStart(path, TermUtils.HTTPS); https = true; } //String [] parts = StringUtils.split(path, URI_SEP); // this is alot faster than String.split or StringUtils.split List<String> parts = TermUtils.splitIntoTwo(term); if (!parts.isEmpty()) { // 1- encode parts long[] values = new long[parts.size()]; int index = 0; Integer enc; for (String part : parts) { enc = this.get(part); if (enc == null) { throw new IllegalArgumentException("Term part not found in the dictionary: " + part); } values[index] = enc; index++; } // 2- compose value = NumberUtils.join(values); // 3- add flags // 1 1 1 // has / at the end (1) or not (0) http (0) or https (1) one (1) or two (0) parts int flags = 0; if (parts.size() == 1) { flags = 1; } if (https) { flags |= 0b10; } // do we have a slash at the end of the URL or not if (url.lastIndexOf(TermUtils.URI_SEP) == (url.length() - 1)) { flags |= 0b100; } value = (value <<= 3) | flags; } else { // invalid URIs, e.g. <http:///www.taotraveller.com> is parsed by NxParser as http:/// value = RESOURCE_ID_INVALID; } } return value; }
From source file:com.labs64.utils.swid.support.SwidUtils.java
/** * <p>/*w w w . j a v a2 s.c om*/ * Revert given URL according to the <a href="http://en.wikipedia.org/wiki/Reverse_domain_name_notation">Reverse * domain name notation</a> * </p> * <p> * * @see <a * href="http://en.wikipedia.org/wiki/Reverse_domain_name_notation">http://en.wikipedia.org/wiki/Reverse_domain_name_notation</a> * </p> * * @param domainName * the domain name to be reverted * @return reverted domain name */ public static String revertDomainName(final String domainName) { if (StringUtils.isBlank(domainName)) { throw new SwidException("domainName isn't defined"); } try { URI uri = new URI(StringUtils.prependIfMissing(domainName, "http://", "https://")); String hostName = StringUtils.removeStart(uri.getHost(), "www."); String[] domainNameSplit = StringUtils.split(hostName, "."); CollectionUtils.reverseArray(domainNameSplit); return StringUtils.join(domainNameSplit, "."); } catch (URISyntaxException e) { throw new SwidException("Cannot revert domain name"); } }
From source file:info.magnolia.ui.contentapp.ContentApp.java
@Override public void openChooseDialog(UiContext overlayLayer, String targetTreeRootPath, String selectedId, final ChooseDialogCallback callback) { // fetch or compute chooseDialogDefinition from default subApp ChooseDialogDefinition chooseDialogDefinition; if (appContext.getAppDescriptor() instanceof ContentAppDescriptor) { chooseDialogDefinition = ((ContentAppDescriptor) appContext.getAppDescriptor()).getChooseDialog(); } else {/*from w w w. j ava2s . c om*/ chooseDialogDefinition = new ConfiguredChooseDialogDefinition(); } chooseDialogDefinition = ensureChooseDialogField(chooseDialogDefinition, targetTreeRootPath); chooseDialogDefinition = addAvailabilityActionRenderer(chooseDialogDefinition); // create chooseDialogComponentProvider and get new instance of presenter from there ComponentProvider chooseDialogComponentProvider = ChooseDialogComponentProviderUtil .createChooseDialogComponentProvider(overlayLayer, chooseDialogDefinition, componentProvider); presenter = chooseDialogComponentProvider.newInstance(chooseDialogDefinition.getPresenterClass(), chooseDialogComponentProvider); if (!StringUtils.isBlank(targetTreeRootPath) && !StringUtils.isBlank(selectedId) && !"/".equals(targetTreeRootPath) && selectedId.startsWith(targetTreeRootPath)) { selectedId = StringUtils.removeStart(selectedId, targetTreeRootPath); } presenter.start(callback, chooseDialogDefinition, overlayLayer, selectedId); }
From source file:com.norconex.commons.lang.ClassFinder.java
private static List<String> findSubTypesFromDirectory(File dir, Class<?> superClass) { List<String> classes = new ArrayList<String>(); String dirPath = dir.getAbsolutePath(); Collection<File> classFiles = FileUtils.listFiles(dir, new String[] { "class" }, true); ClassLoader loader = getClassLoader(dir); if (loader == null) { return classes; }/*from ww w . ja v a2s. c o m*/ for (File classFile : classFiles) { String filePath = classFile.getAbsolutePath(); String className = StringUtils.removeStart(filePath, dirPath); className = resolveName(loader, className, superClass); if (className != null) { classes.add(className); } } return classes; }
From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java
private String getNameFromMethod(Method method) { if (method.getParameterCount() > 0) { return null; }//from www . ja v a 2 s . com if (method.getReturnType().equals(Void.TYPE)) { return null; } String mthdName = method.getName(); if (mthdName.startsWith("get")) { if (mthdName.length() <= 3) { return null; } if (method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE)) { return null; } StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "get")); buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0))); return buffer.toString(); } else if (!mthdName.startsWith("is")) { if (mthdName.length() <= 2) { return null; } if (!method.getReturnType().equals(Boolean.class) && !method.getReturnType().equals(Boolean.TYPE)) { return null; } StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "is")); buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0))); return buffer.toString(); } return null; }