List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty
public static String trimToEmpty(final String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .
From source file:org.fabrician.enabler.DockerContainer.java
private String resolveAndSet(RuntimeContextVariable var) throws Exception { String name = var.getName(); String currentValue = StringUtils.trimToEmpty(getStringVariableValue(name)); getEngineLogger().fine("Runtime context variable [" + name + "] has current value [" + currentValue + "]."); String newValue = resolveToString(name); getEngineLogger().fine("Runtime context variable [" + name + "] has resolved value [" + newValue + "]."); if (!newValue.equals(currentValue)) { getEngineLogger().fine(/*from w ww . j a v a2 s . c om*/ "Setting runtime context variable [" + name + "] to new resolved value [" + newValue + "]."); var.setValue(newValue); } return newValue; }
From source file:org.fabrician.enabler.util.BuildCmdOptions.java
public static Optional<String> build(RuntimeContextVariable var) { try {/*from w w w . j a v a2 s . co m*/ BuildCmdOptions val = valueOf(var.getName()); if (var.getTypeInt() != RuntimeContextVariable.OBJECT_TYPE) { String currentValue = StringUtils.trimToEmpty((String) var.getValue()); // empty value means the option is not valid and would be skipped // so that we accept the default if (!currentValue.isEmpty()) { if (val.isBooleanType) { Boolean b = BooleanUtils.toBooleanObject(currentValue); if (b != val.defaultBooleanValue) { return Optional.of(" " + val.optionSwitch + " "); } } else { return Optional.of(" " + val.optionSwitch + " " + currentValue); } } } } catch (Exception ex) { } return Optional.absent(); }
From source file:org.fabrician.enabler.util.RunCmdAuxiliaryOptions.java
public static Optional<String> build(RuntimeContextVariable var) { try {/*from w w w.ja v a 2 s . c o m*/ RunCmdAuxiliaryOptions val = valueOf(var.getName()); if (var.getTypeInt() != RuntimeContextVariable.OBJECT_TYPE) { String currentValue = StringUtils.trimToEmpty((String) var.getValue()); // empty value means the option is not valid and would be skipped // so that we accept the default if (!currentValue.isEmpty()) { if (val.isBooleanType) { Boolean b = BooleanUtils.toBooleanObject(currentValue); if (b != val.defaultBooleanValue) { return Optional.of(" " + val.optionSwitch + " "); } } else { return Optional.of(" " + val.optionSwitch + " " + currentValue); } } } } catch (Exception ex) { } return Optional.absent(); }
From source file:org.fabrician.enabler.util.SpecialDirective.java
/** * Resolve a string value including the special directive runtime context variables substitution tokens. * /* ww w. j a v a 2s. co m*/ * @param enabler * the enabler use * @param str * the string value * @return a fully resolved string value * @throws Exception */ public static String resolveStringValue(AbstractContainer enabler, String str) throws Exception { if (StringUtils.trimToEmpty(str).isEmpty()) { return str; } String resolvedStr = enabler.resolveVariables(str); List<String> substitution_tokens = extractSubstitutionTokens(resolvedStr); if (substitution_tokens.isEmpty()) { return resolvedStr; } Map<String, String> resolutionMap = resolveSubstitutionTokens(enabler, substitution_tokens); resolvedStr = StringUtils.replaceEachRepeatedly(resolvedStr, substitution_tokens.toArray(new String[] {}), getReplacementValues(substitution_tokens, resolutionMap)); return resolvedStr; }
From source file:org.fabrician.enabler.util.SpecialDirective.java
/** * Extract the list of 'Special Directive' runtime context variable substitution tokens embedded in a String * /*from w w w.j a va 2 s . com*/ * @param str * the string to extract from * @return a List of substitution tokens. */ public static List<String> extractSubstitutionTokens(String str) { List<String> list = new ArrayList<String>(); if (StringUtils.trimToEmpty(str).isEmpty()) { return Collections.unmodifiableList(list); } for (SpecialDirective directive : list()) { Matcher m = directive.substitutionPattern.matcher(str); if (m.find()) { String substring = m.group(0); if (substring != null && !list.contains(substring)) { list.add(substring); } } } return Collections.unmodifiableList(list); }
From source file:org.forgerock.cloudfoundry.Configuration.java
/** * Constructs a new Configuration./*w ww .ja v a2s . c om*/ * @param baseUri the base URI of OpenAM * @param openAmUsername the username to use to authenticate against OpenAM * @param openAmPassword the password to use to authenticate against OpenAM * @param realm the OpenAM realm to use * @param brokerUsername the username that clients to this broker are required to use. * @param brokerPassword the password that clients to this broker are required to use. * @param scopes A space delimited list of scopes that OAuth 2.0 clients will be created with. */ public Configuration(String baseUri, String openAmUsername, String openAmPassword, String realm, String brokerUsername, String brokerPassword, String scopes) { URI openAmBaseUrl; try { openAmBaseUrl = new URI(validateProperty(baseUri, "OPENAM_BASE_URI") + "/"); } catch (URISyntaxException e) { throw new IllegalStateException("OPENAM_BASE_URI is not a valid URI", e); } this.openAmUsername = validateProperty(openAmUsername, "OPENAM_USERNAME"); this.openAmPassword = validateProperty(openAmPassword, "OPENAM_PASSWORD"); this.brokerUsername = validateProperty(brokerUsername, "SECURITY_USER_NAME"); this.brokerPassword = validateProperty(brokerPassword, "SECURITY_USER_PASSWORD"); this.scopes = Lists.newArrayList(validateProperty(scopes, "OAUTH2_SCOPES").split(" ")); realm = StringUtils.trimToEmpty(realm); openAmApiBaseUrl = openAmBaseUrl.resolve("json/"); openAmApiRealmUrl = openAmBaseUrl.resolve("json/" + realm + "/"); openAmOAuth2Url = openAmBaseUrl.resolve("oauth2/" + realm + "/"); }
From source file:org.gbif.dwca.utils.UrlUtils.java
public static String encodeURLWhitespace(final String s) { return StringUtils.trimToEmpty(s).replaceAll(" ", "%20"); }
From source file:org.gbif.ipt.action.manage.SourceAction.java
@Override public void validateHttpPostOnly() { if (source != null) { // ALL SOURCES // check if title exists already as a source if (StringUtils.trimToEmpty(source.getName()).length() == 0) { addFieldError("source.name", getText("validation.required", new String[] { getText("source.name") })); } else if (StringUtils.trimToEmpty(source.getName()).length() < 3) { addFieldError("source.name", getText("validation.short", new String[] { getText("source.name"), "3" })); } else if (id == null && resource.getSources().contains(source)) { addFieldError("source.name", getText("manage.source.unique")); }/*from w w w . j ava2s .c om*/ if (SqlSource.class.isInstance(source)) { // SQL SOURCE SqlSource src = (SqlSource) source; // pure ODBC connections need only a DSN, no server if (StringUtils.trimToEmpty(src.getHost()).length() == 0 && rdbms != null && !rdbms.equalsIgnoreCase("odbc")) { addFieldError("sqlSource.host", getText("validation.required", new String[] { getText("sqlSource.host") })); } else if (StringUtils.trimToEmpty(src.getHost()).length() < 2) { addFieldError("sqlSource.host", getText("validation.short", new String[] { getText("sqlSource.host"), "2" })); } if (StringUtils.trimToEmpty(src.getDatabase()).length() == 0) { addFieldError("sqlSource.database", getText("validation.required", new String[] { getText("sqlSource.database") })); } else if (StringUtils.trimToEmpty(src.getDatabase()).length() < 2) { addFieldError("sqlSource.database", getText("validation.short", new String[] { getText("sqlSource.database"), "2" })); } } // else { // FILE SOURCE // TextFileSource src = (TextFileSource) source; // TODO validate file source // } } }
From source file:org.gbif.ipt.validation.ExtensionMappingValidator.java
public ValidationStatus validate(ExtensionMapping mapping, Resource resource, List<String[]> peek) { ValidationStatus v = new ValidationStatus(); // check required fields Extension ext = mapping.getExtension(); if (ext != null) { for (ExtensionProperty p : ext.getProperties()) { if (p.isRequired() && !mapping.isMapped(p)) { v.addMissingRequiredField(p); }//from w ww.j a v a 2 s. com } // check data types for default mappings for (PropertyMapping pm : mapping.getFields()) { ExtensionProperty extProperty = mapping.getExtension().getProperty(pm.getTerm()); DataType type = extProperty != null ? extProperty.getType() : null; if (type != null && DataType.string != type) { // non string data type. check if (!isValidDataType(type, pm, peek)) { v.addWrongDataTypeField(pm.getTerm()); } } } // check id mapping if (mapping.getIdColumn() == null) { // no id, ok if this is a core if (!ext.isCore()) { v.setIdProblem("validation.mapping.coreid.missing"); } } else if (mapping.getIdColumn().equals(ExtensionMapping.IDGEN_LINE_NUMBER)) { // pure integers are not allowed as line numbers plus integers will result in duplicates if (StringUtils.isNumericSpace(StringUtils.trimToNull(mapping.getIdSuffix()))) { v.setIdProblem("validation.mapping.coreid.linenumber.integer"); } // if its core make sure all other mappings to the same extensions dont use linenumber with the same suffix or if (ext.isCore()) { Set<ExtensionMapping> maps = new HashSet<ExtensionMapping>( resource.getMappings(ext.getRowType())); maps.remove(mapping); if (!maps.isEmpty()) { // we more mappings to the same extension, compare their id policy for (ExtensionMapping m : maps) { if (m.getIdColumn() != null && m.getIdColumn().equals(ExtensionMapping.IDGEN_LINE_NUMBER)) { // do we have different suffices? if (StringUtils.trimToEmpty(mapping.getIdSuffix()).equals(m.getIdSuffix())) { v.setIdProblem("validation.mapping.coreid.linenumber.samesufix"); } } } } } else { // linenumbers for extensions only make sense when there is a core with the same suffix boolean found = false; for (ExtensionMapping m : resource.getCoreMappings()) { if (m.getIdColumn() != null && m.getIdColumn().equals(ExtensionMapping.IDGEN_LINE_NUMBER)) { // do they have the same suffix? if (StringUtils.trimToEmpty(mapping.getIdSuffix()) .equals(StringUtils.trimToEmpty(m.getIdSuffix()))) { found = true; break; } } } if (!found) { v.setIdProblem("validation.mapping.coreid.linenumber.nocoresuffix"); } } } else if (mapping.getIdColumn().equals(ExtensionMapping.IDGEN_UUID)) { // not allowed for extensions if (ext.isCore()) { // if there are any extensions existing the cant link to the new UUIDs for (ExtensionMapping m : resource.getMappings()) { if (!m.isCore()) { v.setIdProblem("validation.mapping.coreid.uuid.extensions.exist"); } } } else { v.setIdProblem("validation.mapping.coreid.uuid.extension"); } } // else { // TODO: anything to check for regular columns? // } } return v; }
From source file:org.haiku.haikudepotserver.pkg.job.PkgIconImportArchiveJobRunner.java
private void processEntriesFromArchive(ArchiveInputStream archiveInputStream, CSVWriter writer) throws IOException { String[] row = new String[3]; ArchiveEntry archiveEntry;/*from www. ja va2 s. c om*/ while (null != (archiveEntry = archiveInputStream.getNextEntry())) { if (!archiveEntry.isDirectory()) { Matcher nameMatcher = PATTERN_PATH.matcher(archiveEntry.getName()); ArchiveEntryResult result; row[CSV_COLUMN_PKGNAME] = archiveEntry.getName(); if (nameMatcher.matches()) { if (archiveEntry.getSize() <= MAX_ICON_PAYLOAD) { result = processMatchingFileEntryFromArchive(archiveInputStream, nameMatcher.group(GROUP_PKGNAME), nameMatcher.group(GROUP_LEAFEXTENSION).toLowerCase()); } else { result = new ArchiveEntryResult(Action.INVALID, "ignoring archive entry as the payload was too long"); } } else { result = new ArchiveEntryResult(Action.INVALID, "ignoring archive entry as the form of the name is invalid"); } row[CSV_COLUMN_ACTION] = result.action.name(); row[CSV_COLUMN_MESSAGE] = StringUtils.trimToEmpty(result.message); writer.writeNext(row); } else { LOGGER.debug("ignoring directory from archive; [{}]", archiveEntry.getName()); } } }