List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:hydrograph.ui.expression.editor.jar.util.BuildExpressionEditorDataSturcture.java
@SuppressWarnings("restriction") public PackageFragmentRoot getSrcPackageFragment(IJavaProject iJavaProject) throws JavaModelException { for (IPackageFragmentRoot iPackageFragmentRoot : iJavaProject.getAllPackageFragmentRoots()) { if (iPackageFragmentRoot instanceof PackageFragmentRoot && iPackageFragmentRoot.getKind() == iPackageFragmentRoot.K_SOURCE) { if (StringUtils.startsWith(iPackageFragmentRoot.toString(), hydrograph.ui.common.util.Constants.ProjectSupport_SRC)) { return (PackageFragmentRoot) iPackageFragmentRoot; }// w ww .ja v a2s .co m } } return null; }
From source file:com.adobe.acs.commons.util.ParameterUtil.java
/** * Util for parsing Arrays of Service properties in the form >value<>separator<>value< * * If a value is missing from a key/value pair, the entry is rejected only if allowValuelessKyes is false. * To keep the valueless keys pass in allowValuelessKeys => true * * *//from w ww .jav a2 s . c o m * @param values Array of key/value pairs in the format => [ a<separator>b, x<separator>y ] ... ex. ["dog:woof", "cat:meow"] * @param separator separator between the values * @param allowValuelessKeys true is keys are allowed without associated values * @param defaultValue default value to use if a value for a key is not present and allowValuelessKeys is true * @param allowMultipleSeparators if true, multiple separators are allowed per entry in which case only the first is considered. * If false, entries with multiple separators are considered invalid * @return */ public static Map<String, String> toMap(final String[] values, final String separator, final boolean allowValuelessKeys, final String defaultValue, final boolean allowMultipleSeparators) { final Map<String, String> map = new LinkedHashMap<String, String>(); if (values == null || values.length < 1) { return map; } for (final String value : values) { final String[] tmp = StringUtils.split(value, separator, allowMultipleSeparators ? 2 : -1); if (tmp.length == 1 && allowValuelessKeys) { if (StringUtils.startsWith(value, separator)) { // Skip keyless values continue; } map.put(tmp[0], defaultValue); } else if (tmp.length == 2) { map.put(tmp[0], tmp[1]); } } return map; }
From source file:com.mmounirou.spotirss.SpotiRss.java
private static Iterable<String> getCharts(String strProvider) throws IOException { InputStream chartsStreams = SpotiRss.class.getResourceAsStream("/" + strProvider + ".charts"); try {/*from w w w. j a v a 2 s . c o m*/ List<String> readLines = IOUtils.readLines(chartsStreams, Charsets.UTF_8); return Iterables.filter(readLines, new Predicate<String>() { @Override public boolean apply(@Nullable String input) { return !StringUtils.startsWith(input, "#"); } }); } finally { IOUtils.closeQuietly(chartsStreams); } }
From source file:com.mirth.connect.connectors.smtp.SmtpMessageDispatcher.java
@Override public void doDispatch(UMOEvent event) throws Exception { monitoringController.updateStatus(connector, connectorType, Event.BUSY); MessageObject mo = messageObjectController.getMessageObjectFromEvent(event); if (mo == null) { return;/*from www . j a v a 2 s . com*/ } try { Email email = null; if (connector.isHtml()) { email = new HtmlEmail(); } else { email = new MultiPartEmail(); } email.setCharset(connector.getCharsetEncoding()); email.setHostName(replacer.replaceValues(connector.getSmtpHost(), mo)); try { email.setSmtpPort(Integer.parseInt(replacer.replaceValues(connector.getSmtpPort(), mo))); } catch (NumberFormatException e) { // Don't set if the value is invalid } try { email.setSocketConnectionTimeout( Integer.parseInt(replacer.replaceValues(connector.getTimeout(), mo))); } catch (NumberFormatException e) { // Don't set if the value is invalid } if ("SSL".equalsIgnoreCase(connector.getEncryption())) { email.setSSL(true); } else if ("TLS".equalsIgnoreCase(connector.getEncryption())) { email.setTLS(true); } if (connector.isAuthentication()) { email.setAuthentication(replacer.replaceValues(connector.getUsername(), mo), replacer.replaceValues(connector.getPassword(), mo)); } /* * NOTE: There seems to be a bug when calling setTo with a List * (throws a java.lang.ArrayStoreException), so we are using addTo * instead. */ for (String to : replaceValuesAndSplit(connector.getTo(), mo)) { email.addTo(to); } // Currently unused for (String cc : replaceValuesAndSplit(connector.cc(), mo)) { email.addCc(cc); } // Currently unused for (String bcc : replaceValuesAndSplit(connector.getBcc(), mo)) { email.addBcc(bcc); } // Currently unused for (String replyTo : replaceValuesAndSplit(connector.getReplyTo(), mo)) { email.addReplyTo(replyTo); } for (Entry<String, String> header : connector.getHeaders().entrySet()) { email.addHeader(replacer.replaceValues(header.getKey(), mo), replacer.replaceValues(header.getValue(), mo)); } email.setFrom(replacer.replaceValues(connector.getFrom(), mo)); email.setSubject(replacer.replaceValues(connector.getSubject(), mo)); String body = replacer.replaceValues(connector.getBody(), mo); if (connector.isHtml()) { ((HtmlEmail) email).setHtmlMsg(body); } else { email.setMsg(body); } /* * If the MIME type for the attachment is missing, we display a * warning and set the content anyway. If the MIME type is of type * "text" or "application/xml", then we add the content. If it is * anything else, we assume it should be Base64 decoded first. */ for (Attachment attachment : connector.getAttachments()) { String name = replacer.replaceValues(attachment.getName(), mo); String mimeType = replacer.replaceValues(attachment.getMimeType(), mo); String content = replacer.replaceValues(attachment.getContent(), mo); byte[] bytes; if (StringUtils.indexOf(mimeType, "/") < 0) { logger.warn("valid MIME type is missing for email attachment: \"" + name + "\", using default of text/plain"); attachment.setMimeType("text/plain"); bytes = content.getBytes(); } else if ("application/xml".equalsIgnoreCase(mimeType) || StringUtils.startsWith(mimeType, "text/")) { logger.debug("text or XML MIME type detected for attachment \"" + name + "\""); bytes = content.getBytes(); } else { logger.debug("binary MIME type detected for attachment \"" + name + "\", performing Base64 decoding"); bytes = Base64.decodeBase64(content); } ((MultiPartEmail) email).attach(new ByteArrayDataSource(bytes, mimeType), name, null); } /* * From the Commons Email JavaDoc: send returns * "the message id of the underlying MimeMessage". */ String response = email.send(); messageObjectController.setSuccess(mo, response, null); } catch (EmailException e) { alertController.sendAlerts(connector.getChannelId(), Constants.ERROR_402, "Error sending email message.", e); messageObjectController.setError(mo, Constants.ERROR_402, "Error sending email message.", e, null); connector.handleException(new Exception(e)); } finally { monitoringController.updateStatus(connector, connectorType, Event.DONE); } }
From source file:ddf.catalog.source.solr.SolrFilterDelegate.java
private void combineXpathFilterQueries(SolrQuery query, List<SolrQuery> subQueries, String operator) { List<String> queryParams = new ArrayList<>(); // Use Set to remove duplicates now that the namespaces have been stripped out Set<String> xpathFilters = new TreeSet<>(); Set<String> xpathIndexes = new TreeSet<>(); for (SolrQuery subQuery : subQueries) { String[] params = subQuery.getParams(FILTER_QUERY_PARAM_NAME); if (params != null) { for (String param : params) { if (StringUtils.startsWith(param, XPATH_QUERY_PARSER_PREFIX)) { if (StringUtils.contains(param, XPATH_FILTER_QUERY_INDEX)) { xpathIndexes/*from w ww . j a v a2 s. co m*/ .add(StringUtils.substringAfter(StringUtils.substringBeforeLast(param, "\""), XPATH_FILTER_QUERY_INDEX + ":\"")); } else if (StringUtils.startsWith(param, XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY)) { xpathFilters.add(StringUtils.substringAfter( StringUtils.substringBeforeLast(param, "\""), XPATH_FILTER_QUERY + ":\"")); } } Collections.addAll(queryParams, param); } } } if (xpathFilters.size() > 1) { // More than one XPath found, need to combine String filter = XPATH_QUERY_PARSER_PREFIX + XPATH_FILTER_QUERY + ":\"(" + StringUtils.join(xpathFilters, operator.toLowerCase()) + ")\""; List<String> indexes = new ArrayList<>(); for (String xpath : xpathIndexes) { indexes.add("(" + XPATH_FILTER_QUERY_INDEX + ":\"" + xpath + "\")"); } // TODO DDF-1882 add pre-filter xpath index //String index = XPATH_QUERY_PARSER_PREFIX + StringUtils.join(indexes, operator); //query.setParam(FILTER_QUERY_PARAM_NAME, filter, index); query.setParam(FILTER_QUERY_PARAM_NAME, filter); } else if (queryParams.size() > 0) { // Pass through original filter queries if only a single XPath is present query.setParam(FILTER_QUERY_PARAM_NAME, queryParams.toArray(new String[queryParams.size()])); } }
From source file:com.pieframework.model.repository.ModelStore.java
public static List<ExpressionEntry> parseInstanceFile(File file) throws IOException { List<ExpressionEntry> retList = new ArrayList<ExpressionEntry>(); LineIterator it = FileUtils.lineIterator(file); try {/*from w w w . j ava 2 s. c o m*/ while (it.hasNext()) { String line = it.nextLine(); if (StringUtils.startsWith(line, "#")) { // ignore comments } else { String expression = StringUtils.trimToEmpty(StringUtils.substringBefore(line, "=")); String value = StringUtils.trimToEmpty(StringUtils.substringAfter(line, "=")); if (StringUtils.isNotEmpty(expression) && StringUtils.isNotEmpty(value)) { retList.add(new ExpressionEntry().withExpression(expression).withValue(value)); } } } } finally { it.close(); } return retList; }
From source file:com.intellij.plugins.haxe.ide.HaxeFindUsagesHandler.java
@Nullable private static PsiElement[] tryGetProperty(HaxeMethodDeclaration method) { final HaxeMethodModel methodModel = method.getModel(); final HaxeClassModel declaringClass = methodModel.getDeclaringClass(); final String methodName = method.getName(); HaxeMemberModel classField = null;/*from w ww . j a v a 2 s.co m*/ if (StringUtils.startsWith(methodName, GETTER_PREFIX)) { classField = declaringClass.getField(methodName.substring(GETTER_PREFIX.length())); } else if (StringUtils.startsWith(methodName, SETTER_PREFIX)) { classField = declaringClass.getField(methodName.substring(SETTER_PREFIX.length())); } return classField == null ? null : new PsiElement[] { classField.getBasePsi() }; }
From source file:com.activecq.samples.slingresourceprovider.impl.SampleSlingResourceProvider.java
/** * Checks if this Resource Provider is willing to handle the resource path * * @param path// w w w. j av a2 s .co m * @return */ protected boolean accepts(String path) { for (String root : this.roots) { if (StringUtils.startsWith(path, root.concat("/"))) { return true; } } return false; }
From source file:com.microsoft.alm.plugin.external.commands.SyncCommand.java
/** * An error will be in the following form where there are duplicates for each error. The duplicates only differ * by the fact that the first reference of the error refers to only the file name and the second reference refers * to the entire path of the file. All the file name errors are the first listed followed by all the path errors. * Only make exceptions out of the path errors and ignore the file name errors so we see no duplicates. Example * of an error message will look like this: * <p/>/* w ww .ja v a2s . c om*/ * Warning - Unable to refresh testHereRename.txt because you have a pending edit. * Conflict TestAdd.txt - Unable to perform the get operation because you have a conflicting edit * Warning - Unable to refresh /Users/user/tfvc-tfs/tfsTest_01/addFold/testHereRename.txt because you have a pending edit. * Conflict /Users/user/tfvc-tfs/tfsTest_01/TestAdd.txt - Unable to perform the get operation because you have a conflicting edit * * @param stderr * @return */ private List<SyncException> parseException(final String stderr) { final List<SyncException> exceptions = new ArrayList<SyncException>(); final String[] exceptionLines = getLines(stderr); for (int i = exceptionLines.length / 2; i < exceptionLines.length; i++) { // skip empty lines and don't treat conflicts as exceptions if (StringUtils.isNotEmpty(exceptionLines[i]) && !StringUtils.contains(exceptionLines[i], CONFLICT_MESSAGE)) { //TODO: what if warning is that file was skipped (but only shows up when force was used) final SyncException exception = new SyncException(exceptionLines[i], StringUtils.startsWith(exceptionLines[i], WARNING_PREFIX)); exceptions.add(exception); } } return exceptions; }
From source file:com.adobe.acs.commons.components.longformtext.impl.LongFormTextComponentImpl.java
private int getResourceIndex(final Resource resource) { final String resourceName = resource.getName(); if (!StringUtils.startsWith(resourceName, LONG_FORM_TEXT_PAR)) { return -1; }/*from w w w. j a va2 s. c o m*/ final String indexStr = StringUtils.removeStart(resourceName, LONG_FORM_TEXT_PAR); try { return Integer.parseInt(indexStr); } catch (NumberFormatException ex) { return -1; } }