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

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

Introduction

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

Prototype

public static boolean containsOnly(String str, String validChars) 

Source Link

Document

Checks if the String contains only certain characters.

Usage

From source file:de.devboost.emfcustomize.EcoreModelRefactorer.java

public Set<Method> getAnnotatedMethods(Class customClass) {
    Set<Method> annotatedMethods = new HashSet<Method>();

    List<Method> methods = customClass.getMethods();
    for (Method method : methods) {
        List<String> comments = method.getComments();
        if (comments != null && comments.size() > 0) {
            for (String comment : comments) {
                String[] lines = comment.split("[\\r\\n]+");
                for (String line : lines) {
                    String deleteWhitespace = StringUtils.deleteWhitespace(line);
                    if (StringUtils.endsWith(deleteWhitespace, MODEL_ANNOTATION)) {
                        String difference = StringUtils.removeEnd(deleteWhitespace, MODEL_ANNOTATION);
                        if (StringUtils.containsOnly(difference, VALID_PREFIX_CHARACTERS)
                                || difference.isEmpty()) {
                            annotatedMethods.add(method);
                        }//w  w  w  .  j  av a  2s  . co  m
                    }
                }
            }
        }
    }
    return annotatedMethods;
}

From source file:de.innovationgate.webgate.api.WGACL.java

/**
 * Determines if a name is a valid role name.
 * Valid role names contain only these characters:
 * a-z,A-Z,0-9,$,#,[,]/*w w w. j  av a2 s.c om*/
 * 
 * @param name The role name candidate
 * @return true, if the role name is valid, false if not
 */
public static boolean isValidRoleName(String name) {

    return StringUtils.containsOnly(name, VALID_ROLENAME_CHARS);

}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static boolean esIdentificadorSqlValido(String string) {
    String validChars = VALID_CHARS;
    return StringUtils.isNotBlank(string) && StringUtils.containsOnly(string.toLowerCase(), validChars)
            && StringUtils.isAlpha(string.substring(0, 1));
}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static boolean esIdentificadorArchivoValido(String string) {
    String validChars = VALID_CHARS;
    return StringUtils.isNotBlank(string) && StringUtils.containsOnly(string.toLowerCase(), validChars);
}

From source file:ips1ap101.lib.core.jsf.JSF.java

public static CampoArchivoMultiPart upload(Part part, String carpeta, EnumOpcionUpload opcion)
        throws Exception {
    Bitacora.trace(JSF.class, "upload", part, carpeta, opcion);
    if (part == null) {
        return null;
    }//from   w w  w  .ja  va  2  s.c o m
    if (part.getSize() == 0) {
        return null;
    }
    String originalName = getPartFileName(part);
    if (StringUtils.isBlank(originalName)) {
        return null;
    }
    CampoArchivoMultiPart campoArchivo = new CampoArchivoMultiPart();
    campoArchivo.setPart(part);
    campoArchivo.setClientFileName(null);
    campoArchivo.setServerFileName(null);
    /**/
    Bitacora.trace(JSF.class, "upload", "name=" + part.getName());
    Bitacora.trace(JSF.class, "upload", "type=" + part.getContentType());
    Bitacora.trace(JSF.class, "upload", "size=" + part.getSize());
    /**/
    String sep = System.getProperties().getProperty("file.separator");
    String validChars = StrUtils.VALID_CHARS;
    String filepath = null;
    if (STP.esIdentificadorArchivoValido(carpeta)) {
        filepath = carpeta.replace(".", sep);
    }
    long id = LongUtils.getNewId();
    //      String filename = STP.getRandomString();
    String filename = id + "";
    String pathname = Utils.getAttachedFilesDir(filepath) + filename;
    String ext = Utils.getExtensionArchivo(originalName);
    if (StringUtils.isNotBlank(ext)) {
        String str = ext.toLowerCase();
        if (StringUtils.containsOnly(str, validChars)) {
            filename += "." + str;
            pathname += "." + str;
        }
    }
    /**/
    //      part.write(pathname);
    /**/
    //      OutputStream outputStream = new FileOutputStream(pathname);
    //      outputStream.write(IOUtils.readFully(part.getInputStream(), -1, false));
    /**/
    int bytesRead;
    int bufferSize = 8192;
    byte[] bytes = null;
    byte[] buffer = new byte[bufferSize];
    try (InputStream input = part.getInputStream(); OutputStream output = new FileOutputStream(pathname)) {
        while ((bytesRead = input.read(buffer)) != -1) {
            if (!EnumOpcionUpload.FILA.equals(opcion)) {
                output.write(buffer, 0, bytesRead);
            }
            if (!EnumOpcionUpload.ARCHIVO.equals(opcion)) {
                if (bytesRead < bufferSize) {
                    bytes = ArrayUtils.addAll(bytes, ArrayUtils.subarray(buffer, 0, bytesRead));
                } else {
                    bytes = ArrayUtils.addAll(bytes, buffer);
                }
            }
        }
    }
    /**/
    String clientFilePath = null;
    String clientFileName = clientFilePath == null ? originalName : clientFilePath + originalName;
    String serverFileName = Utils.getWebServerRelativePath(pathname);
    if (!EnumOpcionUpload.ARCHIVO.equals(opcion)) {
        String contentType = part.getContentType();
        long size = part.getSize();
        insert(id, clientFileName, serverFileName, contentType, size, bytes);
    }
    campoArchivo.setClientFileName(clientFileName);
    campoArchivo.setServerFileName(serverFileName);
    return campoArchivo;
}

