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:org.structr.websocket.command.WrappedRestCommand.java
@Override public void processMessage(WebSocketMessage webSocketData) throws FrameworkException { final Map<String, Object> nodeData = webSocketData.getNodeData(); final String method = (String) nodeData.get("method"); if (method == null || !(method.equals("POST") || method.equals("PUT"))) { logger.log(Level.WARNING, "Method not supported: {0}", method); getWebSocket().send(//from w ww.j a v a2 s .c o m MessageBuilder.wrappedRest().code(422).message("Method not supported: " + method).build(), true); return; } ResourceProvider resourceProvider; try { resourceProvider = UiResourceProvider.class.newInstance(); } catch (Throwable t) { logger.log(Level.SEVERE, "Couldn't establish a resource provider", t); getWebSocket().send(MessageBuilder.wrappedRest().code(422) .message("Couldn't establish a resource provider").build(), true); return; } final Map<Pattern, Class<? extends Resource>> resourceMap = new LinkedHashMap<>(); resourceMap.putAll(resourceProvider.getResources()); final StructrWebSocket socket = this.getWebSocket(); final String url = (String) nodeData.get("url"); // mimic HTTP request final HttpServletRequest wrappedRequest = new HttpServletRequestWrapper(socket.getRequest()) { @Override public Enumeration<String> getParameterNames() { return new IteratorEnumeration(getParameterMap().keySet().iterator()); } @Override public String getParameter(String key) { String[] p = getParameterMap().get(key); return p != null ? p[0] : null; } @Override public Map<String, String[]> getParameterMap() { String[] parts = StringUtils.split(getQueryString(), "&"); Map<String, String[]> parameterMap = new HashMap(); for (String p : parts) { String[] kv = StringUtils.split(p, "="); if (kv.length > 1) { parameterMap.put(kv[0], new String[] { kv[1] }); } } return parameterMap; } @Override public String getQueryString() { return StringUtils.substringAfter(url, "?"); } @Override public String getPathInfo() { return StringUtils.substringBefore(url, "?"); } @Override public StringBuffer getRequestURL() { return new StringBuffer(url); } }; Resource resource; final StaticValue fakePropertyView = new StaticValue(PropertyView.Public); try { resource = ResourceHelper .applyViewTransformation(wrappedRequest, socket.getSecurityContext(), ResourceHelper.optimizeNestedResourceChain(ResourceHelper.parsePath( socket.getSecurityContext(), wrappedRequest, resourceMap, fakePropertyView)), fakePropertyView); } catch (IllegalPathException | NotFoundException e) { logger.log(Level.WARNING, "Illegal path for REST query"); getWebSocket().send( MessageBuilder.wrappedRest().code(422).message("Illegal path for REST query").build(), true); return; } final String data = (String) nodeData.get("data"); final Gson gson = new GsonBuilder().create(); final Map<String, Object> jsonData = gson.fromJson(data, Map.class); RestMethodResult result = null; switch (method) { case "PUT": // we want to update data result = resource.doPut(jsonData); break; case "POST": // we either want to create data or call a method on an object result = resource.doPost(jsonData); break; } // right now we do not send messages if (result != null) { // getWebSocket().send(MessageBuilder.wrappedRest().code(result.getResponseCode()).message(result.jsonMessage()).build(), true); } }
From source file:org.talend.daikon.exception.json.JsonErrorCode.java
/** * @return the error code group./*ww w . jav a2 s . c om*/ */ @Override public String getGroup() { return StringUtils.substringBefore(StringUtils.substringAfter(code, "_"), "_"); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:org.trimou.servlet.locator.ServletContextTemplateLocator.java
private Set<String> listResources(String path, ServletContext ctx) { Set<String> resources = new HashSet<String>(); Set<String> resourcePaths = ctx.getResourcePaths(path); if (resourcePaths != null) { for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(Strings.SLASH)) { // Subdirectory String subdirectory = getRootPath() + StringUtils.substringAfter(resourcePath, getRootPath()); resources.addAll(listResources(subdirectory, ctx)); } else { if (getSuffix() != null && !resourcePath.endsWith(getSuffix())) { continue; }/* w w w . j ava 2 s. c om*/ resources.add(resourcePath); } } } return resources; }
From source file:org.trimou.servlet.locator.ServletContextTemplateLocator.java
@Override protected String constructVirtualPath(String source) { String[] parts = StringUtils.split(StringUtils.substringAfter(source, getRootPath()), Strings.SLASH); StringBuilder name = new StringBuilder(); for (int i = 0; i < parts.length; i++) { name.append(parts[i]);/*from w w w . j a va 2 s.c o m*/ if (i + 1 < parts.length) { name.append(getVirtualPathSeparator()); } } return name.toString(); }
From source file:org.wise.portal.domain.project.impl.Projectcode.java
/** * @return the periodname */ public String getRunPeriod() { return StringUtils.substringAfter(projectcode, SEPARATOR); }
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
/** * Extracts information from the "other"-fields of the response. This field may contain information about plural * forms or irregular verb forms.// w w w . java2s . c o m * <p> * Examples: * <ul> * <li>Plural: Mtter</li> * <li>fl.: mdre</li> * <li>syn.: tschs</li> * <li>Dialekt (sddeutsch/sterreichisch)</li> * <li>presens: kommer, preteritum: kom, partisipp perfekt: kommet</li> * <li>bestemt form: lille, intetkjnn: lite, flertall: sm</li> * <li>komparativ: frre, superlativ: frrest</li> * <li>Komparativ: weniger, Superlativ: am wenigsten</li> * </ul> * * @param otherInformation * The source string * @param builder * The target builder to write into. */ protected void extractOtherInformation(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { // Try to extract plural forms if (StringUtils.startsWith(otherInformation, "Plural:") || StringUtils.startsWith(otherInformation, "fl.:")) { String pluralForm = StringUtils.substringAfter(otherInformation, ":"); builder.setAdditionalForm(GrammaticalNumber.PLURAL, StringUtils.strip(pluralForm)); } // Try to extract verb forms else if (StringUtils.startsWith(otherInformation, "presens")) { extractVerbForms(otherInformation, builder); } // Try to extract adjective comparisons else if (StringUtils.startsWithIgnoreCase(otherInformation, "komparativ")) { extractComparisonForms(otherInformation, builder); } // Try to extract adjective forms else if (StringUtils.startsWithIgnoreCase(otherInformation, "bestemt form")) { extractAdjectiveForms(otherInformation, builder); } // Write to description string otherwise... else if (StringUtils.isNotEmpty(otherInformation)) { builder.setDescription(StringUtils.strip(otherInformation)); } }
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
private void extractAdjectiveForms(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { for (String s : StringUtils.split(otherInformation, ',')) { String flectedForm = StringUtils.strip(StringUtils.substringAfter(s, ":")); if (StringUtils.containsIgnoreCase(s, "bestemt form:")) { builder.setAdditionalForm(GrammaticalCase.DEFINITE_FORM, flectedForm); }//from w w w.j a v a 2 s . c om if (StringUtils.containsIgnoreCase(s, "intetkjnn:")) { builder.setAdditionalForm(GrammaticalGender.NEUTER, flectedForm); } if (StringUtils.containsIgnoreCase(s, "flertall:")) { builder.setAdditionalForm(GrammaticalNumber.PLURAL, flectedForm); } } }
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
private void extractComparisonForms(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { for (String s : StringUtils.split(otherInformation, ',')) { String flectedForm = StringUtils.strip(StringUtils.substringAfter(s, ":")); if (StringUtils.containsIgnoreCase(s, "komparativ:")) { builder.setAdditionalForm(GrammaticalComparison.COMPARATIVE, flectedForm); }//from w ww. j a v a2 s . c o m if (StringUtils.containsIgnoreCase(s, "superlativ:")) { builder.setAdditionalForm(GrammaticalComparison.SUPERLATIVE, flectedForm); } } }
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
private void extractVerbForms(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { for (String s : StringUtils.split(otherInformation, ',')) { String flectedForm = StringUtils.strip(StringUtils.substringAfter(s, ":")); if (StringUtils.contains(s, "presens:")) { builder.setAdditionalForm(GrammaticalTense.PRESENT_TENSE, flectedForm); }/* w w w .j av a 2s . com*/ if (StringUtils.contains(s, "preteritum:")) { builder.setAdditionalForm(GrammaticalTense.PAST_TENSE, flectedForm); } if (StringUtils.contains(s, "partisipp perfekt:")) { builder.setAdditionalForm(GrammaticalTense.PERFECT_PARTICIPLE, flectedForm); } } }
From source file:org.xwiki.appwithinminutes.test.po.EntryEditPage.java
/** * @return the list of form field names available on this page *//*from www .ja v a 2s . c om*/ public List<String> getFieldNames() { List<String> fieldNames = new ArrayList<String>(); for (WebElement field : getForm().findElements(By.xpath("//*[contains(@name, '_0_')]"))) { fieldNames.add(StringUtils.substringAfter(field.getAttribute("name"), "_0_")); } return fieldNames; }