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.erudika.para.rest.Signer.java
/** * Validates the signature of the request. * @param incoming the incoming HTTP request containing a signature * @param secretKey the app's secret key * @return true if the signature is valid *///from w ww . j a va 2 s.c om public boolean isValidSignature(HttpServletRequest incoming, String secretKey) { if (incoming == null || StringUtils.isBlank(secretKey)) { return false; } String auth = incoming.getHeader(HttpHeaders.AUTHORIZATION); String givenSig = StringUtils.substringAfter(auth, "Signature="); String sigHeaders = StringUtils.substringBetween(auth, "SignedHeaders=", ","); String credential = StringUtils.substringBetween(auth, "Credential=", ","); String accessKey = StringUtils.substringBefore(credential, "/"); if (StringUtils.isBlank(auth)) { givenSig = incoming.getParameter("X-Amz-Signature"); sigHeaders = incoming.getParameter("X-Amz-SignedHeaders"); credential = incoming.getParameter("X-Amz-Credential"); accessKey = StringUtils.substringBefore(credential, "/"); } Request<?> awsReq = buildAWSRequest(incoming, new HashSet<String>(Arrays.asList(sigHeaders.split(";")))); sign(awsReq, accessKey, secretKey); String auth2 = awsReq.getHeaders().get(HttpHeaders.AUTHORIZATION); String recreatedSig = StringUtils.substringAfter(auth2, "Signature="); return StringUtils.equals(givenSig, recreatedSig); }
From source file:kenh.xscript.Environment.java
/** * Load element packages from system properties. * If system property has name starts with <code>kenh.xscript.element.packages</code>, * it will be loaded by xScript./* w w w . j ava 2s. c om*/ */ private void loadElementPackages_SystemProperties() { Properties p = System.getProperties(); Set keys = p.keySet(); for (Object key_ : keys) { if (key_ instanceof String) { String key = (String) key_; if (StringUtils.startsWith(key, ELEMENTS_PATH_PREFIX + ".")) { String name = StringUtils.substringAfter(key, ELEMENTS_PATH_PREFIX + "."); String funcPackage = p.getProperty(key); setElementPackage(name, funcPackage); } } } }
From source file:com.cognifide.qa.bb.config.YamlConfig.java
private Map<? extends String, ? extends Map<String, String>> getContextsFromYaml(Path path) { TypeReference<Map<String, Map<String, String>>> typeRef = new TypeReference<Map<String, Map<String, String>>>() { };/*from ww w .j a v a 2 s . co m*/ return YamlReader.read(ADDITIONAL_CONTEXTS_FOLDER + StringUtils.substringAfter(path.toString(), ADDITIONAL_CONTEXTS_FOLDER_NAME), typeRef); }
From source file:me.ineson.demo.service.rest.SolarBodyRestClient.java
public FileResponse getImage(String baseUrl, Long id) { Assert.notNull(baseUrl, "baseUrl was NULL or empty"); Assert.notNull(id, "id was NULL"); log.debug("Calling {} to get image for solar body id {}", baseUrl, id); String url = baseUrl + "/" + ENDPOINT_PATH + "/" + id.toString() + "/image"; log.debug("Calling url {}", url); WebTarget target = CLIENT.target(url); Response response = target.request().get(); FileResponse result = new FileResponse(); result.setStatus(response.getStatus()); result.setMediaType(response.getMediaType()); result.setContentLength(response.getLength()); if (response.getStatus() == Status.OK.getStatusCode()) { InputStream input = (InputStream) response.getEntity(); try {//from www . j a v a 2s .c o m result.setContent(IOUtils.toByteArray(input)); } catch (IOException e) { throw new IllegalStateException("Error with file data for solar body id " + id + " for url " + url, e); } String contentAttachment = response.getHeaderString("content-attachment"); Assert.hasText(contentAttachment, "context-attachment was empty"); int index = contentAttachment.indexOf("filename="); Assert.isTrue((index <= 0), "context-attachment had no filename: " + contentAttachment); result.setFilename(StringUtils.substringAfter(contentAttachment, "filename=")); } return result; }
From source file:com.adobe.acs.commons.mcp.impl.processes.cfi.ContentFragmentImportTest.java
private void addImportRow(String path, String title, String... values) { Map<String, CompositeVariant> row = new HashMap<>(); row.put(PATH, new CompositeVariant(path)); row.put(FOLDER_TITLE, new CompositeVariant("test folder")); row.put(NAME, new CompositeVariant(StringUtils.substringAfter(path, "/"))); row.put(TITLE, new CompositeVariant(title)); row.put(TEMPLATE, new CompositeVariant("/test/template")); for (int i = 0; i < values.length - 1; i += 2) { row.put(values[i], new CompositeVariant(values[i + 1])); }/* w w w .ja v a 2 s . c om*/ importer.spreadsheet.getDataRowsAsCompositeVariants().add(row); }
From source file:gobblin.data.management.retention.action.RetentionAction.java
@SuppressWarnings("unchecked") protected VersionSelectionPolicy<DatasetVersion> createSelectionPolicy(Config selectionConfig, Config jobConfig) {/* w w w . j av a 2s.c o m*/ try { String selectionPolicyKey = StringUtils.substringAfter( ConfigurableCleanableDataset.SELECTION_POLICY_CLASS_KEY, ConfigurableCleanableDataset.CONFIGURATION_KEY_PREFIX); Preconditions.checkArgument(selectionConfig.hasPath(selectionPolicyKey)); String className = selectionConfig.getString(selectionPolicyKey); return (VersionSelectionPolicy<DatasetVersion>) GobblinConstructorUtils.invokeFirstConstructor( this.versionSelectionAliasResolver.resolveClass(className), ImmutableList.<Object>of(selectionConfig), ImmutableList.<Object>of(selectionConfig, ConfigUtils.configToProperties(jobConfig)), ImmutableList.<Object>of(ConfigUtils.configToProperties(jobConfig))); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } }
From source file:net.siegmar.japtproxy.fetcher.HttpClientConfigurer.java
protected Credentials buildNTCredentials(final String userPart, final String password) throws InitializationException { final String domain = StringUtils.substringBefore(userPart, "\\"); final String username = StringUtils.substringAfter(userPart, "\\"); return new NTCredentials(username, password, getLocalHostName(), domain); }
From source file:net.sf.jabb.util.text.MatchingDefinition.java
/** * Loads definitions from properties. For example: * <br>name1.expression=...//from w w w .ja v a 2 s. com * <br>name1.example.1=... * <br>name1.example.2=... * <br>... * <br>name1.attachment=... * <br> * <br>name2.expression=... * <br>name2.example.1=... * <br>name2.example.2=... * <br>... * <br>name2.attachment=... * <br>... * @param props * @return */ static public List<MatchingDefinition> load(Map<? extends Object, ? extends Object> props) { List<MatchingDefinition> result = new LinkedList<MatchingDefinition>(); Map<String, Map<String, Object>> defs = new PutIfAbsentMap<String, Map<String, Object>>( new HashMap<String, Map<String, Object>>(), new MapValueFactory<String, Map<String, Object>>() { @Override public Map<String, Object> createValue(String key) { return new HashMap<String, Object>(); } }); // classify for (Map.Entry<? extends Object, ? extends Object> entry : props.entrySet()) { String key = (String) entry.getKey(); String name = StringUtils.substringBefore(key, "."); String postfix = StringUtils.substringAfter(key, "."); defs.get(name).put(postfix, entry.getValue()); } // process for (Map.Entry<String, Map<String, Object>> entry : defs.entrySet()) { Map<String, Object> def = entry.getValue(); String expression = null; Object attachment = null; List<String> examples = new LinkedList<String>(); for (Map.Entry<String, Object> defEntry : def.entrySet()) { String key = defEntry.getKey(); Object value = defEntry.getValue(); if (key != null) { if (key.equalsIgnoreCase("expression")) { expression = (String) value; } else if (key.startsWith("example")) { examples.add((String) value); } else if (key.equalsIgnoreCase("attachment")) { attachment = value; } else { // ignore } } } if (expression != null) { MatchingDefinition mDef = new MatchingDefinition(); mDef.setRegularExpression(expression); mDef.setExactMatchExamples(examples); mDef.setAttachment(attachment); result.add(mDef); } } return result; }
From source file:kenh.xscript.ScriptUtils.java
/** * Use <code>Node</code> to initial an <code>Element</code>. * @param node/*from ww w.j av a2 s . co m*/ * @param env * @return */ private static final Element getElement(Node node, Environment env) throws UnsupportedScriptException { if (env == null) return null; String ns = node.getNamespaceURI(); // name space String name = node.getLocalName(); // name //String prefix = node.getPrefix(); // prefix Element element = env.getElement(ns, name); if (element == null) { throw new UnsupportedScriptException(null, "Could't find the element.[" + (StringUtils.isBlank(ns) ? name : ns + ":" + name) + "]"); } element.setEnvironment(env); NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node attr = attributes.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) { if (attrName.startsWith("xmlns:")) { // to add function package String abbr = StringUtils.substringAfter(attrName, "xmlns:"); if (StringUtils.startsWithAny(abbr, "f.", "func.", "function.")) { abbr = StringUtils.substringAfter(abbr, "."); env.setFunctionPackage(abbr, attrValue); } } } else { element.setAttribute(attrName, attrValue); } } } if (includeTextNode(node)) { String text = node.getTextContent(); element.setText(text); } NodeList nodes = node.getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element child = getElement(n, env); element.addChild(child); } } } return element; }
From source file:de.jfachwert.post.PLZ.java
private static String getPostleitZahl(String plz) { if (!hasLandeskennung(plz)) { return plz; }//from w w w . ja va2s. com return StringUtils.substringAfter(toLongString(plz), "-"); }