List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:com.monarchapis.client.authentication.HawkV1RequestProcessor.java
private static String getHawkHash(BaseClient<?> client) { try {//from w ww. j a v a 2 s . co m StringBuilder sb = new StringBuilder(); String httpContent = client.getBody(); String mimeType = ""; String content = ""; if (httpContent != null) { mimeType = StringUtils.trimToEmpty(StringUtils.substringBefore(client.getContentType(), ";")); content = httpContent; } sb.append("hawk.1.payload\n"); sb.append(mimeType); sb.append("\n"); sb.append(content); sb.append("\n"); MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(sb.toString().getBytes("UTF-8")); return Base64.encodeBase64String(hash); } catch (Exception e) { throw new RuntimeException("Could not create hawk hash", e); } }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.agent.ServiceCachingAgent.java
public static Map<String, Object> convertServiceToAttributes(String accountName, String region, Service service) {/*www.j a v a2 s.c o m*/ Map<String, Object> attributes = new HashMap<>(); String applicationName = service.getServiceName().contains("-") ? StringUtils.substringBefore(service.getServiceName(), "-") : service.getServiceName(); String clusterName = StringUtils.substringAfterLast(service.getClusterArn(), "/"); attributes.put("account", accountName); attributes.put("region", region); attributes.put("applicationName", applicationName); attributes.put("serviceName", service.getServiceName()); attributes.put("serviceArn", service.getServiceArn()); attributes.put("clusterName", clusterName); attributes.put("clusterArn", service.getClusterArn()); attributes.put("roleArn", service.getRoleArn()); attributes.put("taskDefinition", service.getTaskDefinition()); attributes.put("desiredCount", service.getDesiredCount()); attributes.put("maximumPercent", service.getDeploymentConfiguration().getMaximumPercent()); attributes.put("minimumHealthyPercent", service.getDeploymentConfiguration().getMinimumHealthyPercent()); attributes.put("loadBalancers", service.getLoadBalancers()); attributes.put("createdAt", service.getCreatedAt().getTime()); return attributes; }
From source file:com.sunlights.common.utils.PropertyFilter.java
/** * @param filterName/*from w ww . jav a2s .c om*/ * @param value */ public PropertyFilter(final String filterName, final String value) { String matchTypeStr; String matchPattenCode = LikeMatchPatten.ALL.toString(); String matchTypeCode; String propertyTypeCode; if (filterName.contains("LIKE") && filterName.charAt(0) != 'L') { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchPattenCode = StringUtils.substring(matchTypeStr, 0, 1); matchTypeCode = StringUtils.substring(matchTypeStr, 1, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } else { matchTypeStr = StringUtils.substringBefore(filterName, PARAM_PREFIX); matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); } try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); likeMatchPatten = Enum.valueOf(LikeMatchPatten.class, matchPattenCode); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with rules, not get more types of property.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException("filter name: " + filterName + "Not prepared in accordance with the rules, attribute value types can not be.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, PARAM_PREFIX); propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR); Validate.isTrue(propertyNames.length > 0, "filter name: " + filterName + "Not prepared in accordance with the rules, property names can not be."); this.propertyValue = ConvertUtils.convert(value, propertyType); }
From source file:io.wcm.devops.conga.model.util.MapExpander.java
private static Map.Entry<String, Object> expandEntry(Map.Entry<String, Object> entry) { if (!StringUtils.contains(entry.getKey(), ".")) { return new MapEntry<String, Object>(entry.getKey(), expandDeep(entry.getValue())); }//w w w . j ava 2 s .c o m String key = StringUtils.substringBefore(entry.getKey(), "."); String remaining = StringUtils.substringAfter(entry.getKey(), "."); Map<String, Object> map = new HashMap<>(); map.put(remaining, expandDeep(entry.getValue())); Map<String, Object> expandedMap = expand(map); return new MapEntry<String, Object>(key, expandedMap); }
From source file:net.sf.dynamicreports.report.builder.chart.SeriesOrderByNamesComparator.java
@Override public int compare(String o1, String o2) { String row1;/*from w w w .j a v a2 s . com*/ String row2; if (StringUtils.countMatches(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY) == 1 && StringUtils.countMatches(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY) == 1) { String group1 = StringUtils.substringBefore(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); String group2 = StringUtils.substringBefore(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); int compare = group1.compareTo(group2); if (compare != 0) { return compare; } row1 = StringUtils.substringAfter(o1, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); row2 = StringUtils.substringAfter(o2, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); } else { row1 = o1; row2 = o2; } int index1 = seriesNames.indexOf(row1); int index2 = seriesNames.indexOf(row2); if (index1 < 0 && index2 < 0) { return row1.compareTo(row2); } if (index1 == index2) { return 0; } if (index1 < 0) { return index1 * -1; } if (index2 < 0) { return index2; } return index1 - index2; }
From source file:com.erudika.para.rest.RestUtils.java
/** * Extracts the access key from a request. It can be a header or a parameter. * @param request a request// www .j a va 2 s. c o m * @return the access key */ public static String extractAccessKey(HttpServletRequest request) { if (request == null) { return ""; } String auth = request.getHeader(HttpHeaders.AUTHORIZATION); if (StringUtils.isBlank(auth)) { auth = request.getParameter("X-Amz-Credential"); if (StringUtils.isBlank(auth)) { return ""; } else { return StringUtils.substringBefore(auth, "/"); } } else { String credential = StringUtils.substringBetween(auth, "Credential=", ","); return StringUtils.substringBefore(credential, "/"); } }
From source file:com.norconex.importer.handler.tagger.AbstractCharStreamTagger.java
@Override protected final void tagApplicableDocument(String reference, InputStream document, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException { String contentType = metadata.getString("Content-Type", ""); contentType = StringUtils.substringBefore(contentType, ";"); String charset = metadata.getString("Content-Encoding", null); if (charset == null) { charset = metadata.getString("charset", null); }/*from w w w.jav a2 s.co m*/ if (charset == null) { for (String type : metadata.getStrings("Content-Type")) { if (type.contains("charset")) { charset = StringUtils.trimToNull(StringUtils.substringAfter(type, "charset=")); break; } } } if (StringUtils.isBlank(charset) || !CharEncoding.isSupported(charset)) { charset = CharEncoding.UTF_8; } try { InputStreamReader is = new InputStreamReader(document, charset); tagTextDocument(reference, is, metadata, parsed); } catch (UnsupportedEncodingException e) { throw new ImporterHandlerException(e); } }
From source file:de.crowdcode.movmvn.core.ContextImpl.java
/** * {@inheritDoc}// w w w .j av a 2s .c o m */ @Override public String getProjectName() { if (zipFile != null && !zipFile.equals("")) { String nameWithoutZip = StringUtils.substringBefore(zipFile, ".zip"); String nameResult = StringUtils.substringAfterLast(nameWithoutZip, "/"); if (nameResult.equals("")) { // We have no "/" instead "\\" nameResult = StringUtils.substringAfterLast(nameWithoutZip, "\\"); } return nameResult; } else if (directory != null && !directory.equals("")) { String nameResult = StringUtils.substringAfterLast(directory, "/"); if (nameResult.equals("")) { // We have no "/" instead "\\" nameResult = StringUtils.substringAfterLast(directory, "\\"); } return nameResult; } else { return ""; } }
From source file:info.magnolia.photoreview.app.container.RecursiveBeanItem.java
@Override public Property<?> getItemProperty(Object id) { if (id instanceof String && ((String) id).contains(SEPARATOR)) { String thisKey = StringUtils.substringBefore((String) id, SEPARATOR); String nextKey = StringUtils.substringAfter((String) id, SEPARATOR); Property<?> property = super.getItemProperty(thisKey); Object subBean = property.getValue(); if (subBean != null) { return new RecursiveBeanItem(subBean).getItemProperty(nextKey); } else {// www . j a va 2s. co m return null; } } return super.getItemProperty(id); }
From source file:com.mgmtp.jfunk.data.source.BaseDataSource.java
/** * Creates a new instance of the data source, reading fixed properties from the configuration. * /*from ww w .j a va 2 s . co m*/ * @param configuration * Configuration for the data source. */ protected BaseDataSource(final Configuration configuration) { this.name = StringUtils.uncapitalize(StringUtils.substringBefore(getClass().getSimpleName(), "DataSource")); this.configuration = configuration; }