From source file:com.borqs.sync.server.contact.admin.ContactSyncSourceAdminPanel.java

/**
 * Checks if the values provided by the user are all valid. If they are, the
 * method ends regularly./*from w  w  w  . j  av  a2s . co  m*/
 *
 * @throws IllegalArgumentException if name, uri, type or directory are empty
 *                                  (null or zero-length)
 */
protected void validateValues() throws IllegalArgumentException {
    String value = null;

    value = nameValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Name' cannot be empty. " + "Please provide a SyncSource name.");
    }

    if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) {
        throw new IllegalArgumentException(
                "Only the following characters are allowed for field 'Name':" + "\n" + NAME_ALLOWED_CHARS);
    }

    value = (String) typeCombo.getSelectedItem();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Type' cannot be empty. " + "Please provide a SyncSource type.");
    }

    value = sourceUriValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Source URI' cannot be empty. " + "Please provide a SyncSource URI.");
    }
}

From source file:com.funambol.foundation.admin.FileSystemSyncSourceConfigPanel.java

/**
 * Checks if the values provided by the user are all valid. In caso of errors,
 * a IllegalArgumentException is thrown.
 *
 * @throws IllegalArgumentException if:/*from w  w  w .  j  a  v  a2  s  .c  om*/
 *         <ul>
 *         <li>name, uri, type or directory are empty (null or zero-length)
 *         <li>the types list length does not match the versions list length
 *         </ul>
 */
private void validateValues() throws IllegalArgumentException {
    String value = null;

    value = nameValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException("Field 'Name' cannot be empty. Please provide a SyncSource name.");
    }

    if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) {
        throw new IllegalArgumentException(
                "Only the following characters are allowed for field 'Name': \n" + NAME_ALLOWED_CHARS);
    }

    value = sourceUriValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Source URI' cannot be empty. Please provide a SyncSource URI.");
    }

    value = directoryValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Source directory' cannot be empty. Please provide a SyncSource db directory.");
    }

    int typesCount = new StringTokenizer(infoTypesValue.getText(), ",").countTokens();
    if (typesCount == 0) {
        throw new IllegalArgumentException(
                "Field 'Supported types' cannot be empty. Please provide one or more supported types.");
    }
    if (typesCount != new StringTokenizer(infoVersionsValue.getText(), ",").countTokens()) {
        throw new IllegalArgumentException("Number of supported types does not match number of versions");
    }
}

From source file:com.db4o.sync4o.ui.Db4oSyncSourceConfigPanel.java

