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:MainClass.java

public static void main(String[] args) {
    //Check if string contains only a specified set of characters. Return boolean
    System.out.println("4) Check if 643287460 contains only 0123456789 >>>"
            + StringUtils.containsOnly("643287460", "0123456789"));

}

From source file:StringUtilsTrial.java

public static void main(String[] args) {

    // Check if string contains only a specified set of characters. Return
    // boolean//from  w  ww. j a va2s  .  com
    System.out.println("4) Check if 643287460 contains only 0123456789 >>>"
            + StringUtils.containsOnly("643287460", "0123456789"));

}

From source file:com.rslakra.java.string.TestApacheStringUtils.java

public static void main(String args[]) {

    System.err.println(StringUtils.abbreviate("Take time off working", 0, 10));
    System.err.println(StringUtils.capitalize("vanderLust"));
    System.err.println(StringUtils.center("MTV", 7, '='));
    System.err.println(StringUtils.chomp("temperature", "ure"));
    System.err.println(StringUtils.chop("Dane"));
    System.err.println(StringUtils.contains("Dorothy", "oro"));
    System.err.println(StringUtils.containsNone("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.containsOnly("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.countMatches("arthur", "r"));
    System.err.println(StringUtils.deleteWhitespace("f f f f"));
    System.err.println(StringUtils.difference("govern", "government"));
    System.err.println(StringUtils.getLevenshteinDistance("govern", "government"));

}

From source file:com.acc.storefront.web.wrappers.UrlEncodeHttpRequestWrapper.java

@Override
public String getRequestURI() {
    final String originalRequestURI = super.getRequestURI();
    final String tempRequestURI = StringUtils.remove(originalRequestURI, super.getContextPath());

    if (StringUtils.isEmpty(tempRequestURI) || StringUtils.containsOnly(tempRequestURI, "/")) {
        return "/";
    }//  w w w . j av  a2 s.c o m
    return originalRequestURI;
}

From source file:com.redhat.rhn.common.security.SessionSwap.java

/** given an array of strings, compute the hex session swap, which
 * contains both the original data and the 'signature'.  so the
 * resulting string is encapsulated and can be passed around as
 * 'signed' data.// www  . ja v  a2 s  . c  o  m
 *
 * @param in an array of strings, all of which must be valud hex
 * @return String of the signature, in the form "D1:D2:D3xHEX"
 *         where D1... are the input data and HEX is the hex signature.
 */
public static String encodeData(String[] in) {
    for (int i = 0; i < in.length; i++) {
        if (!StringUtils.containsOnly(in[i], HEX_CHARS)) {
            throw new IllegalArgumentException(
                    "encodeData input must be " + "lowercase hex, but wasn't: " + in[i]);
        }
    }

    String joined = StringUtils.join(in, ':');

    String[] components = new String[] { joined, generateSwapKey(joined) };

    return StringUtils.join(components, "x");
}

From source file:com.opengamma.elsql.OffsetFetchSqlFragment.java

@Override
protected void toSQL(StringBuilder buf, ElSqlBundle bundle, SqlParameterSource paramSource) {
    int offset = 0;
    int fetchLimit = 0;
    if (_offsetVariable != null && paramSource.hasValue(_offsetVariable)) {
        offset = ((Number) paramSource.getValue(_offsetVariable)).intValue();
    }/*from  w  w  w.  j a  v  a  2 s.c o m*/
    if (paramSource.hasValue(_fetchVariable)) {
        fetchLimit = ((Number) paramSource.getValue(_fetchVariable)).intValue();
    } else if (StringUtils.containsOnly(_fetchVariable, "0123456789")) {
        fetchLimit = Integer.parseInt(_fetchVariable);
    }
    buf.append(bundle.getConfig().getPaging(offset, fetchLimit == Integer.MAX_VALUE ? 0 : fetchLimit));
}

From source file:net.mindengine.oculus.frontend.service.admin.user.UserCreateValidator.java

License:asdf

@Override
public void validate(Object object, Errors errors) {
    User user = (User) object;//w  w w .  ja v  a  2  s  .  c  om
    if (user != null) {
        if (user.getName() == null || "".equals(user.getName()))
            errors.reject(null, "Name shouldn't be empty");

        if (user.getLogin() == null || "".equals(user.getLogin()))
            errors.reject(null, "Login shouldn't be empty");

        if (user.getLogin() != null) {
            if (!StringUtils.containsOnly(user.getLogin(), "qwertyuiopasdfghjklzxcvbnm1234567890")) {
                errors.reject(null, "Login should contain only lowercase symbols");
            }
        }

        if (user.getEmail() == null || "".equals(user.getEmail()))
            errors.reject(null, "Email shouldn't be empty");
    } else
        errors.reject(null, "Input users data");

}

From source file:com.opengamma.elsql.PagingSqlFragment.java

/**
 * Applies the paging./*from  w ww .  j  a  va 2 s . com*/
 * 
 * @param selectToPage  the contents of the enclosed block, not null
 * @param bundle  the elsql bundle for context, not null
 * @param paramSource  the SQL parameters, not null
 */
protected String applyPaging(String selectToPage, ElSqlBundle bundle, SqlParameterSource paramSource) {
    int offset = 0;
    int fetchLimit = 0;
    if (_offsetVariable != null && paramSource.hasValue(_offsetVariable)) {
        offset = ((Number) paramSource.getValue(_offsetVariable)).intValue();
    }
    if (paramSource.hasValue(_fetchVariable)) {
        fetchLimit = ((Number) paramSource.getValue(_fetchVariable)).intValue();
    } else if (StringUtils.containsOnly(_fetchVariable, "0123456789")) {
        fetchLimit = Integer.parseInt(_fetchVariable);
    }
    return bundle.getConfig().addPaging(selectToPage, offset, fetchLimit == Integer.MAX_VALUE ? 0 : fetchLimit);
}

From source file:com.autentia.wuija.util.web.jsf.NumberAsBigDecimalConverter.java

@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value)
        throws ConverterException {
    super.setPattern(getPattern(uiComponent));

    Object object = super.getAsObject(facesContext, uiComponent, value);
    if (object == null) {
        return object;
    }//  w w w  .ja v  a2  s  . c  om

    if (value == null) {
        return null;
    }

    if (!StringUtils.containsOnly(value, "0123456789.,-+")) {
        throw new ConverterException(value);
    }

    if (!checkIfIsCorrectDecimal(value)) {
        JsfUtils.addMessage(uiComponent.getClientId(facesContext), FacesMessage.SEVERITY_ERROR,
                "javax.faces.converter.BigDecimalConverter.DECIMAL", value);
        throw new ConverterException(value);
    }

    if (value.contains(",")) {
        final String decimalValue = value.substring(value.indexOf(',') + 1);
        String integerValue;
        try {
            integerValue = value.substring(0, value.indexOf(','));
            integerValue = integerValue.replace(".", "");
            return new BigDecimal(integerValue.concat(".").concat(decimalValue));
        } catch (NumberFormatException e) {
            throw new ConverterException(value);
        }
    }
    return new BigDecimal(value.replace(".", ""));
}

From source file:net.bible.service.format.osistohtml.taghandler.NoteHandler.java

@Override
public void end() {
    String noteText = writer.getTempStoreString();
    if (noteText.length() > 0) {
        if (!StringUtils.containsOnly(noteText, "[];()., ")) {
            Note note = new Note(verseInfo.currentVerseNo, currentNoteRef, noteText, NoteType.TYPE_GENERAL,
                    null, null);/*from ww w.  j a  v a  2  s.  c  om*/
            notesList.add(note);
        }
        // and clear the buffer
        writer.clearTempStore();
    }
    isInNote = false;
    writer.finishWritingToTempStore();
}