List of usage examples for org.apache.commons.lang CharUtils isAsciiAlphanumeric
public static boolean isAsciiAlphanumeric(char ch)
Checks whether the character is ASCII 7 bit numeric.
From source file:com.hp.alm.ali.idea.translate.expr.Lexer.java
Lexeme next() { if (next == null) { while (pos < str.length() && Character.isWhitespace(str.charAt(pos))) { ++pos;/*from www . j a v a2 s . co m*/ } if (pos > str.length()) { throw new NoSuchElementException(); } if (pos == str.length()) { next = new Lexeme(pos, pos, "", Type.END); return next; } int startPos = pos; if (str.charAt(pos) == '\'' || str.charAt(pos) == '"') { int end = pos; do { ++end; } while (end < str.length() && str.charAt(end) != str.charAt(pos)); if (end == str.length() || str.charAt(end) != str.charAt(pos)) { throw new ParserException("Unterminated literal", pos); } pos = end + 1; next = new Lexeme(startPos, end, str.substring(startPos + 1, end), Type.VALUE); return next; } for (Type type : Type.values()) { if (type.getRepr() == null) { continue; } if (str.substring(pos).toUpperCase().startsWith(type.getRepr())) { int len = type.getRepr().length(); if (CharUtils.isAsciiAlphanumeric(type.getRepr().charAt(len - 1)) && str.length() > pos + len && CharUtils.isAsciiAlphanumeric(str.charAt(pos + len))) { // don't split words to match lexeme continue; } next = new Lexeme(startPos, startPos + len, str.substring(startPos, startPos + len), type); pos += len; return next; } } do { ++pos; } while (pos < str.length() && allowedInLiteral(str.charAt(pos))); next = new Lexeme(startPos, pos, str.substring(startPos, pos), Type.VALUE); } return next; }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.util.ManifestHelper.java
private static String normalize(final String key) { final int length = key.length(); final StringBuilder buffer = new StringBuilder(length); for (int i = 0; i < length; i++) { final char ch = key.charAt(i); if (CharUtils.isAsciiAlphanumeric(ch) || ch == '-' || ch == '_') { buffer.append(ch);//from w w w .jav a2 s .co m } else { buffer.append('_'); } } return buffer.toString(); }
From source file:istata.service.StataService.java
/** * produce a list with possible sidebar suggestions for the current context * //from w ww . j a v a2s . c o m * @param filter * @param pos * @param from * @param to * @return */ public List<ContentLine> suggest(String filter, int pos, int from, int to) { LinkedHashSet<ContentLine> res = new LinkedHashSet<ContentLine>(); ArrayList<ContentLine> rescmd = new ArrayList<ContentLine>(); { int i = 0; for (ContentLine cl : cmdRepository.findAll()) { if (cl.getContent().startsWith(filter)) { ContentLine srl = new ContentLine(); Map<String, Object> model = new HashMap<String, Object>(); model.put("cmd", cl); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/cmd.vm", "UTF-8", model); srl.setContent(text); srl.setLine(i++); rescmd.add(srl); } } } Collections.reverse(rescmd); res.addAll(rescmd.subList(0, Math.min(10, rescmd.size()))); List<ContentLine> out = new ArrayList<ContentLine>(); try { IStata stata = stataFactory.getInstance(); /* * get files */ Collection<ContentLine> filesNames = filteredFiles(filter, pos, from, to); res.addAll(filesNames); /* * get VARS, should be a mothod call probably */ // current token StringBuilder token = new StringBuilder(""); StringBuilder rest = new StringBuilder(filter); int p = (pos == -1 || pos > filter.length()) ? filter.length() : pos; char ch = 'x'; while (p > 0 && (CharUtils.isAsciiAlphanumeric(ch = filter.charAt(p - 1)) || ch == '_')) { token.insert(0, ch); rest.deleteCharAt(p - 1); p--; } // remove rest of potential token while (rest.length() > 0 && p > 0 && p < rest.length() && (CharUtils.isAsciiAlphanumeric(rest.charAt(p)) || rest.charAt(p) == '_')) { rest.deleteCharAt(p); } String t = token.toString(); List<StataVar> list = new ArrayList<StataVar>(); List<StataVar> listfull = stata.getVars("", false); if (t.length() > 0) { for (StataVar sv : listfull) { if (sv.getName().startsWith(t)) { list.add(sv); } } } else { list = listfull; } for (int i = 0; i < list.size(); i++) { ContentLine srl = new ContentLine(); srl.setLine(i + 100); String vname = list.get(i).getName(); String cl = new StringBuilder(rest).insert(p, " ").insert(p, vname).toString(); try { String cc = URLEncoder.encode(cl, "UTF-8"); Map<String, Object> model = new HashMap<String, Object>(); model.put("var", vname); model.put("repl", cc); model.put("focuspos", p + 1 + vname.length()); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/var.vm", "UTF-8", model); srl.setContent(text); res.add(srl); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (StataNotRunningException e) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent( "<div class='list-group-item sidebaritem error' >" + "Stata not running, you can try to start " + "an instance by clicking " + "<a target='_blank' href='/start'>here</a>" + "</div>"); out.add(srl); } catch (StataBusyException e1) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent("<div class='list-group-item sidebaritem error' >" + "Stata appears to by busy or not running, you can try to " + "start a new instance by clicking " + "<a target='_blank' href='/start'>here</a> " + "or wait for the current job to complete</div>"); out.add(srl); } out.addAll(res); return out; }
From source file:com.bibisco.manager.ProjectManager.java
private static String getProjectNameForExport(String pStrProjectName) { StringBuilder lStringBuilder = new StringBuilder(); for (int i = 0; i < pStrProjectName.length(); i++) { if (CharUtils.isAsciiAlphanumeric(pStrProjectName.charAt(i))) { lStringBuilder.append(pStrProjectName.charAt(i)); }/*from w ww . j ava2s . c o m*/ } return lStringBuilder.toString(); }
From source file:com.zb.jcseg.util.WordUnionUtils.java
/** * ?? -- M7//from w w w .j av a 2 s . com * * @param c * @return */ public static boolean isEndWithAsciiAlphanumeric(String str) { if (StringUtils.isEmpty(str)) { return false; } return CharUtils.isAsciiAlphanumeric(str.charAt(str.length() - 1)); }
From source file:net.sourceforge.subsonic.taglib.UrlTag.java
private boolean isAsciiAlphaNumeric(String s) { if (s == null) { return true; }/*from w w w . j a va 2s . c o m*/ for (int i = 0; i < s.length(); i++) { if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) { return false; } } return true; }
From source file:org.apache.openjpa.lib.identifier.IdentifierRule.java
/** * SQL identifier rules:/* w w w. j av a2s.c o 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.eclipse.skalli.model.Project.java
/** * Returns the short name if it exists or constructs one from the project name otherwise. * * <p>//from www . ja v a2 s . c o m * The constructed name is guaranteed to contain only alpha-numeric letters and to be 2 to 10 characters long. * It will consist of the first letters of each word, if the project name includes multiple words. * Otherwise the project name shortened to max. 10 characters will be returned. * </p> * * @return */ public String getOrConstructShortName() { if (!StringUtils.isBlank(shortName)) { return shortName; } else { if (name.contains(" ")) { //$NON-NLS-1$ // use first characters of each word, if they are alpha-numeric and the resulting length exceeds 1 char. StringBuilder retAbbrev = new StringBuilder(); for (String n : name.split(" ")) { //$NON-NLS-1$ if (n.length() > 0) { char ch = n.charAt(0); if (CharUtils.isAsciiAlphanumeric(ch) && retAbbrev.length() < 10) { retAbbrev.append(ch); } } } // if the first-char abbreviation is long enough, use it if (retAbbrev.length() > 1) { return retAbbrev.toString(); } } // Otherwise use the first 10 alpha-numeric characters of the project name, if they exceed 1 char. StringBuilder retShortenedName = new StringBuilder(); for (int i = 0; i < name.length() && retShortenedName.length() < 10; i++) { char ch = name.charAt(i); if (CharUtils.isAsciiAlphanumeric(ch)) { retShortenedName.append(ch); } } if (retShortenedName.length() > 1) { return retShortenedName.toString(); } // If still no valid short name was found, then return the last 10 alpha-numeric characters of the project id StringBuilder retProjectId = new StringBuilder(); for (int i = projectId.length() - 1; i >= 0 && retProjectId.length() < 10; i--) { char ch = projectId.charAt(i); if (CharUtils.isAsciiAlphanumeric(ch)) { retProjectId.append(ch); } } return retProjectId.reverse().toString(); } }
From source file:org.hac.service.impl.FormatCheck.java
/** * ???/* w w w .ja v a2 s . c om*/ */ @SuppressWarnings("unchecked") @Override protected Map<String, Object> executeService(Map<String, Object> inputData) throws TsrvfwSystemException, TsrvfwBusinessException { // ??? if (!LogicUtils.isNotEmptyMap(inputData)) { throw new HACSystemException("?????"); } // ?? for (Map.Entry<String, ?> e : inputData.entrySet()) { Map<String, Object> valueMap = (Map<String, Object>) inputData.get(e.getKey()); // ??? if (!LogicUtils.isNotEmptyMap(valueMap)) { throw new HACSystemException("???????"); } String data = LogicUtils.getMapValueToString(valueMap, "data"); String type = LogicUtils.getMapValueToString(valueMap, "type"); if (!NumberUtils.isNumber(type)) { throw new HACSystemException("?????type????"); } if (LogicUtils.isNotEmptyString(data)) { // ?? if (2 == Integer.parseInt(type)) { if (!NumberUtils.isNumber(data)) { throw new HACBusinessException(this.getClass().getName() + ":00001", "", (String[]) valueMap.get("name")); } } // ?? if (3 == Integer.parseInt(type)) { for (char c : data.toCharArray()) { if (!CharUtils.isAsciiAlphanumeric(c)) { throw new HACBusinessException(this.getClass().getName() + ":00002", "", (String[]) valueMap.get("name")); } } } // ?? if (4 == Integer.parseInt(type)) { Pattern ptn = Pattern.compile(ComponentCommonConst.REGEX_PATTERN_EMAIL); Matcher mc = ptn.matcher(data); if (!mc.matches()) { throw new HACBusinessException(this.getClass().getName() + ":00002", "", (String[]) valueMap.get("name")); } } } } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(ActionCommonConst.RESULT_CODE, ActionCommonConst.RESULT_SUCCESS); return resultMap; }
From source file:org.jahia.services.content.JCRContentUtils.java
/** * Generates the JCR node name from the provided text by normalizing it, * converting to lower case, replacing spaces with dashes and truncating to * ${@code maxLength} characters.//from ww w. jav a2s.co m * * @param text the original text to be used as a source * @param maxLength the maximum length of the resulting name (it will be * truncated if needed) * @return the JCR node name from the provided text by normalizing it, * converting to lower case, replacing spaces with dashes and * truncating to ${@code maxLength} characters */ public static String generateNodeName(String text, int maxLength) { String nodeName = text; final char[] chars = Normalizer.normalize(nodeName, Normalizer.NFKD).toCharArray(); final char[] newChars = new char[chars.length]; int j = 0; for (char aChar : chars) { if (CharUtils.isAsciiAlphanumeric(aChar) || aChar == 32 || aChar == '-') { newChars[j++] = aChar; } } nodeName = Patterns.SPACE.matcher(new String(newChars, 0, j).trim()).replaceAll("-").toLowerCase(); if (nodeName.length() > maxLength) { nodeName = nodeName.substring(0, maxLength); if (nodeName.endsWith("-") && nodeName.length() > 2) { nodeName = nodeName.substring(0, nodeName.length() - 1); } } return StringUtils.isNotEmpty(nodeName) ? nodeName : "untitled"; }