Example usage for org.apache.commons.lang3 StringUtils isAlphanumeric

List of usage examples for org.apache.commons.lang3 StringUtils isAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isAlphanumeric.

Prototype

public static boolean isAlphanumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode letters or digits.

null will return false .

Usage

From source file:org.forgerock.openidm.provisioner.openicf.impl.SimpleSystemIdentifier.java

public SimpleSystemIdentifier(JsonValue configuration) throws JsonValueException {
    name = configuration.get("name").required().expect(String.class).asString().trim();

    if (StringUtil.isBlank(name)) {
        throw new JsonValueException(configuration, "Failed to determine system name from configuration.");
    }/*  w w  w.ja  v a  2 s. c  o  m*/
    if (!StringUtils.isAlphanumeric(name)) {
        throw new JsonValueException(configuration, "System name is not alphanumeric: " + name);
    }
}

From source file:org.forgerock.openidm.provisioner.SimpleSystemIdentifier.java

public SimpleSystemIdentifier(JsonValue configuration) throws JsonValueException {
    name = configuration.get("name").required().expect(String.class).asString().trim();

    if (StringUtils.isBlank(name)) {
        throw new JsonValueException(configuration, "Failed to determine system name from configuration.");
    }/* w ww. jav  a 2s  .c o  m*/
    if (!StringUtils.isAlphanumeric(name)) {
        throw new JsonValueException(configuration, "System name is not alphanumeric: " + name);
    }
}

From source file:org.gvnix.web.datatables.util.QuerydslUtils.java

/**
 * Return where clause expression for non-String
 * {@code entityPath.fieldName} by transforming it to text before check its
 * value.//from  w w w.ja  v  a  2 s .  c  o m
 * <p/>
 * Expr:
 * {@code entityPath.fieldName.as(String.class) like ('%' + searchStr + '%')}
 * <p/>
 * Like operation is case insensitive.
 * 
 * @param entityPath Full path to entity and associations. For example:
 *        {@code Pet} , {@code Pet.owner}
 * @param fieldName Property name in the given entity path. For example:
 *        {@code weight} in {@code Pet} entity, {@code age} in
 *        {@code Pet.owner} entity.
 * @param searchStr the value to find, may be null
 * @param enumClass Enumeration type. Needed to enumeration values
 * @return BooleanExpression
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> BooleanExpression createEnumExpression(PathBuilder<T> entityPath, String fieldName,
        String searchStr, Class<? extends Enum> enumClass) {
    if (StringUtils.isEmpty(searchStr)) {
        return null;
    }
    // Filter string to search than cannot be a identifier
    if (!StringUtils.isAlphanumeric(StringUtils.lowerCase(searchStr))) {
        return null;
    }

    // TODO i18n of enum name

    // normalize search string
    searchStr = StringUtils.trim(searchStr).toLowerCase();

    // locate enums matching by name
    Set matching = new HashSet();

    Enum<?> enumValue;
    String enumStr;

    for (Field enumField : enumClass.getDeclaredFields()) {
        if (enumField.isEnumConstant()) {
            enumStr = enumField.getName();
            enumValue = Enum.valueOf(enumClass, enumStr);

            // Check enum name contains string to search
            if (enumStr.toLowerCase().contains(searchStr)) {
                // Add to matching enum
                matching.add(enumValue);
                continue;
            }

            // Check using toString
            enumStr = enumValue.toString();
            if (enumStr.toLowerCase().contains(searchStr)) {
                // Add to matching enum
                matching.add(enumValue);
            }
        }
    }
    if (matching.isEmpty()) {
        return null;
    }

    // create a enum in matching condition
    BooleanExpression expression = entityPath.get(fieldName).in(matching);
    return expression;
}

From source file:org.n52.oss.Identifiers.java

@Test
public void identifiersAreGenerated() {
    IdentifierGenerator gen = new ShortAlphanumericIdentifierGenerator();
    String id0 = gen.generate();//from  w  w  w .  j av  a 2s .  c o m
    System.out.println("Generated id: " + id0);
    String id1 = gen.generate();
    System.out.println("Generated id: " + id1);
    String id2 = gen.generate();
    System.out.println("Generated id: " + id2);

    assertThat(id0, not(equalTo(id1)));
    assertThat(id0, not(equalTo(id2)));
    assertThat(id1, not(equalTo(id2)));

    assertTrue(StringUtils.isAlphanumeric(id0));
    assertTrue(StringUtils.isAlphanumeric(id1));
    assertTrue(StringUtils.isAlphanumeric(id2));

    assertTrue(StringUtils.isAllLowerCase(id0.replaceAll("[\\d.]", "")));
    assertTrue(StringUtils.isAllLowerCase(id1.replaceAll("[\\d.]", "")));
    assertTrue(StringUtils.isAllLowerCase(id2.replaceAll("[\\d.]", "")));
}

From source file:org.openml.weka.algorithm.WekaAlgorithm.java

public static String getVersion(String algorithm) {
    String version = "undefined";
    try {/*from w  w w  .  j a  va  2 s.  c  o m*/
        RevisionHandler classifier = (RevisionHandler) Class.forName(algorithm).newInstance();
        if (StringUtils.isAlphanumeric(classifier.getRevision())) {
            version = classifier.getRevision();
        }
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return version;
}

