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:de.jfachwert.bank.Bankverbindung.java
private static Object[] split(String bankverbindung) { String[] splitted = new String[3]; splitted[0] = stripSeparator(StringUtils.substringBefore(bankverbindung, "IBAN")); splitted[1] = stripSeparator(StringUtils.substringAfter(bankverbindung, "IBAN")); if (StringUtils.isBlank(splitted[1])) { throw new LocalizedIllegalArgumentException(bankverbindung, "bank_account"); }// w w w . j a va2s . co m if (splitted[1].contains("BIC")) { splitted[2] = stripSeparator(StringUtils.substringAfter(splitted[1], "BIC")); splitted[1] = stripSeparator(StringUtils.substringBefore(splitted[1], "BIC")); } else { splitted[2] = ""; } Object[] values = new Object[3]; values[0] = splitted[0]; values[1] = new IBAN(splitted[1]); values[2] = splitted[2].isEmpty() ? null : new BIC(splitted[2]); return values; }
From source file:io.wcm.handler.media.CropDimension.java
/** * Get crop dimension from crop string.// w w w . j a v a2 s.c o m * Please note: Crop string contains not width/height as 3rd/4th parameter but right, bottom. * @param cropString Cropping string from CQ5 smartimage widget * @return Crop dimension instance * @throws IllegalArgumentException if crop string syntax is invalid */ public static CropDimension fromCropString(String cropString) { if (StringUtils.isEmpty(cropString)) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); } // strip off optional size parameter after "/" String crop = cropString; if (StringUtils.contains(crop, "/")) { crop = StringUtils.substringBefore(crop, "/"); } String[] parts = StringUtils.split(crop, ","); if (parts.length != 4) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); } long x1 = NumberUtils.toLong(parts[0]); long y1 = NumberUtils.toLong(parts[1]); long x2 = NumberUtils.toLong(parts[2]); long y2 = NumberUtils.toLong(parts[3]); long width = x2 - x1; long height = y2 - y1; if (x1 < 0 || y1 < 0 || width <= 0 || height <= 0) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); } return new CropDimension(x1, y1, width, height); }
From source file:io.wcm.wcm.parsys.componentinfo.impl.AllowedComponentsProviderImpl.java
/** * Get allowed components for given resource path * @param resourcePath Resource path inside content page * @return Set of component paths (absolute resource types) *///from w w w . ja v a2s . c o m @Override public Set<String> getAllowedComponents(String resourcePath, ResourceResolver resolver) { Set<String> allowedComponents = new HashSet<>(); Set<String> deniedComponents = new HashSet<>(); PageManager pageManager = resolver.adaptTo(PageManager.class); Page page = pageManager.getContainingPage(resourcePath); if (page == null && StringUtils.contains(resourcePath, "/" + JcrConstants.JCR_CONTENT)) { // if resource does not exist (e.g. inherited parsys) get page from resource path manually page = pageManager.getPage(StringUtils.substringBefore(resourcePath, "/" + JcrConstants.JCR_CONTENT)); } if (page != null) { String pageComponentPath = page.getContentResource().getResourceType(); String relativePath = resourcePath.substring(page.getPath().length() + 1); Iterable<ParsysConfig> parSysConfigs = parsysConfigManager.getParsysConfigs(pageComponentPath, relativePath, resolver); Resource parentResource = null; Resource grandParentResource = null; for (ParsysConfig pathDef : parSysConfigs) { boolean includePathDef = false; if (pathDef.getAllowedParents().size() == 0) { includePathDef = true; } else { Resource checkResource = null; if (pathDef.getParentAncestorLevel() == 1) { if (parentResource == null) { parentResource = resolver.getResource(resourcePath); } checkResource = parentResource; } if (pathDef.getParentAncestorLevel() == 2) { if (grandParentResource == null) { grandParentResource = resolver.getResource(resourcePath + "/.."); } checkResource = grandParentResource; } if (checkResource != null) { String resourceType = ResourceType.makeAbsolute(checkResource.getResourceType(), resolver); includePathDef = pathDef.getAllowedParents().contains(resourceType); } } if (includePathDef) { allowedComponents.addAll(makeAbsolute(pathDef.getAllowedChildren(), resolver)); deniedComponents.addAll(makeAbsolute(pathDef.getDeniedChildren(), resolver)); } } } // filter out denied components allowedComponents.removeAll(deniedComponents); return allowedComponents; }
From source file:com.bmw.spdxeditor.SPDXPreferencesPage.java
@Override protected Control createContents(Composite parent) { IPreferenceStore store = getPreferenceStore(); String fileCreatorValue = store.getString(DEFAULT_FILE_CREATOR); String fileCreatorType = null; if (StringUtils.isEmpty(fileCreatorValue)) { fileCreatorValue = "NOASSERTION"; fileCreatorType = ""; } else {/*from www.jav a 2 s . com*/ fileCreatorType = StringUtils.substringBefore(fileCreatorValue, ":"); fileCreatorValue = StringUtils.substringAfter(fileCreatorValue, ":").trim(); } // Describe layout for this group panel GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; parent.setLayout(gridLayout); Label lbl = new Label(parent, SWT.NONE); lbl.setText("Package creator default"); // Person, Organization, Tool String items[] = { "Person", "Organization", "Tool", "" }; creatorTypes = new Combo(parent, SWT.READ_ONLY); creatorTypes.setItems(items); creatorTypes.setText(fileCreatorType); creatorText = new Text(parent, SWT.BORDER); creatorText.setText(fileCreatorValue); return null; }
From source file:com.handpay.ibenefit.framework.util.PropertyFilter.java
/** * /*from w ww . ja v a2 s .c om*/ * @param defalutObjectName default object name * @param filterName property name * @param value the value of the property */ public PropertyFilter(final String defalutObjectName, final String filterName, final String value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); this.filterName = filterName; matchType = Enum.valueOf(MatchType.class, matchTypeCode); propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); propertyName = StringUtils.substringAfter(filterName, "_"); if (propertyName.indexOf(".") != -1) { String[] array = propertyName.split("\\."); objectName = array[0]; propertyName = array[1]; } else { objectName = defalutObjectName; } propertyValueString = value; try { this.propertyValue = ReflectUtils.convertStringToObject(value, propertyType); //Handle Date type if (propertyTypeCode.equals("D")) { //Set to the begin of the date or end of the date if (matchType == MatchType.GE || matchType == MatchType.GT) { this.propertyValue = DateUtils.getBeginOfTheDate((Date) this.propertyValue); } else if (matchType == MatchType.LE || matchType == MatchType.LT) { this.propertyValue = DateUtils.getEndOfTheDate((Date) this.propertyValue); } } if (matchType == PropertyFilter.MatchType.IC || matchType == PropertyFilter.MatchType.NC) { String[] values = value.split(","); propertyValues = new ArrayList(values.length); for (String v : values) { propertyValues.add(ReflectUtils.convertStringToObject(v, propertyType)); } } } catch (Exception e) { } }
From source file:io.cloudslang.lang.compiler.modeller.transformers.AbstractForTransformer.java
public TransformModellingResult<LoopStatement> transformToLoopStatement(String rawData, boolean isParallelLoop) { List<RuntimeException> errors = new ArrayList<>(); Accumulator dependencyAccumulator = extractFunctionData("${" + rawData + "}"); if (StringUtils.isEmpty(rawData)) { errors.add(new RuntimeException("For statement is empty.")); return new BasicTransformModellingResult<>(null, errors); }//from ww w. j a v a2 s. c o m LoopStatement loopStatement = null; String varName; String collectionExpression; Pattern regexSimpleFor = Pattern.compile(FOR_REGEX); Matcher matcherSimpleFor = regexSimpleFor.matcher(rawData); try { if (matcherSimpleFor.find()) { // case: value in variable_name varName = matcherSimpleFor.group(2); collectionExpression = matcherSimpleFor.group(4); loopStatement = createLoopStatement(varName, collectionExpression, dependencyAccumulator, isParallelLoop); } else { String beforeInKeyword = StringUtils.substringBefore(rawData, FOR_IN_KEYWORD); collectionExpression = StringUtils.substringAfter(rawData, FOR_IN_KEYWORD).trim(); Pattern regexKeyValueFor = Pattern.compile(KEY_VALUE_PAIR_REGEX); Matcher matcherKeyValueFor = regexKeyValueFor.matcher(beforeInKeyword); if (matcherKeyValueFor.find()) { // case: key, value String keyName = matcherKeyValueFor.group(2); String valueName = matcherKeyValueFor.group(6); loopStatement = createMapForLoopStatement(keyName, valueName, collectionExpression, dependencyAccumulator); } else { // case: value in expression_other_than_variable_name varName = beforeInKeyword.trim(); loopStatement = createLoopStatement(varName, collectionExpression, dependencyAccumulator, isParallelLoop); } } } catch (RuntimeException rex) { errors.add(rex); } return new BasicTransformModellingResult<>(loopStatement, errors); }
From source file:com.buildabrand.gsb.util.URLUtils.java
/** * Returns the canonicalized form of a URL, core logic written by Henrik Sjostrand, heavily modified for v2 by Dave Shanley. * * @param queryURL//w w w. j av a 2 s .c o m * @return * @author Henrik Sjostrand, Netvouz, http://www.netvouz.com/, info@netvouz.com & Dave Shanley <dave@buildabrand.com> */ public String canonicalizeURL(String queryURL) { if (StringUtils.isEmpty(queryURL)) { return null; } // Start by stripping off the fragment identifier. queryURL = StringUtils.substringBefore(queryURL, "#"); // Stripping off leading and trailing white spaces. queryURL = StringUtils.trim(queryURL); // Remove any embedded tabs and CR/LF characters which aren't escaped. queryURL = StringUtils.remove(queryURL, '\t'); queryURL = StringUtils.remove(queryURL, '\r'); queryURL = StringUtils.remove(queryURL, '\n'); // Un-escape and re-escpae the URL just in case there are some encoded // characters in the url scheme for example. queryURL = escape(queryURL); URL url; try { url = new URL(queryURL); } catch (MalformedURLException e) { // Try again with "http://" try { url = new URL("http://" + queryURL); } catch (MalformedURLException e2) { logger.error("Malformed url", e); return null; } } if (!(url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("ftp"))) { return null; } // Note: applying HOST_PORT_REGEXP also removes any user and password. Matcher hostMatcher = HOST_PORT_REGEXP.matcher(url.getHost()); if (!hostMatcher.find()) { return null; } String host = hostMatcher.group(1); String canonicalHost = canonicalizeHost(host); if (canonicalHost == null) { return null; } // Now that the host is canonicalized we add the port back if it's not the // default port for that url scheme if (url.getPort() != -1 && ((url.getProtocol().equalsIgnoreCase("http") && url.getPort() != 80) || (url.getProtocol().equalsIgnoreCase("https") && url.getPort() != 443) || (url.getProtocol().equalsIgnoreCase("ftp") && url.getPort() != 21))) { canonicalHost = canonicalHost + ":" + url.getPort(); } String canonicalPath = canonicalizePath(url.getPath()); String canonicalUrl = url.getProtocol() + "://" + canonicalHost + canonicalPath; if (StringUtils.isNotEmpty(url.getQuery()) || queryURL.endsWith("?")) { canonicalUrl += "?" + url.getQuery(); } return canonicalUrl; }
From source file:com.gargoylesoftware.htmlunit.protocol.data.DataUrlDecoder.java
private static String extractMediaType(final String beforeData) { if (beforeData.contains("/")) { if (beforeData.contains(";")) { return StringUtils.substringBefore(beforeData, ";"); }/*from ww w . j a va2 s.c o m*/ return beforeData; } return DEFAULT_MEDIA_TYPE; }
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.GroupedStackedBarRendererCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { this.seriesColors = new LinkedHashMap<String, Paint>(); this.map = null; Set<String> groups = new LinkedHashSet<String>(); CategoryDataset dataset = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset.getRowCount(); i++) { String rowKey = (String) dataset.getRowKey(i); String group = StringUtils.substringBefore(rowKey, GROUP_SERIES_KEY); String series = StringUtils.substringAfter(rowKey, GROUP_SERIES_KEY); if (map == null) { map = new KeyToGroupMap(group); }/*w ww . ja va2 s .c o m*/ map.mapKeyToGroup(rowKey, group); groups.add(group); if (!seriesColors.containsKey(series)) { Paint paint = chart.getCategoryPlot().getDrawingSupplier().getNextPaint(); seriesColors.put(series, paint); } } DefaultCategoryDataset newDataset = new DefaultCategoryDataset(); for (Object column : dataset.getColumnKeys()) { for (String group : groups) { for (String series : seriesColors.keySet()) { try { Number value = dataset.getValue(group + GROUP_SERIES_KEY + series, (Comparable<?>) column); newDataset.addValue(value, group + GROUP_SERIES_KEY + series, (Comparable<?>) column); } catch (UnknownKeyException e) { newDataset.addValue(0, group + GROUP_SERIES_KEY + series, (Comparable<?>) column); } } } } dataset = newDataset; GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); renderer.setSeriesToGroupMap(map); StackedBarRenderer categoryRenderer = (StackedBarRenderer) chart.getCategoryPlot().getRenderer(); renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible()); renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont()); renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint()); renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator()); renderer.setShadowVisible(categoryRenderer.getShadowsVisible()); renderer.setItemMargin(0.10); renderer.setDrawBarOutline(false); for (int i = 0; i < dataset.getRowCount(); i++) { String rowKey = (String) dataset.getRowKey(i); String score = StringUtils.substringAfter(rowKey, GROUP_SERIES_KEY); renderer.setSeriesPaint(i, seriesColors.get(score)); } CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); SubCategoryAxis newDomainAxis = new SubCategoryAxis(domainAxis.getLabel()); newDomainAxis.setLabelFont(domainAxis.getLabelFont()); newDomainAxis.setTickLabelFont(domainAxis.getTickLabelFont()); newDomainAxis.setLabelPaint(domainAxis.getLabelPaint()); newDomainAxis.setTickLabelPaint(domainAxis.getTickLabelPaint()); newDomainAxis.setAxisLinePaint(domainAxis.getAxisLinePaint()); newDomainAxis.setTickMarkPaint(domainAxis.getTickMarkPaint()); newDomainAxis.setTickLabelsVisible(domainAxis.isTickLabelsVisible()); newDomainAxis.setTickMarksVisible(domainAxis.isTickMarksVisible()); newDomainAxis.setCategoryMargin(0.05); for (String group : groups) { newDomainAxis.addSubCategory(group); } CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(newDomainAxis); plot.setRenderer(renderer); LegendItemCollection legendItems = new LegendItemCollection(); for (String item : seriesColors.keySet()) { legendItems.add(new LegendItem(item, seriesColors.get(item))); } plot.setFixedLegendItems(legendItems); chart.getCategoryPlot().setDataset(dataset); }
From source file:io.wcm.testing.mock.sling.servlet.MockSlingHttpServletResponse.java
@Override public void setContentType(final String type) { this.contentType = type; if (StringUtils.contains(this.contentType, CHARSET_SEPARATOR)) { this.characterEncoding = StringUtils.substringAfter(this.contentType, CHARSET_SEPARATOR); this.contentType = StringUtils.substringBefore(this.contentType, CHARSET_SEPARATOR); }/* ww w . j av a2s . c o m*/ }