Example usage for org.apache.commons.lang StringUtils containsAny

List of usage examples for org.apache.commons.lang StringUtils containsAny

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils containsAny.

Prototype

public static boolean containsAny(String str, String searchChars) 

Source Link

Document

Checks if the String contains any character in the given set of characters.

Usage

From source file:org.colombbus.tangara.io.ScriptReader.java

private static boolean containsWitnessChar(String script) {
     if (script != null)
         return StringUtils.containsAny(script, WITNESS_CHARS);
     return false;
 }

From source file:org.dataconservancy.dcs.util.FilePathUtil.java

/**
 * This method checks whether a file path contains any illegal characters.
 * @param file the file to check/* w ww  .  j av  a  2  s.c o m*/
 * @return boolean true if the path is OK, false otherwise
 */
public static boolean hasValidFilePath(File file) {
    Path path = file.toPath();
    for (int i = 0; i < path.getNameCount(); i++) {
        if (StringUtils.containsAny(path.getName(i).toString(), getCharacterBlackList())) {
            return false;
        }
    }
    return true;
}

From source file:org.dataconservancy.packaging.gui.presenter.impl.PackageGenerationPresenterImpl.java

/**
 * Sets the output name of the file that will be saved based on the path of the output directory the package name,
 * and the archive format, and the compression format.
 *///from  w w  w  .  ja va2 s  .c om
private void setOutputDirectory(boolean overrideStatus) {
    String currentOutput = "";
    String errorText = "";
    boolean hasPackageName = (getPackageName() != null && !getPackageName().isEmpty());

    if (!hasPackageName || controller.getOutputDirectory() == null) {
        if (hasPackageName) {
            errorText = errors.get(ErrorKey.OUTPUT_DIRECTORY_MISSING);
        } else if (controller.getOutputDirectory() != null) {
            errorText = errors.get(ErrorKey.PACKAGE_NAME_MISSING);
        } else {
            errorText = errors.get(ErrorKey.OUTPUT_DIRECTORY_AND_PACKAGE_NAME_MISSING);
        }
    }

    if (StringUtils.containsAny(getPackageName(), controller.getPackageFilenameIllegalCharacters())) {
        errorText = errors.get(ErrorKey.PACKAGE_FILENAME_HAS_ILLEGAL_CHARACTERS) + "   "
                + controller.getPackageFilenameIllegalCharacters();
    }

    if (errorText.isEmpty()) {
        currentOutput = controller.getOutputDirectory().getAbsolutePath() + File.separator + getPackageName();

        if (view.getArchiveToggleGroup().getSelectedToggle() != null
                && !view.getArchiveToggleGroup().getSelectedToggle().getUserData().equals("exploded")) {
            currentOutput += "." + view.getArchiveToggleGroup().getSelectedToggle().getUserData();
        }

        if (view.getCompressionToggleGroup().getSelectedToggle() != null) {
            String compressionExtension = (String) view.getCompressionToggleGroup().getSelectedToggle()
                    .getUserData();
            if (!compressionExtension.isEmpty()) {
                currentOutput += "." + compressionExtension;
            }
        }

        view.getStatusLabel().setVisible(false);
        view.getContinueButton().setDisable(false);
    } else {
        if (overrideStatus || !view.getStatusLabel().isVisible()) {
            view.getStatusLabel().setText(errorText);
            view.getStatusLabel().setTextFill(Color.RED);
            view.getStatusLabel().setVisible(true);
        }
        view.getContinueButton().setDisable(true);
    }

    // Warning for long filenames, won't prevent you from continuing but may cause an error when you actually save
    // Mostly affects Windows machines
    if (currentOutput.length() > 259) {
        view.getStatusLabel().setText(messages.formatFilenameLengthWarning(currentOutput.length()));
        view.getStatusLabel().setTextFill(Color.RED);
        view.getStatusLabel().setVisible(true);
    }

    view.getCurrentOutputDirectoryTextField().setText(currentOutput);
}

From source file:org.eclipse.skalli.gerrit.client.internal.GerritClientImpl.java

@Override
public String checkProjectName(String name) {
    if (StringUtils.isBlank(name)) {
        return "Repository names must not be blank";
    }//from  w  ww  .  j a v a 2 s.c o  m
    if (StringUtils.trim(name).length() < name.length()) {
        return "Repository names must not start or end with whitespace";
    }
    if (containsWhitespace(name, false)) {
        return "Repository names must not contain whitespace";
    }
    if (name.startsWith("/")) {
        return "Repository names must not start with a slash";
    }
    if (name.endsWith("/")) {
        return "Repository names must not end with a trailing slash";
    }
    if (HtmlUtils.containsTags(name)) {
        return "Repository names must not contain HTML tags";
    }
    if (StringUtils.containsAny(name, REPO_NAME_INVALID_CHARS)) {
        return "Repository names must not contain any of the following characters: "
                + "'\', ':', '~', '?', '*', '<', '>', '|', '%', '\"'";
    }
    if (name.startsWith("../") //$NON-NLS-1$
            || name.contains("/../") //$NON-NLS-1$
            || name.contains("/./")) { //$NON-NLS-1$
        return "Repository names must not contain \"../\", \"/../\" or \"/./\"";
    }
    return null;
}