From source file:org.paxml.bean.excel.ReadExcelTag.java

protected int[] getXY(String xy) {
    xy = xy.trim();/*from  www  . j  a v  a  2  s .  c  om*/
    if (StringUtils.isEmpty(xy)) {
        return new int[] { -1, -1 };
    }
    if (!StringUtils.isAlphanumeric(xy)) {
        return null;
    }
    CellReference ref = new CellReference(xy);
    return new int[] { ref.getRow() < 0 ? -1 : ref.getRow(), ref.getCol() < 0 ? -1 : ref.getCol() };
}

From source file:org.paxml.table.excel.ExcelRange.java

public final static int[] getXY(String xy) {
    xy = xy.trim();//  w w w  . ja v  a2 s .co m
    if (StringUtils.isEmpty(xy)) {
        return new int[] { -1, -1 };
    }
    if (!StringUtils.isAlphanumeric(xy)) {
        return null;
    }
    CellReference ref = new CellReference(xy);
    return new int[] { ref.getRow() < 0 ? -1 : ref.getRow(), ref.getCol() < 0 ? -1 : ref.getCol() };
}

From source file:org.talend.components.azurestorage.blob.runtime.AzureStorageContainerRuntime.java

@Override
public ValidationResult initialize(RuntimeContainer runtimeContainer, ComponentProperties properties) {
    // init/*from   w  w w  .j  av  a 2  s.  com*/
    AzureStorageContainerProperties componentProperties = (AzureStorageContainerProperties) properties;

    this.containerName = componentProperties.container.getValue();

    // validate
    ValidationResult validationResult = super.initialize(runtimeContainer, properties);
    if (validationResult.getStatus() == ValidationResult.Result.ERROR) {
        return validationResult;
    }

    String errorMessage = "";
    // not empty
    if (StringUtils.isEmpty(containerName)) {
        errorMessage = messages.getMessage("error.ContainerEmpty");
    }
    // valid characters 0-9 a-z and -
    else if (!StringUtils.isAlphanumeric(containerName.replaceAll("-", ""))) {

        errorMessage = messages.getMessage("error.IncorrectName");
    }
    // all lowercase
    else if (!StringUtils.isAllLowerCase(containerName.replaceAll("(-|\\d)", ""))) {
        errorMessage = messages.getMessage("error.UppercaseName");
    }
    // length range : 3-63
    else if ((containerName.length() < 3) || (containerName.length() > 63)) {
        errorMessage = messages.getMessage("error.LengthError");
    }

    if (errorMessage.isEmpty()) {
        return ValidationResult.OK;
    } else {
        return new ValidationResult(ValidationResult.Result.ERROR, errorMessage);
    }
}

From source file:org.talend.components.azurestorage.blob.runtime.AzureStorageSource.java

