List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:nl.nn.adapterframework.monitoring.GalmMonitorAdapter.java
public void configure() throws ConfigurationException { super.configure(); hostname = Misc.getHostname();/* w w w . ja va 2 s . c o m*/ AppConstants appConstants = AppConstants.getInstance(); sourceId = appConstants.getResolvedProperty(SOURCE_ID_KEY); if (StringUtils.isEmpty(sourceId)) { throw new ConfigurationException("cannot read sourceId from [" + SOURCE_ID_KEY + "]"); } if (sourceId.indexOf(' ') >= 0) { StringBuffer replacement = new StringBuffer(); boolean replacementsMade = false; for (int i = 0; i < sourceId.length(); i++) { char c = sourceId.charAt(i); if (Character.isLetterOrDigit(c) || c == '_') { replacement.append(c); } else { replacement.append('_'); replacementsMade = true; } } if (replacementsMade) { if (log.isDebugEnabled()) log.debug("sourceId [" + sourceId + "] read from [" + SOURCE_ID_KEY + "] contains spaces, replacing them with underscores, resulting in [" + replacement.toString() + "]"); sourceId = replacement.toString(); } } dtapStage = appConstants.getString(DTAP_STAGE_KEY, null); if (StringUtils.isEmpty(dtapStage)) { throw new ConfigurationException("cannot read dtapStage from [" + DTAP_STAGE_KEY + "]"); } if (!("DEV".equals(dtapStage)) && !("TEST".equals(dtapStage)) && !("ACCEPT".equals(dtapStage)) && !("PROD".equals(dtapStage))) { throw new ConfigurationException("dtapStage [" + dtapStage + "] read from [" + DTAP_STAGE_KEY + "] not equal to one of DEV, TEST, ACCEPT, PROD"); } }
From source file:org.sakaiproject.kernel.util.PathUtils.java
/** * @param target/* w w w .ja va 2s .co m*/ * the target being formed into a structured path. * @return the structured path. */ private static String getStructuredHash(String target) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] userHash = md.digest(target.getBytes("UTF-8")); char[] chars = new char[8 + target.length()]; byte current = userHash[0]; int hi = (current & 0xF0) >> 4; int lo = current & 0x0F; chars[0] = '/'; chars[1] = (char) (hi < 10 ? ('0' + hi) : ('A' + hi - 10)); chars[2] = (char) (lo < 10 ? ('0' + lo) : ('A' + lo - 10)); current = userHash[1]; hi = (current & 0xF0) >> 4; lo = current & 0x0F; chars[3] = '/'; chars[4] = (char) (hi < 10 ? ('0' + hi) : ('A' + hi - 10)); chars[5] = (char) (lo < 10 ? ('0' + lo) : ('A' + lo - 10)); chars[6] = '/'; for (int i = 0; i < target.length(); i++) { char c = target.charAt(i); if (!Character.isLetterOrDigit(c)) { c = '_'; } chars[i + 7] = c; } chars[7 + target.length()] = '/'; return new String(chars); } catch (NoSuchAlgorithmException e) { LOG.error(e); } catch (UnsupportedEncodingException e) { LOG.error(e); } return null; }
From source file:com.amazonaws.cognito.devauthsample.Utilities.java
public static boolean isValidUsername(String username) { int length = username.length(); if (length < 3 || length > 128) { return false; }// w ww. ja va 2s .c o m char c = 0; for (int i = 0; i < length; i++) { c = username.charAt(i); if (!Character.isLetterOrDigit(c) && '_' != c && '.' != c && '@' != c) { return false; } } return true; }
From source file:org.apache.abdera2.common.security.ApiKey.java
/** * Generates a random string that can be used as an API Key. * The string is generated by creating a random array of * bytes, generating an hmac, then base64 encoding those. * All non alphanumeric characters in the base64 encoded * result are then replaced with periods ('.') to simplify * the result a bit more. The resulting API Key can be * expected to be reasonably random and suitable for use * within a request URI (e.g. key={apikey}). *///ww w . j av a2 s . co m public String generateNext() { int len = Math.min(20, size); byte[] buf = hmac(randomBytes(len)); buf = Base64.encodeBase64(buf, false, true); StringBuilder sb = new StringBuilder(); for (byte b : buf) sb.append(Character.isLetterOrDigit(b) ? (char) b : '.'); return sb.toString(); }
From source file:br.com.renatoccosta.regexrenamer.element.FilterElement.java
@Override public String convert(String src) { StringBuilder sb = new StringBuilder(); char[] caracs = src.toCharArray(); switch (mode) { case LETTERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isLetter(c)) { sb.append(c);// w w w .j a v a 2 s . c om } } return sb.toString(); case NUMBERS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (!Character.isDigit(c)) { sb.append(c); } } return sb.toString(); case SYMBOLS: for (int i = 0; i < caracs.length; i++) { char c = caracs[i]; if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) { sb.append(c); } } return sb.toString(); case WHITE_SPACE: return StringUtils.deleteWhitespace(src); } return src; }
From source file:com.agiletec.aps.system.common.entity.model.attribute.HypertextAttribute.java
/** * Return the requested number of characters rounded on word boundary of * the text associated to this attribute, in the current language, * stripping HTML tags, if any. // w ww .java 2 s . c o m * @param n The minimum number of characters to return * @return The string of text with the desired length. */ public String getEscapedHead(int n) { String parsedText = super.getText().replaceAll("<[^<>]+>", "").trim(); String head = parsedText; if (n < parsedText.length()) { while ((Character.isLetterOrDigit(parsedText.charAt(n)) || (parsedText.charAt(n) == ';')) && (n < parsedText.length())) { n++; } head = parsedText.substring(0, n); } return head; }
From source file:egovframework.rte.fdl.string.EgovStringUtil.java
/** * @param str/* w w w .j a v a 2s. co m*/ * @return */ public static boolean isAlphaNumeric(String str) { if (str == null) { return false; } int size = str.length(); if (size == 0) return false; for (int i = 0; i < size; i++) { if (!Character.isLetterOrDigit(str.charAt(i))) { return false; } } return true; }
From source file:jahirfiquitiva.iconshowcase.utilities.utils.IconUtils.java
/** * This method's code was created by Aidan Follestad. Complete credits to him. *//*from ww w . j a v a 2s . c om*/ public static String formatName(String mName) { StringBuilder sb = new StringBuilder(); int underscoreMode = 0; boolean foundFirstLetter = false; boolean lastWasLetter = false; for (int i = 0; i < mName.length(); i++) { final char c = mName.charAt(i); if (Character.isLetterOrDigit(c)) { if (underscoreMode == SPACE) { sb.append(' '); underscoreMode = CAPS; } if (!foundFirstLetter && underscoreMode == CAPS) sb.append(c); else sb.append(i == 0 || underscoreMode > 1 ? Character.toUpperCase(c) : c); if (underscoreMode < CAPS_LOCK) underscoreMode = 0; foundFirstLetter = true; lastWasLetter = true; } else if (c == '_') { if (underscoreMode == CAPS_LOCK) { if (lastWasLetter) { underscoreMode = SPACE; } else { sb.append(c); underscoreMode = 0; } } else { underscoreMode++; } lastWasLetter = false; } } return sb.toString(); }
From source file:org.gradle.api.internal.plugins.osgi.OsgiHelper.java
/** * Get the symbolic name as group + "." + archivesBaseName, with the following exceptions * <ul>//from w ww . j av a 2s .co m * <li> * if group has only one section (no dots) and archivesBaseName is not null then the first package * name with classes is returned. eg. commons-logging:commons-logging -> org.apache.commons.logging * </li> * <li> * if archivesBaseName is equal to last section of group then group is returned. * eg. org.gradle:gradle -> org.gradle * </li> * <li> * if archivesBaseName starts with last section of group that portion is removed. * eg. org.gradle:gradle-core -> org.gradle.core * </li> * <li> * if archivesBaseName starts with the full group, the archivesBaseName is return, * e.g. org.gradle:org.gradle.core -> org.gradle.core * </li> * </ul> * * @param project The project being processed. * * @return Returns the SymbolicName that should be used for the bundle. */ public String getBundleSymbolicName(Project project) { String group = project.getGroup().toString(); String archiveBaseName = project.getConvention().getPlugin(BasePluginConvention.class) .getArchivesBaseName(); if (archiveBaseName.startsWith(group)) { return archiveBaseName; } int i = group.lastIndexOf('.'); String lastSection = group.substring(++i); if (archiveBaseName.equals(lastSection)) { return group; } if (archiveBaseName.startsWith(lastSection)) { String artifactId = archiveBaseName.substring(lastSection.length()); if (Character.isLetterOrDigit(artifactId.charAt(0))) { return getBundleSymbolicName(group, artifactId); } else { return getBundleSymbolicName(group, artifactId.substring(1)); } } return getBundleSymbolicName(group, archiveBaseName); }
From source file:org.marketcetera.util.misc.RandomStringsTest.java
private static void testStrId(int len, String s) { int[] ucps = StringUtils.toUCPArray(s); assertEquals(len, ucps.length);/* w w w. j a v a 2 s . com*/ if (len >= 1) { assertTrue("Value was " + Integer.toHexString(ucps[0]), Character.isLetter(ucps[0])); } if (len >= 2) { assertTrue("Value was " + Integer.toHexString(ucps[1]), Character.isDigit(ucps[1])); } for (int i = 2; i < len; i++) { assertTrue("Value was " + Integer.toHexString(ucps[i]), Character.isLetterOrDigit(ucps[i])); } }