From source file:org.eclipse.skalli.model.Expression.java

@SuppressWarnings("nls")
@Override//from  w  w w  .  j a  v  a 2 s  .c o  m
public String toString() {
    if (arguments == null) {
        return name;
    }
    StringBuilder sb = new StringBuilder(name);
    sb.append('(');
    for (int i = 0; i < arguments.length; ++i) {
        if (i > 0) {
            sb.append(',');
        }
        String arg = arguments[i];
        boolean quoted = StringUtils.containsAny(arg, ", '\"\t\r\n\b\f\\");
        if (quoted) {
            sb.append('\'');
            sb.append(StringUtils.replace(arg, "'", "\\'"));
            sb.append('\'');
        } else {
            sb.append(arg);
        }
    }
    sb.append(')');
    return sb.toString();
}

From source file:org.eclipse.smila.binarystorage.persistence.io.IOHierarchicalManager.java

/**
 * Deterministically calculation of record internal path.
 *
 * @param id/*from  w w w .  j a  v  a2  s  . co m*/
 * @return String path
 * @throws BinaryStorageException
 */
public String calculateDirectoryPath(final String id) throws BinaryStorageException {

    if (StringUtils.containsAny(id, FORBIDDEN_CHARS)) {
        throw new BinaryStorageException(
                "id contains one of the forbidden chars " + FORBIDDEN_CHARS + " : " + id);
    }
    try {
        final StringBuffer internalPath = new StringBuffer();
        for (int i = 0; i < _pathDepth && i * _length + _length < id.length(); i++) {
            int offset = i * _length;
            internalPath.append(id.substring(offset, offset + _length));
            internalPath.append(_separator);
        }
        internalPath.append(id);
        return internalPath.toString();
    } catch (RuntimeException e) {
        throw new BinaryStorageException("unable to create path from id", e);
    }
}

From source file:org.executequery.gui.editor.ManageShortcutsPanel.java

private boolean shortcutsValid(List<EditorSQLShortcut> shortcuts) {

    char[] whitespaces = { ' ', '\n', '\r', '\t' };
    for (EditorSQLShortcut shortcut : shortcuts) {

        if (nameExists(shortcut, shortcut.getShortcut())
                || StringUtils.containsAny(shortcut.getShortcut(), whitespaces)
                || MiscUtils.isNull(shortcut.getQuery())) {

            return false;
        }/*from www.  ja  v a 2s  . com*/

    }

    return true;
}

From source file:org.flite.cach3.aop.CacheBase.java

public static String buildCacheKey(final String objectId, final String namespace, final String prefix) {
    if (objectId == null || objectId.length() < 1) {
        throw new InvalidParameterException("Ids for objects in the cache must be at least 1 character long.");
    }/*from  w  w w  .  ja  v a2 s .  co  m*/
    final StringBuilder result = new StringBuilder(namespace).append(SEPARATOR);
    if (StringUtils.isNotBlank(prefix)) {
        result.append(prefix);
    }
    result.append(objectId);
    if (result.length() > 255) {
        throw new InvalidParameterException(
                "Ids for objects in the cache must not exceed 255 characters: [" + result.toString() + "]");
    }
    final String resultString = result.toString();
    if (StringUtils.containsAny(resultString, WS)) {
        throw new InvalidParameterException(
                "Ids for objects in the cache must not have whitespace: [" + result.toString() + "]");
    }
    return resultString;
}

From source file:org.gradle.util.NameValidator.java

/**
 * Validates that a given name string does not contain any forbidden characters.
 */// w w  w  .  j av  a2  s  .  com
public static void validate(String name, String nameDescription, String fixSuggestion) {
    if (StringUtils.isEmpty(name)) {
        DeprecationLogger.nagUserOfDeprecatedThing("The " + nameDescription + " is empty.", fixSuggestion);
    } else if (StringUtils.containsAny(name, FORBIDDEN_CHARACTERS)) {
        DeprecationLogger.nagUserOfDeprecatedThing(
                "The " + nameDescription + " '" + name + "' contains at least one of the following characters: "
                        + Arrays.toString(FORBIDDEN_CHARACTERS) + ".",
                fixSuggestion);
    } else if (name.charAt(0) == FORBIDDEN_LEADING_AND_TRAILING_CHARACTER
            || name.charAt(name.length() - 1) == FORBIDDEN_LEADING_AND_TRAILING_CHARACTER) {
        DeprecationLogger.nagUserOfDeprecatedThing("The " + nameDescription + " '" + name
                + "' starts or ends with a '" + FORBIDDEN_LEADING_AND_TRAILING_CHARACTER + "'.", fixSuggestion);
    }
}

From source file:org.hoteia.qalingo.core.web.validation.contraint.ForbiddenCharsValidator.java

@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
    return !StringUtils.containsAny(value, forbiddenCharList);
}