List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:com.adobe.acs.commons.mcp.form.RadioComponent.java
@Override public Resource buildComponentResource() { AbstractResourceImpl component = (AbstractResourceImpl) super.buildComponentResource(); AbstractResourceImpl options = new AbstractResourceImpl("items", null, null, new ResourceMetadata()); component.addChild(options);// w ww . j a v a 2s . c o m String defaultValue = getOption("default").orElse(null); getOptions().forEach((value, name) -> { final ResourceMetadata meta = new ResourceMetadata(); final String nodeName = JcrUtil.escapeIllegalJcrChars(value); if (value.equals(defaultValue)) { meta.put("checked", true); } meta.put("name", getName()); meta.put("value", value); if (name.contains("::")) { String description = StringUtils.substringAfter(name, DESCRIPTION_DELIMITER); meta.put("title", description); name = StringUtils.substringBefore(name, DESCRIPTION_DELIMITER); } meta.put("text", name); AbstractResourceImpl option = new AbstractResourceImpl("option_" + nodeName, "granite/ui/components/foundation/form/radio", "granite/ui/components/foundation/form/field", meta); options.addChild(option); }); return component; }
From source file:com.sunlights.common.utils.PropertyFilter.java
/** * @param filterName/*from w ww. j a va 2s . c o m*/ * @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:com.norconex.importer.handler.tagger.impl.ForceSingleValueTagger.java
@Override public void tagApplicableDocument(String reference, InputStream document, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException { for (String name : singleFields.keySet()) { List<String> values = metadata.getStrings(name); String action = singleFields.get(name); if (values != null && !values.isEmpty() && StringUtils.isNotBlank(action)) { String singleValue = null; if ("keepFirst".equalsIgnoreCase(action)) { singleValue = values.get(0); } else if ("keepLast".equalsIgnoreCase(action)) { singleValue = values.get(values.size() - 1); } else if (StringUtils.startsWithIgnoreCase(action, "mergeWith")) { String sep = StringUtils.substringAfter(action, ":"); singleValue = StringUtils.join(values, sep); } else { singleValue = StringUtils.join(values, ","); }/*from ww w . ja va 2 s .c o m*/ metadata.setString(name, singleValue); } } }
From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetObjectName.java
private static String resolveObjectName(String objectName, List<?> args) { String option = args.size() > 1 ? (String) args.get(1) : null; Options opt;/* w w w . j a v a 2 s . co m*/ try { opt = StringUtils.isEmpty(option) ? Options.DEFAULT : Options.valueOf(option.toUpperCase()); } catch (IllegalArgumentException exc) { opt = Options.DEFAULT; } switch (opt) { case FULL: break; case BEFORE: String sSymbol = args.size() > 2 ? (String) args.get(2) : null; if (StringUtils.isNotEmpty(sSymbol)) { objectName = StringUtils.substringBefore(objectName, sSymbol); } break; case AFTER: sSymbol = args.size() > 2 ? (String) args.get(2) : null; if (StringUtils.isNotEmpty(sSymbol)) { objectName = StringUtils.substringAfter(objectName, sSymbol); } break; case REPLACE: sSymbol = args.size() > 2 ? (String) args.get(2) : null; if (StringUtils.isNotEmpty(sSymbol)) { String rSymbol = args.size() > 3 ? (String) args.get(3) : null; objectName = StringUtils.replaceChars(objectName, sSymbol, rSymbol == null ? "" : rSymbol); } break; case SECTION: String idxStr = args.size() > 2 ? (String) args.get(2) : null; int idx; try { idx = Integer.parseInt(idxStr); } catch (Exception exc) { idx = -1; } if (idx >= 0) { sSymbol = args.size() > 3 ? (String) args.get(3) : null; String[] onTokens = StringUtils.split(objectName, StringUtils.isEmpty(sSymbol) ? OBJ_NAME_TOKEN_DELIMITERS : sSymbol); objectName = idx < ArrayUtils.getLength(onTokens) ? onTokens[idx] : objectName; } break; case DEFAULT: default: idx = StringUtils.indexOfAny(objectName, OBJ_NAME_TOKEN_DELIMITERS); if (idx > 0) { objectName = StringUtils.substring(objectName, 0, idx); } break; } return objectName; }
From source file:com.sketchy.server.action.ManageNetworkSettings.java
private NetworkInfo readNetworkInfo() throws Exception { NetworkInfo networkInfo = new NetworkInfo(); List<String> lines = FileUtils.readLines(WPA_SUPPLICANT_FILE); for (String line : lines) { String ssid = StringUtils.substringAfter(line, "ssid="); String psk = StringUtils.substringAfter(line, "psk="); if (StringUtils.isNotBlank(ssid)) { networkInfo.ssid = StringUtils.substringBetween(ssid, "\"", "\""); }//from w ww . j a va2 s. co m if (StringUtils.isNotBlank(psk)) { networkInfo.password = StringUtils.substringBetween(psk, "\"", "\""); } } return networkInfo; }
From source file:com.neatresults.mgnltweaks.ui.contentapp.browser.QueryableJcrContainer.java
@Override protected String getQueryWhereClause() { String[] segments = StringUtils.split(path, "/"); if ("dialogs".equals(segments[2])) { String id = segments[1] + ":" + StringUtils.substringAfter(path, "/dialogs/"); return " where contains(t.dialog, '" + id + "') or contains(t.dialogName, '" + id + "')" + buildExtends(path);/*from www .ja v a 2 s . c o m*/ } else if ("templates".equals(segments[2])) { String id = segments[1] + ":" + StringUtils.substringAfter(path, "/templates/"); this.setWorkspace(RepositoryConstants.WEBSITE); return " where contains(t.[mgnl:template], '" + id + "')"; } else { return " where " + buildExtends(path).substring(3); } }
From source file:com.xpn.xwiki.user.impl.xwiki.AppServerTrustedKerberosAuthServiceImpl.java
/** * Helper method to extract the username part out of a Kerberos principal. * //from w w w . j av a 2 s . com * @param principal the principal to extract the username from * @return the extracted username */ private String extractUsernameFromPrincipal(final String principal) { String username = principal; // Clears the Kerberos principal, by removing the domain part, to retain only the user name of the // authenticated remote user. if (username.contains(ANTI_SLASH)) { // old domain form username = StringUtils.substringAfter(username, ANTI_SLASH); } if (username.contains(AT_SIGN)) { // new domain form username = StringUtils.substringBeforeLast(username, AT_SIGN); } return username; }
From source file:hk.mcc.utils.applog2es.Main.java
private static void post2ES(List<AppLog> appLogs) { try {// ww w. j a v a 2s .co m // on startup DateTimeFormatter sdf = ISODateTimeFormat.dateTime(); Settings settings = Settings.settingsBuilder().put("cluster.name", "my-application").build(); //Add transport addresses and do something with the client... Client client = TransportClient.builder().settings(settings).build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); XContentBuilder mapping = jsonBuilder().startObject().startObject("applog").startObject("properties") .startObject("Url").field("type", "string").field("index", "not_analyzed").endObject() .startObject("Event").field("type", "string").field("index", "not_analyzed").endObject() .startObject("ClassName").field("type", "string").field("index", "not_analyzed").endObject() .startObject("UserId").field("type", "string").field("index", "not_analyzed").endObject() .startObject("Application").field("type", "string").field("index", "not_analyzed").endObject() .startObject("ecid").field("type", "string").field("index", "not_analyzed").endObject() .endObject().endObject().endObject(); PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping("applog") .setType("applog").setSource(mapping).execute().actionGet(); BulkRequestBuilder bulkRequest = client.prepareBulk(); for (AppLog appLog : appLogs) { // either use client#prepare, or use Requests# to directly build index/delete requests if (appLog != null) { if (StringUtils.contains(appLog.getMessage(), "[CIMS_INFO] Filter Processing time")) { String[] split = StringUtils.split(appLog.getMessage(), ","); int elapsedTime = 0; String url = ""; String event = ""; for (String token : split) { if (StringUtils.contains(token, "elapsedTime")) { elapsedTime = Integer.parseInt(StringUtils.substringAfter(token, "=")); } else if (StringUtils.contains(token, "with URL")) { url = StringUtils.substringAfter(token, "="); } else if (StringUtils.contains(token, "event")) { event = StringUtils.substringAfter(token, "="); } } bulkRequest.add(client.prepareIndex("applog", "applog").setSource(jsonBuilder() .startObject().field("className", appLog.getClassName()) .field("logTime", appLog.getLogTime()).field("application", appLog.getApplication()) .field("code", appLog.getCode()).field("message", appLog.getMessage()) .field("ecid", appLog.getEcid()).field("application", appLog.getApplication()) .field("level", appLog.getLevel()).field("server", appLog.getServer()) .field("tid", appLog.getTid()).field("userId", appLog.getUserId()) .field("urls", url).field("elapsedTime", elapsedTime).field("events", event) .endObject())); } } } BulkResponse bulkResponse = bulkRequest.get(); if (bulkResponse.hasFailures()) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, bulkResponse.buildFailureMessage()); // process failures by iterating through each bulk response item } // on shutdown client.close(); } catch (UnknownHostException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ambroafb.general.mapeditor.MapEditor.java
public MapEditor() { this.setEditable(true); itemsMap = new HashMap<>(); delimiter = " : "; // default value of delimiter keyPattern = ""; // (?<![\\d-])\\d+ valuePattern = ""; // [0-9]{1,13}(\\.[0-9]*)? keySpecChars = ""; valueSpecChars = ""; this.setCellFactory((ListView<MapEditorElement> param) -> new CustomCell()); removeElement = (MapEditorElement elem) -> { if (itemsMap.containsKey(elem.getKey())) { itemsMap.remove(elem.getKey()); if (getValue() != null && getValue().compare(elem) == 0) { getEditor().setText(delimiter); }/*from w w w. j ava2 s . c o m*/ getItems().remove(elem); } }; editElement = (MapEditorElement elem) -> { getSelectionModel().select(-1); getEditor().setText(elem.getKey() + delimiter + elem.getValue()); itemsMap.remove(elem.getKey()); getItems().remove(elem); }; // Never hide comboBox items listView: this.setSkin(new ComboBoxListViewSkin(this) { @Override protected boolean isHideOnClickEnabled() { return false; } }); // Control textField input. TextField editor = getEditor(); editor.setText(delimiter); editor.textProperty() .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> { if (newValue == null || newValue.isEmpty() || newValue.equals(delimiter)) { editor.setText(delimiter); } else if (!newValue.contains(delimiter)) { editor.setText(oldValue); } else { String keyInput = StringUtils.substringBefore(newValue, delimiter).trim(); String valueInput = StringUtils.substringAfter(newValue, delimiter).trim(); if (!keyInput.isEmpty() && !Pattern.matches(keyPattern, keyInput)) { keyInput = StringUtils.substringBefore(oldValue, delimiter).trim(); } if (!valueInput.isEmpty() && !Pattern.matches(valuePattern, valueInput)) { valueInput = StringUtils.substringAfter(oldValue, delimiter).trim(); } editor.setText(keyInput + delimiter + valueInput); } }); this.setConverter(new StringConverter<MapEditorElement>() { @Override public String toString(MapEditorElement object) { if (object == null) { return delimiter; } return object.getKey() + delimiter + object.getValue(); } @Override public MapEditorElement fromString(String input) { MapEditorElement result = null; if (input != null && input.contains(delimiter)) { result = getNewInstance(); if (result == null) return null; String keyInput = StringUtils.substringBefore(input, delimiter).trim(); String valueInput = StringUtils.substringAfter(input, delimiter).trim(); if (!keyInput.isEmpty()) { result.setKey(keyInput); } if (!valueInput.isEmpty()) { result.setValue(valueInput); } boolean keyOutOfSpec = keySpecChars.isEmpty() || !StringUtils.containsOnly(result.getKey(), keySpecChars); boolean valueOutOfSpec = valueSpecChars.isEmpty() || !StringUtils.containsOnly(result.getValue(), valueSpecChars); if (!keyInput.isEmpty() && !valueInput.isEmpty() && !itemsMap.containsKey(keyInput) && (keyOutOfSpec && valueOutOfSpec)) { itemsMap.put(keyInput, result); getItems().add(result); return null; } } return result; } }); // Control caret position in textField. editor.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> { int caretOldPos = editor.getCaretPosition(); int delimiterIndex = editor.getText().indexOf(delimiter); if (event.getCode().equals(KeyCode.RIGHT)) { if (caretOldPos + 1 > delimiterIndex && caretOldPos + 1 <= delimiterIndex + delimiter.length()) { editor.positionCaret(delimiterIndex + delimiter.length()); event.consume(); } } else if (event.getCode().equals(KeyCode.LEFT)) { if (caretOldPos - 1 >= delimiterIndex && caretOldPos - 1 < delimiterIndex + delimiter.length()) { editor.positionCaret(delimiterIndex); event.consume(); } } }); }
From source file:cgeo.geocaching.connector.ox.OXConnector.java
@Override @Nullable//from www. j av a2s . c o m public String getGeocodeFromUrl(@NonNull final String url) { final String geocode = StringUtils.substringAfter(url, "http://www.opencaching.com/de/#!geocache/"); if (canHandle(geocode)) { return geocode; } return super.getGeocodeFromUrl(url); }