/**
 * Checks if the values provided by the user are all valid. Whenever an
 * invalid value is found, an IllegalArgumentException is thrown (this
 * appears to be the pattern expected by the calling Funambol infrastructure).
 *//*from   ww  w . j  a v a  2  s  .c  o  m*/
private void validateValues() {

    String value = null;

    value = _nameValue.getText();
    if (StringUtils.isBlank(value)) {
        notifyError(new AdminException("Field 'Name' cannot be empty. Please provide a SyncSource name."));
        return;
    }

    if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) {
        notifyError(new AdminException(
                "Only the following characters are allowed for field 'Name': \n" + NAME_ALLOWED_CHARS));
        return;
    }

    value = _sourceUriValue.getText();
    if (StringUtils.isBlank(value)) {
        notifyError(new AdminException("Field 'Source URI' cannot be empty. Please provide a SyncSource URI."));
        return;
    }

    value = _dbFileValue.getText();
    if (StringUtils.isBlank(value)) {
        notifyError(
                new AdminException("Field 'db4o File' cannot be empty. Please provide a path to a db4o file."));
        return;
    }

    File f = new File(value);
    if (!isValidDatabase(f)) {
        notifyError(new AdminException("Field 'db4o File' must refer to an existing db4o file."));
        return;
    }

    if (!_classConfigsTree.validateConfigs()) {
        notifyError(new AdminException("Configuration of classes to be synchronized is in error."));
        return;
    }
}

From source file:com.funambol.json.admin.CalendarSyncSourceAdminPanel.java

/**
 * Checks if the values provided by the user are all valid. In caso of errors,
 * a IllegalArgumentException is thrown.
 *
 * @throws IllegalArgumentException if:/*from  w w w .j a va  2  s.c o m*/
 *         <ul>
 *         <li>name, uri, type or directory are empty (null or zero-length)
 *         <li>the types list length does not match the versions list length
 *         </ul>
 */
private void validateValues() throws IllegalArgumentException {
    String value = null;

    value = nameValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Name' cannot be empty. " + "Please provide a SyncSource name.");
    }

    if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) {
        throw new IllegalArgumentException(
                "Only the following characters are allowed for field 'Name':" + "\n" + NAME_ALLOWED_CHARS);
    }

    value = (String) typeCombo.getSelectedItem();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Type' cannot be empty. " + "Please provide a SyncSource type.");
    }

    value = sourceUriValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Source URI' cannot be empty. " + "Please provide a SyncSource URI.");
    }

    if (!eventValue.isSelected() && !taskValue.isSelected()) {
        throw new IllegalArgumentException("Please check at least one between 'Events' and 'Tasks'.");
    }

}

From source file:com.funambol.admin.module.panels.DefaultSyncSourceConfigPanel.java

/**
 * Checks if the values provided by the user are all valid. If they are, the
 * method ends regularly.// w w  w  .ja  v a 2  s.  co m
 *
 * @throws IllegalArgumentException if the needed values are empty (null or
 *                                  zero-length)
 */
private void validateValues() throws IllegalArgumentException {
    String value = null;

    value = sourceUriValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Source URI' cannot be empty. " + "Please provide a SyncSource URI.");
    }

    value = nameValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException(
                "Field 'Name' cannot be empty. " + "Please provide a SyncSource name.");
    }

    if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) {
        throw new IllegalArgumentException(
                "Only the following characters are allowed for field 'Name':" + "\n" + NAME_ALLOWED_CHARS);
    }

    int typesCount = new StringTokenizer(infoTypesValue.getText(), ",").countTokens();
    if (typesCount == 0) {
        throw new IllegalArgumentException(
                "Field 'Supported types' cannot be empty. " + "Please provide one or more supported types.");
    }

    value = infoVersionsValue.getText();
    if (StringUtils.isEmpty(value)) {
        throw new IllegalArgumentException("Field 'Supported versions' cannot be empty. "
                + "Please provide one or more supported versions.");
    }

    if (typesCount != new StringTokenizer(infoVersionsValue.getText(), ",").countTokens()) {
        throw new IllegalArgumentException("Number of supported types does not match number of versions");
    }

}