List of usage examples for org.apache.commons.lang CharUtils isAsciiNumeric
public static boolean isAsciiNumeric(char ch)
Checks whether the character is ASCII 7 bit numeric.
From source file:gov.nih.nci.protexpress.ui.interceptors.DisplayTagParametersInterceptor.java
/** * determines if the given param is a display tag param. * * @param parameterName the name of the param * @return true if the param is a display tag param *///w ww. j av a 2 s. c o m public static boolean isDisplayTagParam(String parameterName) { boolean retVal = false; if (parameterName != null && parameterName.startsWith(DISPLAY_TAG_PARAM_PREFIX) && parameterName.length() > DISPLAY_TAG_PARAM_FIRST_NUMBER_INDEX && CharUtils.isAsciiNumeric(parameterName.charAt(DISPLAY_TAG_PARAM_FIRST_NUMBER_INDEX))) { retVal = true; } return retVal; }
From source file:com.zb.jcseg.util.WordUnionUtils.java
public static boolean isEndWithDigital(String str, String c) { if (StringUtils.isEmpty(str)) { return false; }/* w w w . j av a 2 s. c o m*/ return CharUtils.isAsciiNumeric(str.charAt(str.length() - 1)) && unitSet.contains(c); }
From source file:org.cesecore.util.CertTools.java
/** * Gets a serial number in numeric form, it takes - either a hex encoded integer with length != 5 (x.509 certificate) - 5 letter numeric string * (cvc), will convert the number to an int - 5 letter alfanumeric string vi some numbers in it (cvc), will convert the numbers in it to a numeric * string (remove the letters) and convert to int - 5 letter alfanumeric string with only letters (cvc), will convert to integer from string with * radix 36/*from www .ja v a 2s .c o m*/ * * @param sernoString * @return BigInteger */ public static BigInteger getSerialNumberFromString(String sernoString) { if (sernoString == null) { throw new IllegalArgumentException("getSerialNumberFromString: cert is null"); } BigInteger ret; if (sernoString.length() != 5) { // This can not be a CVC certificate sequence, so it must be a hex encoded regular certificate serial number ret = new BigInteger(sernoString, 16); } else { // We try to handle the different cases of CVC certificate sequences, see StringTools.KEY_SEQUENCE_FORMAT try { if (NumberUtils.isNumber(sernoString)) { ret = NumberUtils.createBigInteger(sernoString); } else { // check if input is hexadecimal log.info( "getSerialNumber: Sequence is not a numeric string, trying to extract numerical sequence part."); StringBuilder buf = new StringBuilder(); for (int i = 0; i < sernoString.length(); i++) { char c = sernoString.charAt(i); if (CharUtils.isAsciiNumeric(c)) { buf.append(c); } } if (buf.length() > 0) { ret = NumberUtils.createBigInteger(buf.toString()); } else { log.info( "getSerialNumber: can not extract numeric sequence part, trying alfanumeric value (radix 36)."); if (sernoString.matches("[0-9A-Z]{1,5}")) { int numSeq = Integer.parseInt(sernoString, 36); ret = BigInteger.valueOf(numSeq); } else { log.info("getSerialNumber: Sequence does not contain any numeric parts, returning 0."); ret = BigInteger.valueOf(0); } } } } catch (NumberFormatException e) { // If we can't make the sequence into a serial number big integer, set it to 0 log.debug("getSerialNumber: NumberFormatException for sequence: " + sernoString); ret = BigInteger.valueOf(0); } } return ret; }
From source file:org.cesecore.util.StringTools.java
public static String incrementKeySequence(final int keySequenceFormat, final String oldSequence) { if (log.isTraceEnabled()) { log.trace(">incrementKeySequence: " + keySequenceFormat + ", " + oldSequence); }// ww w .java 2 s . c o m // If the sequence does not contain any number in it at all, we can only return the same String ret = null; // If the sequence starts with a country code we will increment the remaining characters leaving // the first two untouched. Per character 10 [0-9] or 36 [0-9A-Z] different values // can be coded if (keySequenceFormat == KEY_SEQUENCE_FORMAT_NUMERIC) { ret = incrementNumeric(oldSequence); } else if (keySequenceFormat == KEY_SEQUENCE_FORMAT_ALPHANUMERIC) { ret = incrementAlphaNumeric(oldSequence); } else if (keySequenceFormat == KEY_SEQUENCE_FORMAT_COUNTRY_CODE_PLUS_NUMERIC) { final String countryCode = oldSequence.substring(0, Math.min(2, oldSequence.length())); if (log.isDebugEnabled()) { log.debug("countryCode: " + countryCode); } final String inc = incrementNumeric(oldSequence.substring(2)); // Cut off the country code if (oldSequence.length() > 2 && inc != null) { ret = countryCode + inc; } } else if (keySequenceFormat == KEY_SEQUENCE_FORMAT_COUNTRY_CODE_PLUS_ALPHANUMERIC) { final String countryCode = oldSequence.substring(0, Math.min(2, oldSequence.length())); if (log.isDebugEnabled()) { log.debug("countryCode: " + countryCode); } final String inc = incrementAlphaNumeric(oldSequence.substring(2)); // Cut off the country code if (oldSequence.length() > 2 && inc != null) { ret = countryCode + inc; } } // unknown, fall back to old implementation if (ret == null) { ret = oldSequence; // A sequence can be 00001, or SE001 for example // Here we will strip any sequence number at the end of the key label and add the new sequence there // We will only count decimal (0-9) to ensure that we will not accidentally update the first to // characters to the provided country code final StringBuilder buf = new StringBuilder(); for (int i = oldSequence.length() - 1; i >= 0; i--) { final char c = oldSequence.charAt(i); if (CharUtils.isAsciiNumeric(c)) { buf.insert(0, c); } else { break; // at first non numeric character we break } } final int restlen = oldSequence.length() - buf.length(); final String rest = oldSequence.substring(0, restlen); final String intStr = buf.toString(); if (StringUtils.isNotEmpty(intStr)) { Integer seq = Integer.valueOf(intStr); seq = seq + 1; // We want this to be the same number of numbers as we converted and incremented final DecimalFormat df = new DecimalFormat("0000000000".substring(0, intStr.length())); final String fseq = df.format(seq); ret = rest + fseq; if (log.isTraceEnabled()) { log.trace("<incrementKeySequence: " + ret); } } else { log.info("incrementKeySequence - Sequence does not contain any nummeric part: " + ret); } } return ret; }
From source file:org.ejbca.util.CertTools.java
/** Gets a serial number in numeric form, it takes * - either a hex encoded integer with length != 5 (x.509 certificate) * - 5 letter numeric string (cvc), will convert the number to an int * - 5 letter alfanumeric string vi some numbers in it (cvc), will convert the numbers in it to a numeric string (remove the letters) and convert to int * - 5 letter alfanumeric string with only letters (cvc), will convert to integer from string with radix 36 * /*from w w w. j a v a2s . c o m*/ * @param sernoString * @return BigInteger */ public static BigInteger getSerialNumberFromString(String sernoString) { BigInteger ret; if (sernoString.length() != 5) { // This can not be a CVC certificate sequence, so it must be a hex encoded regular certificate serial number ret = new BigInteger(sernoString, 16); } else { // We try to handle the different cases of CVC certificate sequences, see StringTools.KEY_SEQUENCE_FORMAT try { if (NumberUtils.isNumber(sernoString)) { ret = NumberUtils.createBigInteger(sernoString); } else { // check if input is hexadecimal log.info( "getSerialNumber: Sequence is not a numeric string, trying to extract numerical sequence part."); final StringBuilder buf = new StringBuilder(); for (int i = 0; i < sernoString.length(); i++) { char c = sernoString.charAt(i); if (CharUtils.isAsciiNumeric(c)) { buf.append(c); } } if (buf.length() > 0) { ret = NumberUtils.createBigInteger(buf.toString()); } else { log.info( "getSerialNumber: can not extract numeric sequence part, trying alfanumeric value (radix 36)."); if (sernoString.matches("[0-9A-Z]{1,5}")) { int numSeq = Integer.parseInt(sernoString, 36); ret = BigInteger.valueOf(numSeq); } else { log.info("getSerialNumber: Sequence does not contain any numeric parts, returning 0."); ret = BigInteger.valueOf(0); } } } } catch (NumberFormatException e) { // If we can't make the sequence into a serial number big integer, set it to 0 log.debug("getSerialNumber: NumberFormatException for sequence: " + sernoString); ret = BigInteger.valueOf(0); } } return ret; }
From source file:org.ejbca.util.StringTools.java
public static String incrementKeySequence(final int keySequenceFormat, final String oldSequence) { if (log.isTraceEnabled()) { log.trace(">incrementKeySequence: " + keySequenceFormat + ", " + oldSequence); }/* ww w.ja v a2s . com*/ // If the sequence does not contain any number in it at all, we can only return the same String ret = null; // If the sequence starts with a country code we will increment the remaining characters leaving // the first two untouched. Per character 10 [0-9] or 36 [0-9A-Z] different values // can be coded if (keySequenceFormat == KEY_SEQUENCE_FORMAT_NUMERIC) { ret = incrementNumeric(oldSequence); } else if (keySequenceFormat == KEY_SEQUENCE_FORMAT_ALPHANUMERIC) { ret = incrementAlphaNumeric(oldSequence); } else if (keySequenceFormat == KEY_SEQUENCE_FORMAT_COUNTRY_CODE_PLUS_NUMERIC) { final String countryCode = oldSequence.substring(0, Math.min(2, oldSequence.length())); if (log.isDebugEnabled()) { log.debug("countryCode: " + countryCode); } final String inc = incrementNumeric(oldSequence.substring(2)); // Cut off the country code if (oldSequence.length() > 2 && inc != null) { ret = countryCode + inc; } } else if (keySequenceFormat == KEY_SEQUENCE_FORMAT_COUNTRY_CODE_PLUS_ALPHANUMERIC) { final String countryCode = oldSequence.substring(0, Math.min(2, oldSequence.length())); log.debug("countryCode: " + countryCode); final String inc = incrementAlphaNumeric(oldSequence.substring(2)); // Cut off the country code if (oldSequence.length() > 2 && inc != null) { ret = countryCode + inc; } } // unknown, fall back to old implementation if (ret == null) { ret = oldSequence; // A sequence can be 00001, or SE001 for example // Here we will strip any sequence number at the end of the key label and add the new sequence there // We will only count decimal (0-9) to ensure that we will not accidentally update the first to // characters to the provided country code final StringBuilder buf = new StringBuilder(); for (int i = oldSequence.length() - 1; i >= 0; i--) { final char c = oldSequence.charAt(i); if (CharUtils.isAsciiNumeric(c)) { buf.insert(0, c); } else { break; // at first non numeric character we break } } final int restlen = oldSequence.length() - buf.length(); final String rest = oldSequence.substring(0, restlen); final String intStr = buf.toString(); if (StringUtils.isNotEmpty(intStr)) { Integer seq = Integer.valueOf(intStr); seq = seq + 1; // We want this to be the same number of numbers as we converted and incremented final DecimalFormat df = new DecimalFormat("0000000000".substring(0, intStr.length())); final String fseq = df.format(seq); ret = rest + fseq; if (log.isTraceEnabled()) { log.trace("<incrementKeySequence: " + ret); } } else { log.info("incrementKeySequence - Sequence does not contain any nummeric part: " + ret); } } return ret; }
From source file:org.intermine.sql.DatabaseUtil.java
/** * Check that a column name provided to us is a legal column name, to prevent SQL injection. * @param name The desired column name./*from w ww.ja v a2s . c o m*/ * @return Whether or not we should accept it. */ protected static boolean isLegalColumnName(String name) { if (StringUtils.isEmpty(name)) { return false; } boolean isValid = true; for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); isValid = isValid && (CharUtils.isAsciiAlphaLower(c) || CharUtils.isAsciiNumeric(c) || c == '_'); } return isValid; }
From source file:org.richfaces.tests.metamer.model.treeAdaptor.KeyConverter.java
public Object getAsObject(FacesContext context, UIComponent component, String value) { List<RecursiveNode> list = RichTreeModelRecursiveAdaptorBean.getRootNodesStatically(); RecursiveNode recursive = null;//from w ww. j av a 2 s . c om ModelNode model = null; char alpha = ' '; for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); if (CharUtils.isAsciiAlpha(ch)) { alpha = ch; switch (alpha) { case 'M': model = recursive.getModel(); break; default: } } if (CharUtils.isAsciiNumeric(ch)) { int num = CharUtils.toIntValue(ch); switch (alpha) { case 'R': recursive = list.get(num); list = recursive.getRecursiveList(); break; case 'K': for (ModelNodeImpl.K key : model.getMap().keySet()) { if (key.number == num) { return key; } } throw new IllegalStateException(); default: } } } if (Strings.isNullOrEmpty(value)) { return null; } return null; }