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

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

Introduction

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

Prototype

public static String lowerCase(String str) 

Source Link

Document

Converts a String to lower case as per String#toLowerCase() .

Usage

From source file:org.apache.usergrid.persistence.cassandra.ConnectionRefImpl.java

public static UUID getIndexId(EntityRef connectingEntity, String connectionType, String connectedEntityType,
        ConnectedEntityRef... pairedConnections) {

    UUID uuid = null;/*from  www . ja v a  2  s.c  om*/
    try {

        if (connectionsNull(pairedConnections) && ((connectionType == null) && (connectedEntityType == null))) {
            return connectingEntity.getUuid();
        }

        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(16 + (32 * pairedConnections.length));

        byteStream.write(uuidToBytesNullOk(connectingEntity.getUuid()));

        for (ConnectedEntityRef connection : pairedConnections) {
            String type = connection.getConnectionType();
            UUID id = connection.getUuid();

            byteStream.write(ascii(StringUtils.lowerCase(type)));
            byteStream.write(uuidToBytesNullOk(id));
        }

        if (connectionType == null) {
            connectionType = NULL_ENTITY_TYPE;
        }
        if (connectedEntityType == null) {
            connectedEntityType = NULL_ENTITY_TYPE;
        }

        byteStream.write(ascii(StringUtils.lowerCase(connectionType)));
        byteStream.write(ascii(StringUtils.lowerCase(connectedEntityType)));

        byte[] raw_id = byteStream.toByteArray();

        logger.info("raw connection index id: " + Hex.encodeHexString(raw_id));

        uuid = UUID.nameUUIDFromBytes(raw_id);

        logger.info("connection index uuid: " + uuid);
    } catch (IOException e) {
        logger.error("Unable to create connection index UUID", e);
    }
    return uuid;
}

From source file:org.apache.wiki.auth.user.DefaultUserProfile.java

/**
 * {@inheritDoc}//from   ww  w. j  av  a2  s.  c  om
 */
public boolean equals(Object o) {
    if ((o != null) && (o instanceof UserProfile)) {
        DefaultUserProfile u = (DefaultUserProfile) o;
        return same(fullname, u.fullname) && same(password, u.password) && same(loginName, u.loginName)
                && same(StringUtils.lowerCase(email), StringUtils.lowerCase(u.email))
                && same(wikiname, u.wikiname);
    }

    return false;
}

From source file:org.apache.wiki.auth.user.DefaultUserProfile.java

public int hashCode() {
    return (fullname != null ? fullname.hashCode() : 0) ^ (password != null ? password.hashCode() : 0)
            ^ (loginName != null ? loginName.hashCode() : 0) ^ (wikiname != null ? wikiname.hashCode() : 0)
            ^ (email != null ? StringUtils.lowerCase(email).hashCode() : 0);
}

From source file:org.apache.wiki.auth.user.XMLUserDatabase.java

/**
 * Private method that returns the first {@link UserProfile}matching a
 * <user> element's supplied attribute. This method will also
 * set the UID if it has not yet been set.
 * @param matchAttribute/*from ww  w . ja  v  a  2  s.  co m*/
 * @param index
 * @return the profile, or <code>null</code> if not found
 */
private UserProfile findByAttribute(String matchAttribute, String index) {
    if (c_dom == null) {
        throw new IllegalStateException("FATAL: database does not exist");
    }

    checkForRefresh();

    NodeList users = c_dom.getElementsByTagName(USER_TAG);

    if (users == null)
        return null;

    // check if we have to do a case insensitive compare
    boolean caseSensitiveCompare = true;
    if (matchAttribute.equals(EMAIL)) {
        caseSensitiveCompare = false;
    }

    for (int i = 0; i < users.getLength(); i++) {
        Element user = (Element) users.item(i);
        String userAttribute = user.getAttribute(matchAttribute);
        if (!caseSensitiveCompare) {
            userAttribute = StringUtils.lowerCase(userAttribute);
            index = StringUtils.lowerCase(index);
        }
        if (userAttribute.equals(index)) {
            UserProfile profile = newProfile();

            // Parse basic attributes
            profile.setUid(user.getAttribute(UID));
            if (profile.getUid() == null || profile.getUid().length() == 0) {
                profile.setUid(generateUid(this));
            }
            profile.setLoginName(user.getAttribute(LOGIN_NAME));
            profile.setFullname(user.getAttribute(FULL_NAME));
            profile.setPassword(user.getAttribute(PASSWORD));
            profile.setEmail(user.getAttribute(EMAIL));

            // Get created/modified timestamps
            String created = user.getAttribute(CREATED);
            String modified = user.getAttribute(LAST_MODIFIED);
            profile.setCreated(parseDate(profile, created));
            profile.setLastModified(parseDate(profile, modified));

            // Is the profile locked?
            String lockExpiry = user.getAttribute(LOCK_EXPIRY);
            if (lockExpiry == null || lockExpiry.length() == 0) {
                profile.setLockExpiry(null);
            } else {
                profile.setLockExpiry(new Date(Long.parseLong(lockExpiry)));
            }

            // Extract all of the user's attributes (should only be one attributes tag, but you never know!)
            NodeList attributes = user.getElementsByTagName(ATTRIBUTES_TAG);
            for (int j = 0; j < attributes.getLength(); j++) {
                Element attribute = (Element) attributes.item(j);
                String serializedMap = extractText(attribute);
                try {
                    Map<String, ? extends Serializable> map = Serializer.deserializeFromBase64(serializedMap);
                    profile.getAttributes().putAll(map);
                } catch (IOException e) {
                    log.error("Could not parse user profile attributes!", e);
                }
            }

            return profile;
        }
    }
    return null;
}

