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.thruzero.common.core.infonode.builder.TokenStreamInfoNodeBuilder.java
protected InfoNodeElement initLeafNode(final String tokenStream, final String separator, final InfoNodeElement targetNode) { // TODO-p1(george) Rewrite this using RegEx String attributeStream = StringUtils.substringBetween(tokenStream, "[@", "]"); String elementName;//from w ww . j a v a2 s . c o m String elementValue; // handle the attributes if (StringUtils.isEmpty(attributeStream)) { elementName = StringUtils.trimToNull(StringUtils.substringBefore(tokenStream, "=")); elementValue = StringUtils.trimToNull(StringUtils.substringAfter(tokenStream, "=")); } else { StringTokenizer st1 = new StringTokenizer(attributeStream, separator); while (st1.hasMoreTokens()) { String attributeSpec = st1.nextToken(); StringTokenizer st2 = new StringTokenizer(attributeSpec, "="); if (!st2.hasMoreTokens()) { throw new TokenStreamException( "Malformed Token Stream (missing attribute name and value): " + tokenStream); } String attributeName = StringUtils.removeStart(st2.nextToken().trim(), "@"); String attributeValue = null; if (st2.hasMoreTokens()) { attributeValue = trimQuotes(st2.nextToken().trim()); } if (StringUtils.isEmpty(attributeValue)) { throw new TokenStreamException( "Malformed Token Stream (missing attribute value): " + tokenStream); } targetNode.setAttribute(attributeName, attributeValue); } elementName = StringUtils.trimToNull(StringUtils.substringBefore(tokenStream, "[")); elementValue = StringUtils.trimToNull(StringUtils.substringAfter(tokenStream, "]")); } // set the element name if (elementName == null) { throw new TokenStreamException("Malformed Token Stream (missing element name): " + tokenStream); } targetNode.setName(elementName); // set the element value if (elementValue != null) { elementValue = StringUtils.removeStart(elementValue, "="); targetNode.setText(elementValue); } return targetNode; }
From source file:cc.recommenders.names.VmMethodName.java
@Override public ITypeName getReturnType() { String returnType = StringUtils.substringAfterLast(identifier, ")"); // strip off throws type from method return returnType = StringUtils.substringBefore(returnType, "|"); if (!returnType.endsWith(";")) { // be sure that if it does not end with a ';' is MUST be a primitive // or an array of primitives: final ITypeName res = VmTypeName.get(returnType); ensureIsTrue(res.isPrimitiveType() || res.isArrayType() && res.getArrayBaseType().isPrimitiveType()); return res; } else {/*w ww .jav a 2 s. com*/ returnType = StringUtils.substring(returnType, 0, -1); return VmTypeName.get(returnType); } }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentMapEditorAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentMapEditor annotation = field.getAnnotation(Annotations.ContentMapEditor.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); MapEditor mapEditorComboBox = (MapEditor) typeAndContent[0]; String editorContent = (String) typeAndContent[1]; String keyPart = StringUtils.substringBefore(editorContent, mapEditorComboBox.getDelimiter()).trim(); String valuePart = StringUtils.substringAfter(editorContent, mapEditorComboBox.getDelimiter()).trim(); boolean keyMatch = Pattern.matches(mapEditorComboBox.getKeyPattern(), keyPart); boolean valueMatch = Pattern.matches(mapEditorComboBox.getValuePattern(), valuePart); String explain;//from www. j a va 2 s .com if (!keyMatch || !valueMatch) { explain = (!keyMatch) ? annotation.explainKey() : annotation.explainValue(); changeNodeTitleLabelVisual(mapEditorComboBox, explain); } else if ((keyPart.isEmpty() && !valuePart.isEmpty()) || (!keyPart.isEmpty() && valuePart.isEmpty())) { explain = annotation.explainEmpty(); changeNodeTitleLabelVisual(mapEditorComboBox, explain); } else { changeNodeTitleLabelVisual(mapEditorComboBox, ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:com.tascape.qa.th.SystemConfiguration.java
public String getJobName() { String value = this.getProperty("qa.th." + SYSENV_JOB_NAME); if (value == null) { value = System.getenv().get(SYSENV_JOB_NAME); }/*from w w w . j a va2 s.c o m*/ if (value == null) { value = System.getProperty("user.name") + "@" + StringUtils.substringBefore(this.getHostName(), "."); } else { value = value.split("/")[0]; } return value.trim(); }
From source file:com.threewks.thundr.http.service.ning.HttpServiceNing.java
private void addBody(HttpRequestNing request, BoundRequestBuilder builder) { Object body = request.getBody(); if (isMultipart(request)) { for (Map.Entry<String, Object> parameter : request.getParameters().entrySet()) { Object value = parameter.getValue(); builder.addBodyPart(new StringPart(parameter.getKey(), getValueAs(value, String.class), "UTF-8")); }// w w w. j a v a2s . com for (FileParameter fileParam : request.getFileParameters()) { Object partBody = fileParam.getBody(); byte[] data = getValueAs(partBody, byte[].class); String contentType = StringUtils.substringBefore(fileParam.getContentType(), ";"); String characterEncoding = StringUtils.substringBetween(fileParam.getContentType(), "charset=\"", "\""); builder.addBodyPart(new ByteArrayPart(fileParam.getName(), fileParam.getName(), data, contentType, characterEncoding)); } builder.setHeader(Header.ContentType, ContentType.MultipartFormData.value()); } else if (body != null) { builder.setBody(convertOutgoing(body)); } }
From source file:cc.recommenders.names.CoReMethodName.java
@Override public ICoReTypeName getReturnType() { String returnType = StringUtils.substringAfterLast(identifier, ")"); // strip off throws type from method return returnType = StringUtils.substringBefore(returnType, "|"); if (!returnType.endsWith(";")) { // be sure that if it does not end with a ';' is MUST be a primitive // or an array of primitives: final ICoReTypeName res = CoReTypeName.get(returnType); ensureIsTrue(res.isPrimitiveType() || res.isArrayType() && res.getArrayBaseType().isPrimitiveType()); return res; } else {//from w ww .jav a2s . c o m returnType = StringUtils.substring(returnType, 0, -1); return CoReTypeName.get(returnType); } }
From source file:io.lavagna.web.security.PathConfiguration.java
private static String findSubpath(HttpServletRequest req, String firstPath) { return StringUtils.substringBefore(StringUtils.substring(req.getServletPath(), firstPath.length() + 1), "/"); }
From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java
public static String getClassName(String code) { String className = StringUtils.substringBefore(code, "{"); if (StringUtils.isBlank(className)) { return className; }//from www.j a v a 2 s . c om if (StringUtils.contains(code, " class ")) { className = StringUtils.substringAfter(className, " class "); if (StringUtils.contains(className, " extends ")) { className = StringUtils.substringBefore(className, " extends ").trim(); } else if (StringUtils.contains(className, " implements ")) { className = StringUtils.trim(StringUtils.substringBefore(className, " implements ")); } else { className = StringUtils.trim(className); } } else if (StringUtils.contains(code, " interface ")) { className = StringUtils.substringAfter(className, " interface "); if (StringUtils.contains(className, " extends ")) { className = StringUtils.substringBefore(className, " extends ").trim(); } else { className = StringUtils.trim(className); } } else if (StringUtils.contains(code, " enum ")) { className = StringUtils.trim(StringUtils.substringAfter(className, " enum ")); } else { return StringUtils.EMPTY; } return className; }
From source file:de.blizzy.documentr.web.system.SystemController.java
private SortedMap<String, SortedMap<String, String>> getMacroSettingsFromRequest(WebRequest webRequest) { Map<String, String[]> params = webRequest.getParameterMap(); SortedMap<String, SortedMap<String, String>> allMacroSettings = Maps.newTreeMap(); for (Map.Entry<String, String[]> entry : params.entrySet()) { String key = entry.getKey(); if (key.startsWith(MACRO_KEY_PREFIX)) { String[] values = entry.getValue(); if (values.length == 0) { values = new String[] { StringUtils.EMPTY }; }/*from w ww .j a v a2s .co m*/ key = key.substring(MACRO_KEY_PREFIX.length()); String macroName = StringUtils.substringBefore(key, "."); //$NON-NLS-1$ key = StringUtils.substringAfter(key, "."); //$NON-NLS-1$ SortedMap<String, String> macroSettings = allMacroSettings.get(macroName); if (macroSettings == null) { macroSettings = Maps.newTreeMap(); allMacroSettings.put(macroName, macroSettings); } macroSettings.put(key, values[0]); } } return allMacroSettings; }
From source file:com.google.dart.java2dart.util.JavaUtils.java
public static String getQualifiedName(ITypeBinding binding) { String name = binding.getQualifiedName(); if (name.contains("<")) { name = StringUtils.substringBefore(name, "<"); }//from w w w . j a v a 2s . co m return name; }