List of usage examples for org.apache.commons.lang CharUtils isAsciiAlpha
public static boolean isAsciiAlpha(char ch)
Checks whether the character is ASCII 7 bit alphabetic.
From source file:com.infosupport.ellison.core.archive.ApplicationArchive.java
/** * Checks whether the path is relative.//from ww w . j av a 2 s. co m * <p/> * {@link java.io.File#isAbsolute()} is not very testable, as its behavior is dependent upon the environment in * which the application is run. * * @param path * the path to check * * @return false if:<ul> <li>the path starts with a slash ('/')</li> <li>the path starts with one backslash * ('\')</li> <li>the path contains a directory component consisting of only two dots ('/../')</li> <li>the * path starts with a windows drive letter ('C:\\')</li> </ul> */ private static boolean isPathRelative(String path) { boolean isNotRelative = false; File pathFile = new File(path); String absolutePath = pathFile.getAbsolutePath(); String canonicalPath = null; try { canonicalPath = pathFile.getCanonicalPath(); } catch (IOException e) { LOGGER.info(String.format("Error canonicalizing path '%s'", path), e); // Assume the path parameter is not canonical, meaning it might be unsafe. return false; } isNotRelative = path.startsWith("/"); isNotRelative = isNotRelative || path.startsWith("\\"); isNotRelative = isNotRelative || !canonicalPath.equals(absolutePath); isNotRelative = isNotRelative || (CharUtils.isAsciiAlpha(path.charAt(0)) && path.substring(1).startsWith(":\\")); return !isNotRelative; }
From source file:org.apache.openjpa.lib.identifier.IdentifierRule.java
/** * SQL identifier rules://from www. j a v a 2 s . co m * 1) Can be up to 128 characters long * 2) Must begin with a letter * 3) Can contain letters, digits, and underscores * 4) Can't contain spaces or special characters such as #, $, &, %, or * punctuation. * 5) Can't be reserved words */ public boolean requiresDelimiters(String identifier) { // Do not delimit single valued wildcards or "?" or names that have method-type // signatures (ex. getValue()). These are considered special values in OpenJPA // and should not be delimited. if (_wildcard.equals(identifier) || "?".equals(identifier) || identifier.endsWith("()")) { return false; } if (getMustDelimit()) { return true; } // Assert identifier begins with a letter char[] chars = identifier.toCharArray(); if (isMustBeginWithLetter()) { if (!CharUtils.isAsciiAlpha(chars[0])) { return true; } } // Iterate through chars, asserting delimiting rules for (char ch : chars) { if (isOnlyLettersDigitsUnderscores()) { if (!CharUtils.isAsciiAlphanumeric(ch) && !(ch == UNDERSCORE)) { return true; } } // Look for special characters if (StringUtils.contains(getSpecialCharacters(), ch)) { return true; } } // Finally, look for reserved words if (getDelimitReservedWords()) { if (isReservedWord(identifier)) { return true; } } return false; }
From source file:org.beangle.struts2.action.DispatchAction.java
protected String getTextInternal(String msgKey, Object... args) { if (null == msgKey) return null; if (CharUtils.isAsciiAlpha(msgKey.charAt(0)) && msgKey.indexOf('.') > 0) { if (args.length > 0) return getText(msgKey, Arrays.asList(args)); else// w w w. ja v a 2 s .c om return getText(msgKey); } else { return msgKey; } }
From source file:org.beangle.struts2.view.component.UIBean.java
protected String getText(String text, String defaultText) { if (StringUtils.isEmpty(text)) return defaultText; if (!CharUtils.isAsciiAlpha(text.charAt(0))) return defaultText; if (-1 == text.indexOf('.') || -1 < text.indexOf(' ')) { return defaultText; } else {/*from w ww.ja v a 2 s . co m*/ return TextProviderHelper.getText(text, defaultText, Collections.emptyList(), stack, false); } }
From source file:org.rapidcontext.core.data.XmlSerializer.java
/** * Writes an XML tag name.//from www . ja v a2 s . c om * * @param id the tag name (identifier) * @param buffer the string buffer to append into */ private static void tagName(String id, StringBuilder buffer) { for (int i = 0; i < id.length(); i++) { char c = id.charAt(i); if (i == 0 && !CharUtils.isAsciiAlpha(c)) { c = '_'; } else if (!CharUtils.isAsciiAlphanumeric(c)) { c = '_'; } buffer.append(c); } }
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 w w . ja v a 2 s. c o m*/ 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; }