From source file:org.apache.wiki.auth.UserManager.java

/**
 * Validates a user profile, and appends any errors to the session errors
 * list. If the profile is new, the password will be checked to make sure it
 * isn't null. Otherwise, the password is checked for length and that it
 * matches the value of the 'password2' HTTP parameter. Note that we have a
 * special case when container-managed authentication is used and the user
 * is not authenticated; this will always cause validation to fail. Any
 * validation errors are added to the wiki session's messages collection
 * (see {@link WikiSession#getMessages()}.
 * @param context the current wiki context
 * @param profile the supplied UserProfile
 *///  w  w w  .j a  v  a  2  s . c om
public void validateProfile(WikiContext context, UserProfile profile) {
    boolean isNew = profile.isNew();
    WikiSession session = context.getWikiSession();
    InputValidator validator = new InputValidator(SESSION_MESSAGES, context);
    ResourceBundle rb = Preferences.getBundle(context, InternationalizationManager.CORE_BUNDLE);

    //
    //  Query the SpamFilter first
    //
    FilterManager fm = m_engine.getFilterManager();
    List<PageFilter> ls = fm.getFilterList();
    for (PageFilter pf : ls) {
        if (pf instanceof SpamFilter) {
            if (((SpamFilter) pf).isValidUserProfile(context, profile) == false) {
                session.addMessage(SESSION_MESSAGES, "Invalid userprofile");
                return;
            }
            break;
        }
    }

    // If container-managed auth and user not logged in, throw an error
    if (m_engine.getAuthenticationManager().isContainerAuthenticated()
            && !context.getWikiSession().isAuthenticated()) {
        session.addMessage(SESSION_MESSAGES, rb.getString("security.error.createprofilebeforelogin"));
    }

    validator.validateNotNull(profile.getLoginName(), rb.getString("security.user.loginname"));
    validator.validateNotNull(profile.getFullname(), rb.getString("security.user.fullname"));
    validator.validate(profile.getEmail(), rb.getString("security.user.email"), InputValidator.EMAIL);

    // If new profile, passwords must match and can't be null
    if (!m_engine.getAuthenticationManager().isContainerAuthenticated()) {
        String password = profile.getPassword();
        if (password == null) {
            if (isNew) {
                session.addMessage(SESSION_MESSAGES, rb.getString("security.error.blankpassword"));
            }
        } else {
            HttpServletRequest request = context.getHttpRequest();
            String password2 = (request == null) ? null : request.getParameter("password2");
            if (!password.equals(password2)) {
                session.addMessage(SESSION_MESSAGES, rb.getString("security.error.passwordnomatch"));
            }
        }
    }

    UserProfile otherProfile;
    String fullName = profile.getFullname();
    String loginName = profile.getLoginName();
    String email = profile.getEmail();

    // It's illegal to use as a full name someone else's login name
    try {
        otherProfile = getUserDatabase().find(fullName);
        if (otherProfile != null && !profile.equals(otherProfile)
                && !fullName.equals(otherProfile.getFullname())) {
            Object[] args = { fullName };
            session.addMessage(SESSION_MESSAGES,
                    MessageFormat.format(rb.getString("security.error.illegalfullname"), args));
        }
    } catch (NoSuchPrincipalException e) {
        /* It's clean */ }

    // It's illegal to use as a login name someone else's full name
    try {
        otherProfile = getUserDatabase().find(loginName);
        if (otherProfile != null && !profile.equals(otherProfile)
                && !loginName.equals(otherProfile.getLoginName())) {
            Object[] args = { loginName };
            session.addMessage(SESSION_MESSAGES,
                    MessageFormat.format(rb.getString("security.error.illegalloginname"), args));
        }
    } catch (NoSuchPrincipalException e) {
        /* It's clean */ }

    // It's illegal to use multiple accounts with the same email
    try {
        otherProfile = getUserDatabase().findByEmail(email);
        if (otherProfile != null && !profile.equals(otherProfile)
                && StringUtils.lowerCase(email).equals(StringUtils.lowerCase(otherProfile.getEmail()))) {
            Object[] args = { email };
            session.addMessage(SESSION_MESSAGES,
                    MessageFormat.format(rb.getString("security.error.email.taken"), args));
        }
    } catch (NoSuchPrincipalException e) {
        /* It's clean */ }
}

