List of usage examples for org.apache.commons.lang3 StringUtils split
public static String[] split(final String str, final String separatorChars, final int max)
Splits the provided text into an array with a maximum length, separators specified.
The separator is not included in the returned String array.
From source file:io.apiman.gateway.platforms.vertx3.common.config.ThreeScaleRequestPathParser.java
@Override public ApiRequestPathInfo parseEndpoint(String path, HeaderMap headers) { String[] split = StringUtils.split(path, "/", 3); if (split == null || split.length < 2 || !"services".equalsIgnoreCase(split[0])) { throw new IllegalArgumentException("Invalid path format, expected /service/serviceName"); }// ww w .ja v a 2 s .c om ApiRequestPathInfo parsed = new ApiRequestPathInfo(); parsed.orgId = "DEFAULT"; parsed.apiVersion = "DEFAULT"; parsed.apiId = split[1]; if (split.length > 2) { parsed.resource = "/" + split[2]; } else { parsed.resource = "/"; } return parsed; }
From source file:kenh.expl.functions.Split.java
public String[] process(String str, String separatorChar, int max) { return StringUtils.split(str, separatorChar, max); }
From source file:io.apiman.gateway.engine.threescale.ThreeScaleRequestPathParser.java
@Override public ApiRequestPathInfo parseEndpoint(String path, HeaderMap headers) { String[] split = StringUtils.split(path, "/", 3); if (split == null || split.length < 2 || !"services".equalsIgnoreCase(split[0])) { throw new IllegalArgumentException("Invalid path format, expected /services/serviceName"); }// w w w . j a va 2s . co m ApiRequestPathInfo parsed = new ApiRequestPathInfo(); parsed.orgId = defaultOrgName; parsed.apiVersion = defaultVersion; parsed.apiId = split[1]; if (split.length > 2) { parsed.resource = "/" + split[2]; } else { parsed.resource = "/"; } return parsed; }
From source file:com.github.rvesse.airline.parser.options.AbstractNameValueOptionParser.java
@Override public ParseState<T> parseOptions(PeekingIterator<String> tokens, ParseState<T> state, List<OptionMetadata> allowedOptions) { List<String> parts = AirlineUtils.unmodifiableListCopy( StringUtils.split(tokens.peek(), new String(new char[] { this.separator }), 2)); if (parts.size() != 2) { return null; }/*from www.java2s. c om*/ OptionMetadata option = findOption(state, allowedOptions, parts.get(0)); if (option == null || option.getArity() != 1) { // Only supported for arity 1 options currently return null; } // we have a match so consume the token tokens.next(); // update state state = state.pushContext(Context.OPTION).withOption(option); state = state.withOptionValue(option, parts.get(1)).popContext(); return state; }
From source file:de.jfachwert.pruefung.exception.LocalizedValidationException.java
/** * Im Gegensatz {@code getMessage()} wird hier die Beschreibung auf deutsch * zurueckgegeben, wenn die Loacale auf Deutsch steht. * * @return lokalisierte Beschreibung// w w w. j av a 2s.com */ public String getLocalizedMessage() { String[] parts = StringUtils.split(getMessage(), ":", 2); String localized = getLocalizedString(getMessageKey(parts[0])); if (parts.length > 1) { localized += ":" + parts[1]; } return localized; }
From source file:com.yevster.spdxtra.Validate.java
public static void spdxElementUri(String uri) { String[] elements = StringUtils.split(uri, "#", 2); if (elements.length != 2) throw exceptionFactory.apply("Illegal SPDX Element URI: " + uri); try {/* w w w. j a va 2 s.c o m*/ baseUrl(elements[0]); spdxElementId(elements[1]); } catch (RuntimeException e) { throw exceptionFactoryWithCause.apply("Illegal SPDX Element URI: " + uri, e); } }
From source file:com.github.wolfdogs.kemono.util.resource.fs.FsDirResource.java
@Override public Resource get(String path) { String[] childs = StringUtils.split(path, "/\\", 2); if (childs.length == 0) return this; Resource res = getChild(childs[0]); if (childs.length == 1) return res; if (childs.length == 2 && res instanceof DirResource) { DirResource dirRes = (DirResource) res; return dirRes.get(childs[1]); }/*from ww w.j a v a 2 s .c om*/ return null; }
From source file:io.stallion.forms.SimpleFormEndpoints.java
@POST @Path("/contacts/submit-form") public Boolean submitForm( @ObjectParam(targetClass = SimpleFormSubmission.class) SimpleFormSubmission rawSubmission) { SimpleFormSubmission submission = SafeMerger.with().nonEmpty("antiSpamToken", "pageUrl", "data") .optionalEmail("email").optional("pageTitle", "formId").merge(rawSubmission); /* The Anti-spam token is an encrypted token with a milliseconds timestamp and a randomly generated key This prevents a spammer from simply hitting this endpoint over and over again with a script. A given random key can only be used once within an hour, and all tokens expire after an hour, so all together it is not possible to submit more than once. /*from w w w . j a v a2 s . c om*/ This will not stop a spammer who is actually requesting a new copy of the page and who is parsing out the spam token single every time. We would have to implement IP address throttling or captchas to fix that. */ String token = Encrypter.decryptString(settings().getAntiSpamSecret(), submission.getAntiSpamToken()); if (empty(token) || !token.contains("|")) { throw new ClientException("Anti-spam token is not in the correct format"); } String[] parts = StringUtils.split(token, "|", 2); Long time = Long.parseLong(parts[0]); String randomKey = parts[1]; if (time == null || ((time + 60 * 60 * 1000) < mils())) { throw new ClientException("Anti-spam token has expired. Please reload the page and submit again."); } Integer submissionCount = or((Integer) LocalMemoryCache.get("form_submissions", randomKey), 0); if (submissionCount > 0) { throw new ClientException("You have already submitted this form once."); } submission.setSubmittedAt(mils()); SimpleFormSubmissionController.instance().save(submission); if (!empty(submission.getEmail())) { SimpleFormSubmissionEmailTask.enqueue(submission); } // Store a record of this token, so it cannot be reused LocalMemoryCache.set("form_submissions", randomKey, submissionCount + 1, 90 * 60 * 1000); return true; }
From source file:com.sonicle.webtop.core.app.servlet.BaseRequest.java
protected String[] splitPath(String pathInfo) throws MalformedURLException { String[] tokens = StringUtils.split(pathInfo, "/", 2); if (tokens.length != 2) throw new MalformedURLException("URL does not esplicitate service ID"); return tokens; }
From source file:io.stallion.users.OAuthClientController.java
public static long fullIdToLongId(String fullClientId) { String idPart = ""; if (!fullClientId.contains("-")) { idPart = fullClientId;//from w ww . ja va 2 s . c om } else { idPart = StringUtils.split(fullClientId, "-", 2)[0]; } if (!StringUtils.isNumeric(idPart)) { return 0; } return Long.parseLong(idPart); }