List of usage examples for org.apache.commons.lang StringUtils containsOnly
public static boolean containsOnly(String str, String validChars)
Checks if the String contains only certain characters.
From source file:com.funambol.foundation.admin.SIFSyncSourceConfigPanel.java
/** * Checks if the values provided by the user are all valid. * In the case of errors, a IllegalArgumentException is thrown. * * @throws IllegalArgumentException if:/*from w ww . j a v a 2 s. com*/ * <ul> * <li>name, uri, type or directory are empty (null or zero-length) * <li>the types list length does not match the versions list length * </ul> */ private void validateValues() throws IllegalArgumentException { String value = null; value = nameValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Field 'Name' cannot be empty. Please provide a SyncSource name."); } if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) { throw new IllegalArgumentException( "Only the following characters are allowed for field 'Name': \n" + NAME_ALLOWED_CHARS); } value = sourceUriValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Source URI' cannot be empty. Please provide a SyncSource URI."); } value = directoryValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Source directory' cannot be empty. Please provide a SyncSource db directory."); } }
From source file:com.funambol.email.admin.EmailSyncSourceConfigPanel.java
/** * Checks if the values provided by the user are all valid. In caso of errors, * a IllegalArgumentException is thrown. * * @throws IllegalArgumentException if://from www.j a v a 2s . c om * <ul> * <li>name, uri, type or directory are empty (null or zero-length) * <li>the types list length does not match the versions list length * <ul> */ public void validateValues() throws IllegalArgumentException { String value; value = sourceUriValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Source URI' cannot be empty. " + "Please provide a SyncSource URI."); } value = nameValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Name' cannot be empty. " + "Please provide a SyncSource name."); } if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) { throw new IllegalArgumentException( "Only the following characters are " + "allowed for field 'Name': \n" + NAME_ALLOWED_CHARS); } int typesCount = new StringTokenizer(infoTypesValue.getText(), ",").countTokens(); if (typesCount == 0) { throw new IllegalArgumentException( "Field 'Supported types' cannot be empty. Please provide one or more supported types."); } if (typesCount != new StringTokenizer(infoVersionsValue.getText(), ",").countTokens()) { throw new IllegalArgumentException("Number of supported types does not match number of versions"); } }
From source file:com.jgui.ttscrape.htmlunit.GridParser.java
private void parseShowSummary(Show show, String txt) { int i1 = txt.indexOf('('); if (i1 >= 0) { int i2 = txt.indexOf(')', i1); if (i2 > 0) { String flags = txt.substring(i1 + 1, i2); parseShowSummary(show, flags); show.setSubtitle(StringUtils.trim(txt.substring(i2 + 1))); return; }/*from w w w . ja va 2 s . c o m*/ } String[] fields = txt.split(","); for (String field : fields) { field = field.trim(); if (StringUtils.isNotEmpty(field)) { // look for star rating. if (StringUtils.containsOnly(field, "*+")) { show.setStars((float) (StringUtils.countMatches(field, "*") + 0.5 * StringUtils.countMatches(field, "+"))); } if (StringUtils.containsOnly(field, "0123456789")) { try { show.setYear(Integer.parseInt(field)); } catch (NumberFormatException e) { logger.error("failed to parse year: {}", field); } } if ("New".equals(field)) { show.setNewFlag(true); } if (knownRatings.contains(field)) { show.setRating(field); } } } }
From source file:gda.device.scannable.scannablegroup.ScannableGroup.java
@Override public String toFormattedString() { //TODO this method does not provide correct indentation level for a scannable group inside another scannable group //TODO the regex parser is unreliable as described by FIXME below // IT would be better to create format message by delegate to individual members directly, rather than re-parsing output again. //TODO this works if the toFormattedString method of the members conforms to a standard. But I don't think there is one! //Rather use getPosition and format here. String membersOutput = getName() + " ::\n"; for (Scannable member : groupMembers) { membersOutput += member.toFormattedString() + "\n"; }//from ww w . j a v a 2 s .co m String[] originalInputNames = getInputNames(); String[] namesToSplitOn = getInputNames(); String[] names = getGroupMemberNames(); String[] extras = getExtraNames(); // FIXME regex-based splitting of membersOutput is broken if one group member name is a substring of another - e.g. "col_y" and "col_yaw" if (originalInputNames.length + extras.length == 0) { return membersOutput; } if (extras.length > 0) { namesToSplitOn = (String[]) ArrayUtils.addAll(namesToSplitOn, extras); } // find the longest name, to help with formatting the output int longestName = 0; for (String objName : namesToSplitOn) { if (objName.length() > longestName) { longestName = objName.length(); } } namesToSplitOn = (String[]) ArrayUtils.add(namesToSplitOn, getName()); namesToSplitOn = (String[]) ArrayUtils.addAll(namesToSplitOn, names); String regex = ""; for (String name : namesToSplitOn) { regex += name + " +|"; } regex = regex.substring(0, regex.length() - 1); String[] values = membersOutput.split(regex); String returnString = getName() + "::\n"; int nextNameIndex = 0; for (int i = 0; i < values.length; i++) { String value = values[i].trim(); if (value.startsWith(":")) { value = value.substring(1).trim(); } if (StringUtils.containsOnly(value, ":()") || value.isEmpty()) { continue; } returnString += " " + StringUtils.rightPad(namesToSplitOn[nextNameIndex], longestName) + ": " + value + "\n"; nextNameIndex++; } returnString.trim(); returnString = returnString.substring(0, returnString.length() - 1); return returnString; }
From source file:ips1ap101.lib.core.util.STP.java
public static boolean esIdentificadorSqlValido(String string) { String validChars = StrUtils.VALID_CHARS; return StringUtils.isNotBlank(string) && StringUtils.containsOnly(string.toLowerCase(), validChars) && StringUtils.isAlpha(string.substring(0, 1)); }
From source file:ips1ap101.lib.core.util.STP.java
public static boolean esIdentificadorArchivoValido(String string) { String validChars = StrUtils.VALID_CHARS; return StringUtils.isNotBlank(string) && StringUtils.containsOnly(string.toLowerCase(), validChars); }
From source file:com.egt.core.util.STP.java
public static boolean esIdentificadorSqlValido(String string) { String validChars = "abcdefghijklmnopqrstuvwxyz_1234567890"; return (StringUtils.isNotBlank(string) && StringUtils.containsOnly(string, validChars) && StringUtils.isAlpha(string.substring(0, 1))); }
From source file:com.egt.core.util.STP.java
public static boolean esIdentificadorArchivoValido(String string) { String validChars = "abcdefghijklmnopqrstuvwxyz_1234567890"; return (StringUtils.isNotBlank(string) && StringUtils.containsOnly(string, validChars)); }
From source file:com.funambol.foundation.admin.FileDataObjectSyncSourceConfigPanel.java
/** * Checks if the values provided by the user are all valid. In caso of errors, * a IllegalArgumentException is thrown. * * @throws IllegalArgumentException if:/*from w w w. j a v a 2 s.co m*/ * <ul> * <li>name, uri, type or directory are empty (null or zero-length) * <li>the types list length does not match the versions list length * </ul> */ private void validateValues() throws IllegalArgumentException { String value = null; value = nameValue.getText().trim(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Field 'Name' cannot be empty. Please provide a SyncSource name."); } if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) { throw new IllegalArgumentException( "Only the following characters are allowed for field 'Name': \n" + NAME_ALLOWED_CHARS); } value = sourceUriValue.getText().trim(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Source URI' cannot be empty. Please provide a SyncSource URI."); } //checks value for storage provider StorageProviderWrapper currentStorageProvider = getStorageProviderWrapperForSelectedComboboxItem(); String errors = currentStorageProvider.checkValidity(); if (!StringUtils.isEmpty(errors)) { throw new IllegalArgumentException(errors + " cannot be empty. Please provide a valid value."); } value = localRootPathValue.getText().trim(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Root local path for temp files' cannot be empty. Please provide a SyncSource db directory."); } //checks role quota values for (int rowIndex = 0; rowIndex < model.getRowCount(); rowIndex++) { String quotaValueString = (String) model.getValueAt(rowIndex, 1); try { long quotaValue = StringTools.converterStringSizeInBytes(quotaValueString); } catch (NumberFormatException e) { String quotaDesc = (String) model.getValueAt(rowIndex, 0); throw new IllegalArgumentException( "Quota value for role '" + quotaDesc + "' is wrong. Please provide a valid value."); } } }
From source file:com.funambol.LDAP.admin.LDAPSyncSourceConfigPanel.java
/** * Checks if the values provided by the user are all valid. In caso of errors, * an IllegalArgumentException is thrown. * * @throws IllegalArgumentException if:/*from ww w . j ava 2 s . co m*/ * <ul> * <li>name, uri, type or directory are empty (null or zero-length) * <li>the types list length does not match the versions list length * </ul> */ private void validateValues() throws IllegalArgumentException { String value = nameValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Field 'Name' cannot be empty. Please provide a SyncSource name."); } if (!StringUtils.containsOnly(value, NAME_ALLOWED_CHARS.toCharArray())) { throw new IllegalArgumentException( "Only the following characters are allowed for field 'Name': \n" + NAME_ALLOWED_CHARS); } value = sourceUriValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException( "Field 'Source URI' cannot be empty. Please provide a SyncSource URI."); } value = dbNameValue.getText(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Field 'Sync DBMS name' cannot be empty. Please provide a name."); } value = (String) ldapServerValue.getSelectedItem(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Field 'LDAP Server Type' cannot be empty. Please provide a name."); } value = (String) daoNameValue.getSelectedItem(); if (StringUtils.isEmpty(value)) { throw new IllegalArgumentException("Field 'DAO objectclass' cannot be empty. Please provide a name."); } }