From source file:org.bubuabu.sonar.fortifysca.FortifyScaConstants.java

public static String fortifyScaRepositoryKey(String language) {
    return "fortifysca-" + StringUtils.lowerCase(language);
}

From source file:org.codehaus.redback.rest.services.DefaultUtilServices.java

public String getI18nResources(String locale) throws RedbackServiceException {
    String cachedi18n = cachei18n.get(StringUtils.isEmpty(locale) ? "en" : StringUtils.lowerCase(locale));
    if (cachedi18n != null) {
        return cachedi18n;
    }//from  w w  w. j av  a 2  s . c om

    Properties properties = new Properties();

    // load redback user api messages
    try {

        // load default first then requested locale
        loadResource(properties, "org/codehaus/plexus/redback/users/messages", null);
        loadResource(properties, "org/codehaus/plexus/redback/users/messages", locale);

    } catch (IOException e) {
        log.warn("skip error loading properties {}", "org/codehaus/plexus/redback/users/messages");
    }

    try {

        // load default first then requested locale
        loadResource(properties, "org/codehaus/redback/i18n/default", null);
        loadResource(properties, "org/codehaus/redback/i18n/default", locale);

    } catch (IOException e) {
        log.warn("skip error loading properties {}", "org/codehaus/redback/i18n/default");
    }

    StringBuilder output = new StringBuilder();

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        output.append((String) entry.getKey()).append('=').append((String) entry.getValue());
        output.append('\n');
    }

    cachei18n.put(StringUtils.isEmpty(locale) ? "en" : StringUtils.lowerCase(locale), output.toString());

    return output.toString();
}

From source file:org.codice.ddf.configuration.migration.PathUtils.java

/**
 * Quietly deletes the specified file or recursively deletes the specified directory and audit the
 * result. The provided directory is deleted.
 *
 * @param path the file or directory to be deleted
 * @param type a string representing the type of file or directory to delete
 * @return <code>true</code> if the file or directory was deleted, <code>false</code> otherwise
 * @throws IllegalArgumentException if <code>path</code> or <code>type</code> is <code>null</code>
 *//* ww  w . j  a va2s.  com*/
public static boolean deleteQuietly(Path path, String type) {
    Validate.notNull(path, PathUtils.INVALID_NULL_PATH);
    Validate.notNull(type, "invalid null type");
    final File file = path.toFile();

    if (FileUtils.deleteQuietly(file)) {
        SecurityLogger.audit("{} file {} deleted", StringUtils.capitalize(type), file);
        return true;
    }
    SecurityLogger.audit("Failed to delete {} file {}", StringUtils.lowerCase(type), file);
    return false;
}

From source file:org.displaytag.filter.BufferedResponseWrapper12Impl.java

/**
 * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String, java.lang.String)
 *///from   ww w .j  av a  2 s . c  o m
public void addHeader(String name, String value) {
    // if the "magic parameter" is set, a table tag is going to call getOutputStream()
    if (TableTagParameters.PARAMETER_EXPORTING.equals(name)) {
        log.debug("Magic header received, real response is now accessible");
        state = true;
    } else {
        if (!ArrayUtils.contains(FILTERED_HEADERS, StringUtils.lowerCase(name))) {
            ((HttpServletResponse) getResponse()).addHeader(name, value);
        }
    }
}

From source file:org.displaytag.filter.BufferedResponseWrapper12Impl.java

/**
 * @see javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String, long)
 *///from  ww w  .ja  va  2s .  c om
public void setDateHeader(String name, long date) {
    if (!ArrayUtils.contains(FILTERED_HEADERS, StringUtils.lowerCase(name))) {
        response.setDateHeader(name, date);
    }
}