Java Code Examples for org.apache.commons.lang3.StringUtils#containsNone()

The following examples show how to use org.apache.commons.lang3.StringUtils#containsNone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopicPermissionImpl.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
public TopicPermissionImpl(@NotNull final String topic, @NotNull final PermissionType type, @NotNull final Qos qos,
                           @NotNull final MqttActivity activity, @NotNull final Retain retain,
                           @NotNull final SharedSubscription sharedSubscription, @NotNull final String sharedGroup) {
    this.topic = topic;
    this.type = type;
    this.qos = qos;
    this.activity = activity;
    this.retain = retain;
    this.sharedSubscription = sharedSubscription;
    this.sharedGroup = sharedGroup;

    //these are used to speed up the evaluation of permissions
    final String strippedPermissionTopic = StringUtils.stripEnd(topic, "/");
    splitTopic = StringUtils.splitPreserveAllTokens(strippedPermissionTopic, "/");
    containsWildcardCharacter = !StringUtils.containsNone(strippedPermissionTopic, "#+");
    isRootWildcard = strippedPermissionTopic.contains("#");
    endsWithWildcard = StringUtils.endsWith(strippedPermissionTopic, "/#");
}
 
Example 2
Source File: TokenizedTopicMatcher.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
public boolean matches(@NotNull final String topicSubscription, @NotNull final String actualTopic) throws InvalidTopicException {

        if (StringUtils.containsAny(actualTopic, "#+")) {
            throw new InvalidTopicException("The actual topic must not contain a wildard character (# or +)");
        }
        final String subscription = StringUtils.stripEnd(topicSubscription, "/");

        String topic = actualTopic;

        if (actualTopic.length() > 1) {
            topic = StringUtils.stripEnd(actualTopic, "/");

        }
        if (StringUtils.containsNone(topicSubscription, "#+")) {

            return subscription.equals(topic);
        }
        if (actualTopic.startsWith("$") && !topicSubscription.startsWith("$")) {
            return false;
        }
        return matchesWildcards(subscription, topic);
    }
 
Example 3
Source File: FeedUtils.java    From commafeed with Apache License 2.0 6 votes vote down vote up
public static String escapeIFrameCss(String orig) {
	String rule = "";
	CSSOMParser parser = new CSSOMParser();
	try {
		List<String> rules = new ArrayList<>();
		CSSStyleDeclaration decl = parser.parseStyleDeclaration(new InputSource(new StringReader(orig)));

		for (int i = 0; i < decl.getLength(); i++) {
			String property = decl.item(i);
			String value = decl.getPropertyValue(property);
			if (StringUtils.isBlank(property) || StringUtils.isBlank(value)) {
				continue;
			}

			if (ALLOWED_IFRAME_CSS_RULES.contains(property) && StringUtils.containsNone(value, FORBIDDEN_CSS_RULE_CHARACTERS)) {
				rules.add(property + ":" + decl.getPropertyValue(property) + ";");
			}
		}
		rule = StringUtils.join(rules, "");
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
	return rule;
}
 
Example 4
Source File: FeedUtils.java    From commafeed with Apache License 2.0 6 votes vote down vote up
public static String escapeImgCss(String orig) {
	String rule = "";
	CSSOMParser parser = new CSSOMParser();
	try {
		List<String> rules = new ArrayList<>();
		CSSStyleDeclaration decl = parser.parseStyleDeclaration(new InputSource(new StringReader(orig)));

		for (int i = 0; i < decl.getLength(); i++) {
			String property = decl.item(i);
			String value = decl.getPropertyValue(property);
			if (StringUtils.isBlank(property) || StringUtils.isBlank(value)) {
				continue;
			}

			if (ALLOWED_IMG_CSS_RULES.contains(property) && StringUtils.containsNone(value, FORBIDDEN_CSS_RULE_CHARACTERS)) {
				rules.add(property + ":" + decl.getPropertyValue(property) + ";");
			}
		}
		rule = StringUtils.join(rules, "");
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
	return rule;
}
 
Example 5
Source File: GemlockParser.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
private Optional<String> parseValidVersion(final String version) {
    String validVersion = null;

    if (version.endsWith(VERSION_SUFFIX) && StringUtils.containsNone(version, FUZZY_VERSION_CHARACTERS)) {
        validVersion = StringUtils.replaceChars(version, VERSION_CHARACTERS, "").trim();
    }

    return Optional.ofNullable(validVersion);
}
 
Example 6
Source File: PermissionTopicMatcher.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matches(@NotNull final String permissionTopic, @NotNull final String actualTopic) throws InvalidTopicException {
    final String stripedPermissionTopic = StringUtils.stripEnd(permissionTopic, "/");
    final String[] splitPermissionTopic = StringUtils.splitPreserveAllTokens(stripedPermissionTopic, "/");
    final boolean nonWildCard = StringUtils.containsNone(stripedPermissionTopic, "#+");
    final boolean rootWildCard = stripedPermissionTopic.contains("#");
    final boolean endsWithWildCard = StringUtils.endsWith(stripedPermissionTopic, "/#");

    final String stripedActualTopic = StringUtils.stripEnd(actualTopic, "/");
    final String[] splitActualTopic = StringUtils.splitPreserveAllTokens(stripedActualTopic, "/");
    return matches(stripedPermissionTopic, splitPermissionTopic, nonWildCard, endsWithWildCard, rootWildCard, stripedActualTopic, splitActualTopic);
}
 
Example 7
Source File: RepomdWriter.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes all control characters from passed in String.
 * @param pkgId package id
 * @param input char input
 * @return sanitized string
 */
protected static String sanitize(Long pkgId, String input) {
    if (StringUtils.containsNone(input, CONTROL_CHARS)) {
        return input;
    }
    if (log.isDebugEnabled()) {
        log.debug("Package " + pkgId +
                " metadata contains control chars, cleanup required: " + input);
    }
    return StringUtils.replaceChars(input, CONTROL_CHARS, CONTROL_CHARS_REPLACEMENT);
}
 
Example 8
Source File: GemlockParser.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
private Optional<String> parseValidVersion(final String version) {
    String validVersion = null;

    if (version.endsWith(VERSION_SUFFIX) && StringUtils.containsNone(version, FUZZY_VERSION_CHARACTERS)) {
        validVersion = StringUtils.replaceChars(version, VERSION_CHARACTERS, "").trim();
    }

    return Optional.ofNullable(validVersion);
}
 
Example 9
Source File: CsvWriter.java    From sample-boot-hibernate with MIT License 5 votes vote down vote up
private String escape(String s) {
    if (layout.isNonQuote()) {
        return s;
    }
    char delim = layout.getDelim();
    char quote = layout.getQuote();
    String quoteStr = String.valueOf(quote);
    String eol = layout.getEolSymbols();
    if (StringUtils.containsNone(s, delim, quote) && StringUtils.containsNone(s, eol)) {
        return quoteStr + s + quoteStr;
    } else {
        return quoteStr + StringUtils.replace(s, quoteStr, quoteStr + quoteStr) + quoteStr;
    }
}