List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:co.runrightfast.core.security.auth.x500.DistinguishedName.java
private void validateAttributeValue(final String value, int maxLength) { if (StringUtils.isBlank(value)) { return;/*from w w w . j a va2 s . co m*/ } checkArgument(!Character.isWhitespace(value.charAt(0)), "cannot start with whitespace"); checkArgument(value.charAt(0) != '#', "cannot start with whitespace"); final char[] invalidChars = { ',', '+', '"', '\\', '<', '>', ';' }; final String invalidCharMessage = "invalid char found '%s' within : %s"; for (final char c : invalidChars) { final int index = value.indexOf(c); if (index != -1) { checkArgument(index != 0, invalidCharMessage, c, value); checkArgument(value.charAt(index - 1) == '\\', invalidCharMessage, c, value); } } }
From source file:com.aionemu.gameserver.cache.HTMLCache.java
private String compactHtml(StringBuilder sb, String html) { sb.setLength(0);/*from ww w . j a va 2 s.c o m*/ sb.append(html); for (int i = 0; i < sb.length(); i++) { if (Character.isWhitespace(sb.charAt(i))) { sb.setCharAt(i, ' '); } } replaceAll(sb, " ", " "); replaceAll(sb, "< ", "<"); replaceAll(sb, " >", ">"); for (int i = 0; i < TAGS_TO_COMPACT.length; i += 3) { replaceAll(sb, TAGS_TO_COMPACT[i + 1], TAGS_TO_COMPACT[i]); replaceAll(sb, TAGS_TO_COMPACT[i + 2], TAGS_TO_COMPACT[i]); } replaceAll(sb, " ", " "); // String.trim() without additional garbage int fromIndex = 0; int toIndex = sb.length(); while (fromIndex < toIndex && sb.charAt(fromIndex) == ' ') { fromIndex++; } while (fromIndex < toIndex && sb.charAt(toIndex - 1) == ' ') { toIndex--; } return sb.substring(fromIndex, toIndex); }
From source file:com.adito.util.Utils.java
/** * @return true if all characters in the string are whitespace characters, or the string is empty **///from w w w . j a v a 2 s. c o m public static boolean isWhitespace(String s) { for (int i = 0; i < s.length(); ++i) { if (!Character.isWhitespace(s.charAt(i))) return false; } return true; }
From source file:gr.abiss.calipso.wicket.customattrs.CustomAttributeUtils.java
/** * Parses the given user intput to create the custom attribute lookup values (options) and their translations, * then add them to the given CustomAttribute. * @param optionsTextIput/*w ww . ja v a 2 s . c o m*/ * @param attribute * @param languages */ public static void parseOptionsIntoAttribute(Map<String, String> optionsTextIput, CustomAttribute attribute, List<Language> languages) { //logger.info("parseOptionsIntoAttribute, attribute: "+attribute); // add options attribute.setPersistedVersion(attribute.getVersion()); attribute.setVersion(attribute.getVersion() + 1); attribute.removeAllLookupValues(); List<CustomAttributeLookupValue> optionsList = new LinkedList<CustomAttributeLookupValue>(); String languageId = null; for (Language language : languages) { if (languageId == null) { languageId = language.getId(); } String input = optionsTextIput.get(language.getId()); //logger.info("textAreaOptions.get(language.getId(): "+input); if (StringUtils.isNotBlank(input)) { Stack<CustomAttributeLookupValue> parents = new Stack<CustomAttributeLookupValue>(); String[] lines = input.split("\\r?\\n"); int listIndex = -1; for (int j = 0; j < lines.length; j++) { listIndex++; // count whitespace characters to determine level String line = lines[j]; //logger.info("Reading option line: "+line); int countLevel = 1; int limit = line.length(); for (int i = 0; i < limit; ++i) { if (Character.isWhitespace(line.charAt(i))) { ++countLevel; } else { break; } } String translatedName = line.substring(countLevel - 1).trim(); //logger.info("translatedName: "+translatedName); // build CustomAttributeLookupValue if it doesn't already exist CustomAttributeLookupValue lookupValue; if (language.getId().equalsIgnoreCase(languageId)) { //logger.info("creating new lookupValue and adding to list index " + listIndex + " for " + translatedName); lookupValue = new CustomAttributeLookupValue(); optionsList.add(lookupValue); } else { //logger.info("trying to get lookupValue from list index " + listIndex + "for "+translatedName); lookupValue = optionsList.get(listIndex); } lookupValue.setShowOrder(listIndex); if (language.getId().equalsIgnoreCase("en")) { lookupValue.setName(translatedName); lookupValue.setValue(translatedName); } lookupValue.setLevel(countLevel); // fix parent/child while ((!parents.isEmpty()) && parents.peek().getLevel() >= lookupValue.getLevel()) { parents.pop(); } // pile it if (lookupValue.getLevel() > 1) { //logger.info("Adding child "+lookupValue.getName() + "to parent " +parents.peek()); parents.peek().addChild(lookupValue); } parents.push(lookupValue); // add the translation //logger.info("Adding lookup value "+language.getId()+" translation: "+translatedName); lookupValue.addNameTranslation(language.getId(), translatedName); //logger.info("translations afre now: "+lookupValue.getNameTranslations()); } } //Set<CustomAttributeLookupValue> lookupValueSet = new HashSet<CustomAttributeLookupValue>(); //lookupValueSet.addAll(optionsList); } // update attribute lookup values attribute.removeAllLookupValues(); /* List<CustomAttributeLookupValue> toRemove = new LinkedList<CustomAttributeLookupValue>(); for(CustomAttributeLookupValue value : attribute.getAllowedLookupValues()){ toRemove.add(value); } attribute.removeAll(toRemove);*/ for (CustomAttributeLookupValue value : optionsList) { //logger.info("Adding lookupValue with translations: "+value.getNameTranslations()); attribute.addAllowedLookupValue(value); } //logger.info("Added lookup values: "+attribute.getAllowedLookupValues()); }
From source file:com.cloudhopper.sxmp.OptionalParamMap.java
private static boolean isBlank(String str) { int strLen;/* w w w.j a v a2s . co m*/ if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; }
From source file:HTMLParser.java
private int getAttrib(int c) { AttribPair a = new AttribPair(); StringBuffer s = new StringBuffer(); while (c != EOF && c != '=' && !Character.isWhitespace((char) c)) { s.append((char) c); c = getC();/*from ww w. j a v a 2 s . c om*/ } a.attrib = s.toString(); c = skipSpace(c); if (c != '=') { attribs.add(a); return c; } s = new StringBuffer(); c = skipSpace(getC()); if (c == '\'' || c == '"') { int quote = c; for (;;) { c = getC(); if (c == -1) break; if (c == quote) { c = getC(); break; } if (c == '\\') { c = getC(); if (c == EOF) break; s.append('\\'); s.append((char) c); } else { s.append((char) c); } } } else { for (;;) { c = getC(); if (c == -1) break; if (c == '>' || c == '/' || Character.isWhitespace((char) c)) { c = getC(); break; } s.append((char) c); } } a.value = s.toString(); attribs.add(a); return c; }
From source file:Version2LicenseDecoder.java
private static String removeWhiteSpaces(String licenseData) { if (licenseData != null && licenseData.length() != 0) { char[] chars = licenseData.toCharArray(); StringBuffer buf = new StringBuffer(chars.length); for (int i = 0; i < chars.length; ++i) { if (!Character.isWhitespace(chars[i])) { buf.append(chars[i]);/*from ww w . j ava 2 s . c o m*/ } } return buf.toString(); } else { return licenseData; } }
From source file:com.playtech.portal.platform.common.util.Validator.java
/** * Returns <code>true</code> if the string is an email address. The only * requirements are that the string consist of two parts separated by an @ * symbol, and that it contain no whitespace. * * @param address the string to check/*w w w . ja v a 2 s .co m*/ * @return <code>true</code> if the string is an email address; * <code>false</code> otherwise */ public static boolean isAddress(String address) { if (isNull(address)) { return false; } String[] tokens = address.split("@"); if (tokens.length != 2) { return false; } for (String token : tokens) { for (char c : token.toCharArray()) { if (Character.isWhitespace(c)) { return false; } } } return true; }
From source file:com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryAccountValidator.java
@Override public void validate(ConfigProblemSetBuilder p, DockerRegistryAccount n) { String resolvedPassword = null; String password = n.getPassword(); String passwordFile = n.getPasswordFile(); String username = n.getUsername(); boolean passwordProvided = password != null && !password.isEmpty(); boolean passwordFileProvided = passwordFile != null && !passwordFile.isEmpty(); if (passwordProvided && passwordFileProvided) { p.addProblem(Severity.ERROR, "You have provided both a password and a password file for your docker registry. You can specify at most one."); return;/* w w w .j a va 2s.co m*/ } if (passwordProvided) { resolvedPassword = password; } else if (passwordFileProvided) { resolvedPassword = ValidatingFileReader.contents(p, passwordFile); if (resolvedPassword == null) { return; } if (resolvedPassword.isEmpty()) { p.addProblem(Severity.WARNING, "The supplied password file is empty."); } } else { resolvedPassword = ""; } if (!resolvedPassword.isEmpty()) { if (username == null || username.isEmpty()) { p.addProblem(Severity.WARNING, "You have supplied a password but no username."); } } else { if (username != null && !username.isEmpty()) { p.addProblem(Severity.WARNING, "You have a supplied a username but no password."); } } DockerRegistryNamedAccountCredentials credentials; try { credentials = (new DockerRegistryNamedAccountCredentials.Builder()).accountName(n.getName()) .address(n.getAddress()).email(n.getEmail()).password(n.getPassword()) .passwordFile(n.getPasswordFile()).dockerconfigFile(n.getDockerconfigFile()) .username(n.getUsername()).build(); } catch (Exception e) { p.addProblem(Severity.ERROR, "Failed to instantiate docker credentials for account \"" + n.getName() + "\"."); return; } ConfigProblemBuilder authFailureProblem = null; if (n.getRepositories() == null || n.getRepositories().size() == 0) { try { DockerRegistryCatalog catalog = credentials.getCredentials().getClient().getCatalog(); if (catalog.getRepositories() == null || catalog.getRepositories().size() == 0) { p.addProblem(Severity.ERROR, "Your docker registry has no repositories specified, and the registry's catalog is empty.") .setRemediation( "Manually specify some repositories for this docker registry to index."); } } catch (Exception e) { authFailureProblem = p.addProblem(Severity.ERROR, "Unable to connect the registries catalog endpoint: " + e.getMessage() + "."); } } else { try { // effectively final int tagCount[] = new int[1]; tagCount[0] = 0; n.getRepositories().forEach( r -> tagCount[0] += credentials.getCredentials().getClient().getTags(r).getTags().size()); if (tagCount[0] == 0) { p.addProblem(Severity.WARNING, "None of your supplied repositories contain any tags. Spinnaker will not be able to deploy anything.") .setRemediation("Push some images to your registry."); } } catch (Exception e) { authFailureProblem = p.addProblem(Severity.ERROR, "Unable to reach repository: " + e.getMessage() + "."); } } if (authFailureProblem != null && !StringUtils.isEmpty(resolvedPassword)) { String message = "Your registry password has %s whitespace; if this is unintentional, this may be the cause of failed authentication."; if (Character.isWhitespace(resolvedPassword.charAt(0))) { authFailureProblem.setRemediation(String.format(message, "leading")); } char c = resolvedPassword.charAt(resolvedPassword.length() - 1); if (Character.isWhitespace(c)) { authFailureProblem.setRemediation(String.format(message, "trailing")); if (passwordFileProvided && c == '\n') authFailureProblem.setRemediation( "Your password file has a trailing newline; many text editors append a newline to files they open." + " If you think this is causing authentication issues, you can strip the newline with the command:\n\n" + " tr -d '\\n' < PASSWORD_FILE | tee PASSWORD_FILE"); } } }