List of usage examples for org.apache.commons.lang StringUtils containsAny
public static boolean containsAny(String str, String searchChars)
Checks if the String contains any character in the given set of characters.
From source file:org.openmrs.validator.ImplementationIdValidator.java
@Override public void validate(Object obj, Errors errors) throws APIException { ImplementationId implId = (ImplementationId) obj; char[] illegalChars = { '^', '|' }; if (implId == null) { throw new APIException("ImplementationId.null", (Object[]) null); } else {/*from w ww. j a v a 2 s . c o m*/ ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "ImplementationId.name.empty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "implementationId", "ImplementationId.implementationId.empty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passphrase", "ImplementationId.passphrase.empty"); if (implId.getImplementationId() != null && StringUtils.containsAny(implId.getImplementationId(), illegalChars)) { errors.rejectValue("implementationId", "ImplementationId.implementationId.invalidCharacter"); } } }
From source file:org.openregistry.core.aspect.LastNameAspect.java
@Around("set(@org.openregistry.core.domain.normalization.LastName * *)") public Object transformFieldValue(final ProceedingJoinPoint joinPoint) throws Throwable { final String value = (String) joinPoint.getArgs()[0]; if (isDisabled() || value == null || value.isEmpty()) { return joinPoint.proceed(); }/*w w w . j a v a 2 s . c o m*/ final String overrideValue = getCustomMapping().get(value); if (overrideValue != null) { return joinPoint.proceed(new Object[] { overrideValue }); } if (StringUtils.containsAny(value, delimiters)) { final String casifyValue = WordUtils.capitalizeFully(value, delimiters); if (casifyValue.startsWith("Mc") && casifyValue.length() > 2) { return joinPoint.proceed( new Object[] { "Mc" + WordUtils.capitalizeFully(casifyValue.substring(2), delimiters) }); } return joinPoint.proceed(new Object[] { casifyValue }); } else { final String casifyValue = WordUtils.capitalizeFully(value); if (casifyValue.startsWith("Mc") && casifyValue.length() > 2) { return joinPoint .proceed(new Object[] { "Mc" + WordUtils.capitalizeFully(casifyValue.substring(2)) }); } return joinPoint.proceed(new Object[] { casifyValue }); } }
From source file:org.openscore.lang.compiler.modeller.transformers.ForTransformer.java
private boolean isContainInvalidChars(String varName) { return StringUtils.containsAny(varName, " \t\r\n\b"); }
From source file:org.orcid.frontend.web.forms.OAuthRegistrationFormTest.java
@Test public void testProfileMapping() throws Exception { OAuthRegistrationForm form = new OAuthRegistrationForm(); form.setConfirmedEmail("confirmedEmail"); form.setConfirmedPassword("confirmedPassword"); form.setEmail("email"); form.setFamilyName("familyName"); form.setGivenNames("givenNames"); form.setKeepLoggedIn(false);//w w w . j a v a 2 s.com form.setNewFeatureInformationRequested(true); form.setPassword("password"); form.setRelatedProductsServiceInformationRequested(false); form.setTermsAccepted(true); OrcidProfile profile = form.getOrcidProfile(); assertNotNull(profile); String actual = profile.toString(); String expected = IOUtils.toString(getClass().getResourceAsStream("minimal_orcid_profile.xml")); boolean profileDataFound = StringUtils.containsAny(actual, expected); assertTrue(profileDataFound); }
From source file:org.pentaho.di.www.ServletTestUtils.java
public static boolean hasBadText(String value) { Matcher matcher = PATTERN.matcher(value); if (matcher.find()) { return true; }/*w w w.ja v a2s . c o m*/ return StringUtils.containsAny(value, BAD_CHARACTERS_TO_ESCAPE); }
From source file:org.restcomm.connect.sms.smpp.RegexRemover.java
/** * SMPP is not supporting organizations at the moment, disable regexes to * prevent an organization to capture all cloud traffic with a single regex. * * @param numbers/*from w w w . j av a2s. com*/ */ static void removeRegexes(List<IncomingPhoneNumber> numbers) { //use a list to prevent conc access during iteration List<IncomingPhoneNumber> toBeRemoved = new ArrayList(); if (numbers != null) { for (IncomingPhoneNumber nAux : numbers) { if (StringUtils.containsAny(nAux.getPhoneNumber(), REGEX_SPECIAL_CHARS)) { //mark this as to be removed later toBeRemoved.add(nAux); } } //finally remove regexes for (IncomingPhoneNumber nAux : toBeRemoved) { //this is relying on Java default equals IncomingPhoneNumber numbers.remove(nAux); } } }
From source file:org.sakaiproject.tool.assessment.services.GradingService.java
/** * extractCalculations() is a utility function for Calculated Questions. It takes * one parameter, which is a block of text, and looks for any calculations * that are encoded in the text. A calculations is enclosed in [[ ]]. * <p>For example, if the passed parameter is <code>{a} + {b} = {{c}}, [[{a}+{b}]]</code>, * the resulting list would contain one entry: a string of "{a}+{b}" * <p>Formulas must contain at least one variable OR parens OR calculation symbol (*-+/) * @param text contents to be searched//from www . j a v a 2 s. c om * @return a list of matching calculations. If no calculations are found, the * list will be empty. */ public List<String> extractCalculations(String text) { List<String> calculations = extractCalculatedQuestionKeyFromItemText(text, CALCQ_CALCULATION_PATTERN); for (Iterator<String> iterator = calculations.iterator(); iterator.hasNext();) { String calc = iterator.next(); if (!StringUtils.containsAny(calc, "{}()+-*/")) { iterator.remove(); } } return calculations; }
From source file:org.sonar.plugins.web.checks.coding.InternationalizationCheck.java
private static boolean isPunctuationOrSpace(String value) { return StringUtils.containsAny(value, PUNCTUATIONS_AND_SPACE); }
From source file:org.sonar.squidbridge.checks.AbstractSingleLineCommentsSyntaxCheck.java
@Override public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { if (trivia.isComment() && trivia.getToken().getLine() < token.getLine()) { String comment = trivia.getToken().getOriginalValue(); if (!comment.startsWith(getSingleLineCommentSyntaxPrefix()) && !StringUtils.containsAny(comment, "\r\n")) { getContext().createLineViolation(this, "This single line comment should use the single line comment syntax \"{0}\"", trivia.getToken(), getSingleLineCommentSyntaxPrefix()); }/*from ww w . j a v a 2 s . com*/ } } }
From source file:org.talend.dataprep.api.filter.SimpleFilterService.java
/** * Test a string value against a pattern returned during value analysis. * * @param value A string value. May be null. * @param pattern A pattern as returned in value analysis. * @return <code>true</code> if value matches, <code>false</code> otherwise. *///w w w . j a v a 2 s .c o m private boolean matches(String value, String pattern) { if (value == null && pattern == null) { return true; } if (value == null) { return false; } // Character based patterns if (StringUtils.containsAny(pattern, new char[] { 'A', 'a', '9' })) { if (value.length() != pattern.length()) { return false; } final char[] valueArray = value.toCharArray(); final char[] patternArray = pattern.toCharArray(); for (int i = 0; i < valueArray.length; i++) { if (patternArray[i] == 'A') { if (!Character.isUpperCase(valueArray[i])) { return false; } } else if (patternArray[i] == 'a') { if (!Character.isLowerCase(valueArray[i])) { return false; } } else if (patternArray[i] == '9') { if (!Character.isDigit(valueArray[i])) { return false; } } else { if (valueArray[i] != patternArray[i]) { return false; } } } } else { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); try { formatter.toFormat().parseObject(value); } catch (ParseException e) { return false; } } return true; }