@Override
public ValidationResult validate(RuntimeContainer container) {
    // checks that account name and key are not empty
    ValidationResult superRes = super.validate(container);
    if (superRes != ValidationResult.OK)
        return superRes;
    // No validation for listing containers
    if (this.properties instanceof TAzureStorageContainerListProperties) {
        return ValidationResult.OK;
    }//from  w w  w. j a va2  s  .c om
    // Checks that container name follows MS naming rules
    if (this.properties instanceof AzureStorageContainerProperties) {
        String cnt = ((AzureStorageContainerProperties) this.properties).container.getValue();
        // not empty
        if (StringUtils.isEmpty(cnt)) {
            ValidationResult vr = new ValidationResult();
            vr.setMessage(messages.getMessage("error.ContainerEmpty")); //$NON-NLS-1$
            vr.setStatus(ValidationResult.Result.ERROR);
            return vr;
        }
        // valid characters 0-9 a-z and -
        if (!StringUtils.isAlphanumeric(cnt.replaceAll("-", ""))) {
            ValidationResult vr = new ValidationResult();
            vr.setMessage(messages.getMessage("error.IncorrectName")); //$NON-NLS-1$
            vr.setStatus(ValidationResult.Result.ERROR);
            return vr;
        }
        // all lowercase
        if (!StringUtils.isAllLowerCase(cnt.replaceAll("(-|\\d)", ""))) {
            ValidationResult vr = new ValidationResult();
            vr.setMessage(messages.getMessage("error.UppercaseName")); //$NON-NLS-1$
            vr.setStatus(ValidationResult.Result.ERROR);
            return vr;
        }
        // length range : 3-63
        int cntl = cnt.length();
        if ((cntl < 3) || (cntl > 63)) {
            ValidationResult vr = new ValidationResult();
            vr.setMessage(messages.getMessage("error.LengthError")); //$NON-NLS-1$
            vr.setStatus(ValidationResult.Result.ERROR);
            return vr;
        }
    }
    // Operations on CloudBlob(s)
    if (this.properties instanceof AzureStorageBlobProperties) {
        // Put operation has different properties
        if (this.properties instanceof TAzureStoragePutProperties) {
            TAzureStoragePutProperties p = (TAzureStoragePutProperties) this.properties;
            String folder = p.localFolder.getValue();
            // checks local folder
            if (!new File(folder).exists()) {
                ValidationResult vr = new ValidationResult();
                vr.setMessage(messages.getMessage("error.EmptyLocalFolder")); //$NON-NLS-1$
                vr.setStatus(ValidationResult.Result.ERROR);
                return vr;
            }
            // checks file list if set.
            if (p.useFileList.getValue() && p.files.fileMask.getValue().size() == 0) {
                ValidationResult vr = new ValidationResult();
                vr.setMessage(messages.getMessage("error.EmptyFileList")); //$NON-NLS-1$
                vr.setStatus(ValidationResult.Result.ERROR);
                return vr;
            }
            // everything is OK.
            return ValidationResult.OK;
        }
        // Get operation needs some additional properties
        if (this.properties instanceof TAzureStorageGetProperties) {
            //
            if (((TAzureStorageGetProperties) this.properties).remoteBlobsGet.prefix.getValue().size() == 0) {
                ValidationResult vr = new ValidationResult();
                vr.setMessage(messages.getMessage("error.EmptyBlobs")); //$NON-NLS-1$
                vr.setStatus(ValidationResult.Result.ERROR);
                return vr;
            }
            String folder = ((TAzureStorageGetProperties) this.properties).localFolder.getValue();
            if (!new File(folder).exists()) {
                ValidationResult vr = new ValidationResult();
                vr.setMessage(messages.getMessage("error.NonentityLocal")); //$NON-NLS-1$
                vr.setStatus(ValidationResult.Result.ERROR);
                return vr;
            }
            // everything is OK.
            return ValidationResult.OK;
        }
        // We need at least one blob filter
        if (((AzureStorageBlobProperties) this.properties).remoteBlobs.prefix.getValue().size() == 0) {
            ValidationResult vr = new ValidationResult();
            vr.setMessage(messages.getMessage("error.EmptyBlobs")); //$NON-NLS-1$
            vr.setStatus(ValidationResult.Result.ERROR);
            return vr;
        }
    }
    return ValidationResult.OK;
}

From source file:org.trnltk.model.morpheme.MorphemeContainer.java

private ImmutableSet<PhoneticAttribute> findPhoneticAttributes() {
    // if there are no transitions or no non-blank transitions or only non-alphanumeric transitions
    // ...then use the phonetic attributes of the root (no need to calculate them using LexemeAttributes and root sequence)
    // otherwise, calculate the phonetic attributes from the sequence built so far and the lexeme attributes of the container
    if (this.hasTransitions()) {
        final String suffixSoFar = this.surfaceSoFar.substring(this.root.getSequence().length());
        if (StringUtils.isBlank(suffixSoFar) || !StringUtils.isAlphanumeric(suffixSoFar))
            return Sets.immutableEnumSet(this.root.getPhoneticAttributes());
        else/*from   ww  w.  j a  va2 s.  co  m*/
            return Sets.immutableEnumSet(phoneticsAnalyzer.calculatePhoneticAttributes(this.getSurfaceSoFar(),
                    this.getLexemeAttributes()));
    } else {
        return Sets.immutableEnumSet(root.getPhoneticAttributes());
    }
}