Example usage for org.apache.commons.lang3 EnumUtils getEnum

List of usage examples for org.apache.commons.lang3 EnumUtils getEnum

Introduction

In this page you can find the example usage for org.apache.commons.lang3 EnumUtils getEnum.

Prototype

public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final String enumName) 

Source Link

Document

Gets the enum for the class, returning null if not found.

This method differs from Enum#valueOf in that it does not throw an exception for an invalid enum name.

Usage

From source file:org.xwiki.localization.wiki.internal.DocumentTranslationBundleFactory.java

/**
 * @param obj the translation object//from   w  w w  .j  av a 2  s .  com
 * @return the {@link Scope} stored in the object, null not assigned or unknown
 */
private Scope getScope(BaseObject obj) {
    if (obj != null) {
        StringProperty scopeProperty = (StringProperty) obj
                .getField(TranslationDocumentModel.TRANSLATIONCLASS_PROP_SCOPE);

        if (scopeProperty != null) {
            String scopeString = scopeProperty.getValue();

            return EnumUtils.getEnum(Scope.class, scopeString.toUpperCase());
        }
    }

    return null;
}

From source file:org.xwiki.model.internal.reference.converter.EntityReferenceConverter.java

private EntityReference convertToType(Type type, String value) {
    Namespace namespace = NamespaceUtils.toNamespace(value);

    EntityType entityType = namespace.getType() != null
            ? EnumUtils.getEnum(EntityType.class, namespace.getType().toUpperCase())
            : null;//  w w  w  .  ja  va 2 s  . c o  m
    String entityReference = namespace.getValue();
    if (entityType == null) {
        entityType = EntityType.DOCUMENT;
        entityReference = value;
    }

    return this.stringResolver.resolve(entityReference, entityType);
}