List of usage examples for org.apache.commons.lang3 StringUtils replaceChars
public static String replaceChars(final String str, final String searchChars, String replaceChars)
Replaces multiple characters in a String in one go.
From source file:com.xpn.xwiki.internal.skin.WikiSkinUtils.java
private BaseProperty<ObjectPropertyReference> getSkinResourceProperty(String resource, XWikiDocument skinDocument) {/*from w w w. j a v a2 s . c o m*/ // Try parsing the object property BaseObject skinObject = skinDocument.getXObject(SKINCLASS_REFERENCE); if (skinObject != null) { BaseProperty<ObjectPropertyReference> resourceProperty = (BaseProperty<ObjectPropertyReference>) skinObject .safeget(resource); // If not found try by replacing '/' with '.' if (resourceProperty == null) { String escapedTemplateName = StringUtils.replaceChars(resource, '/', '.'); resourceProperty = (BaseProperty<ObjectPropertyReference>) skinObject.safeget(escapedTemplateName); } if (resourceProperty != null) { Object value = resourceProperty.getValue(); if (value instanceof String && StringUtils.isNotEmpty((String) value)) { return resourceProperty; } } } return null; }
From source file:com.textocat.textokit.morph.ruscorpora.RusCorporaXmlContentHandler.java
private String preprocessChars(String str) { // normalize line endings return StringUtils.replaceChars(str, "\r\n", ""); }
From source file:gov.nih.nci.caintegrator.external.biodbnet.BioDbNetSearchImpl.java
/** * Extracts the gene information from a line of bioDbNet gene search results. * @param line a gene search result line * @return the parsed gene// w w w.j av a 2 s . c o m */ private GeneResults extractGene(String[] line) { Matcher descrptionMatcher = DESCRIPTION_PATTERN.matcher(line[GENE_INFO_INDEX]); Matcher taxonMatcher = TAXON_PATTERN.matcher(line[TAXON_INDEX]); GeneResults gene = new GeneResults(); gene.setSymbol(line[GENE_SYMBOL_INDEX]); if (NumberUtils.isNumber(line[GENE_ID_INDEX])) { gene.setGeneId(Long.valueOf(line[GENE_ID_INDEX])); } gene.setDescription(getValue(descrptionMatcher)); gene.setAliases(StringUtils.trim(StringUtils.replaceChars(line[GENE_SYNONYM_INDEX], ';', ','))); gene.setTaxon(getValue(taxonMatcher)); return gene; }
From source file:com.anrisoftware.sscontrol.httpd.domain.DomainImpl.java
private String convertName(String name) { return StringUtils.replaceChars(name, " .", "__"); }
From source file:atg.tools.dynunit.nucleus.NucleusUtils.java
/** * A convenience method for returning the configpath for a test. * pConfigDirectory is the top level name to be used for the configpath. * Returns a file in the baseConfigDirectory (or baseConfigDirectory + * "data") subdirectory of the the passed in class's location.<P> * <p/>//w ww . j a va 2s .c o m * The directory location is calculated as (in psuedo-code): * <code> * (classRelativeTo's package location) + "/" + (pConfigDirectory or "data") + "/config" * </code> * * @param classRelativeTo * the class whose package the config/data * (or baseConfigDirectory/data) should be relative in. * @param baseConfigDirectory * the base configuration directory If null, * uses "config". * @param createDirectory * whether to create the config/data subdirectory if * it does not exist. * * @return The calculated configuration path. */ public static File getConfigPath(Class classRelativeTo, String baseConfigDirectory, boolean createDirectory) { Map<String, File> baseConfigToFile = configPath.get(classRelativeTo); if (baseConfigToFile == null) { baseConfigToFile = new ConcurrentHashMap<String, File>(); configPath.put(classRelativeTo, baseConfigToFile); } File fileFound = baseConfigToFile.get(baseConfigDirectory); if (!baseConfigToFile.containsKey(baseConfigDirectory)) { String configdirname = "config"; String packageName = StringUtils.replaceChars(classRelativeTo.getPackage().getName(), '.', '/'); if (baseConfigDirectory != null) { configdirname = baseConfigDirectory; } String configFolder = packageName + "/data/" + configdirname; URL dataURL = classRelativeTo.getClassLoader().getResource(configFolder); // Mkdir if (dataURL == null) { URL root = classRelativeTo.getClassLoader().getResource(packageName); File f = null; if (root != null) { f = new File(root.getFile()); } File f2 = new File(f, "/data/" + configdirname); if (createDirectory) { f2.mkdirs(); } dataURL = NucleusUtils.class.getClassLoader().getResource(configFolder); if (dataURL == null) { System.err.println("Warning: Could not find resource \"" + configFolder + "\" in CLASSPATH"); } } if (dataURL != null) {// check if this URL is contained within a jar file // if so, extract to a temp dir, otherwise just return // the directory fileFound = extractJarDataURL(dataURL); baseConfigToFile.put(baseConfigDirectory, fileFound); } } if (fileFound != null) { System.setProperty("atg.configpath", fileFound.getAbsolutePath()); } return fileFound; }
From source file:com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.java
private Optional<String> parseValidVersion(final String version) { String validVersion = null;//from ww w . j av a2 s. c o m if (version.endsWith(VERSION_SUFFIX) && StringUtils.containsNone(version, FUZZY_VERSION_CHARACTERS)) { validVersion = StringUtils.replaceChars(version, VERSION_CHARACTERS, "").trim(); } return Optional.ofNullable(validVersion); }
From source file:com.netflix.genie.server.jobmanager.impl.JobManagerImpl.java
/** * Set/initialize environment variables for this job. * * @param processBuilder The process builder to use * @throws GenieException if there is any error in initialization *//* www . ja v a 2 s . com*/ protected void setupCommonProcess(final ProcessBuilder processBuilder) throws GenieException { LOG.info("called"); //Get the directory to stage all the work out of final String baseUserWorkingDir = this.getBaseUserWorkingDirectory(); //Save the base user working directory processBuilder.environment().put("BASE_USER_WORKING_DIR", baseUserWorkingDir); //Set the process working directory processBuilder.directory(this.createWorkingDirectory(baseUserWorkingDir)); //Copy any attachments from the job. this.copyAttachments(); LOG.info("Setting job working dir , conf dir and jar dir"); // setup env for current job, conf and jar directories directories processBuilder.environment().put("CURRENT_JOB_WORKING_DIR", this.jobDir); processBuilder.environment().put("CURRENT_JOB_CONF_DIR", this.jobDir + "/conf"); processBuilder.environment().put("CURRENT_JOB_JAR_DIR", this.jobDir + "/jars"); if (this.job.getFileDependencies() != null && !this.job.getFileDependencies().isEmpty()) { processBuilder.environment().put("CURRENT_JOB_FILE_DEPENDENCIES", StringUtils.replaceChars(this.job.getFileDependencies(), ',', ' ')); } // set the cluster related conf files processBuilder.environment().put("S3_CLUSTER_CONF_FILES", convertCollectionToString(this.cluster.getConfigs())); this.setCommandAndApplicationForJob(processBuilder); if (StringUtils.isNotBlank(this.job.getEnvPropFile())) { processBuilder.environment().put("JOB_ENV_FILE", this.job.getEnvPropFile()); } // this is for the generic joblauncher.sh to use to create username // on the machine if needed processBuilder.environment().put("USER_NAME", this.job.getUser()); processBuilder.environment().put("GROUP_NAME", this.getGroupName()); // set the java home final String javaHome = ConfigurationManager.getConfigInstance() .getString("com.netflix.genie.server.java.home"); if (StringUtils.isNotBlank(javaHome)) { processBuilder.environment().put("JAVA_HOME", javaHome); } // Set an ARN if one is available for role assumption with S3 final String arn = ConfigurationManager.getConfigInstance() .getString("com.netflix.genie.server.aws.iam.arn"); if (StringUtils.isNotBlank(arn)) { processBuilder.environment().put("ARN", arn); } // set the genie home final String genieHome = ConfigurationManager.getConfigInstance() .getString("com.netflix.genie.server.sys.home"); if (StringUtils.isBlank(genieHome)) { final String msg = "Property com.netflix.genie.server.sys.home is not set correctly"; LOG.error(msg); throw new GenieServerException(msg); } processBuilder.environment().put("XS_SYSTEM_HOME", genieHome); // set the archive location // unless user has explicitly requested for it to be disabled if (!this.job.isDisableLogArchival()) { final String s3ArchiveLocation = ConfigurationManager.getConfigInstance() .getString("com.netflix.genie.server.s3.archive.location"); if (StringUtils.isNotBlank(s3ArchiveLocation)) { processBuilder.environment().put("S3_ARCHIVE_LOCATION", s3ArchiveLocation); } } }
From source file:cgeo.geocaching.connector.gc.GCParser.java
private static Float parseStars(final String value) { final float floatValue = Float.parseFloat(StringUtils.replaceChars(value, ',', '.')); return floatValue >= 0.5 && floatValue <= 5.0 ? floatValue : null; }
From source file:com.nridge.core.base.field.Field.java
/** * Returns a field name that has been derived from the title. This * method will handle the conversion as follows: * * <ul>//from w w w .j a va 2 s . c o m * <li>Id becomes id</li> * <li>Employee Name becomes employee_name</li> * <li>Federated Name becomes federated_name</li> * </ul> * * The logic will ignore any other conventions and simply pass * the original character forward. * * @param aTitle Title string to convert. * * @return Field name. */ public static String titleToName(String aTitle) { if (StringUtils.isNotEmpty(aTitle)) { String fieldName = StringUtils.replaceChars(aTitle.toLowerCase(), StrUtl.CHAR_SPACE, StrUtl.CHAR_UNDERLINE); fieldName = StringUtils.replaceChars(fieldName, StrUtl.CHAR_HYPHEN, StrUtl.CHAR_UNDERLINE); fieldName = StringUtils.replaceChars(fieldName, StrUtl.CHAR_PAREN_OPEN, StrUtl.CHAR_UNDERLINE); fieldName = StringUtils.replaceChars(fieldName, StrUtl.CHAR_PAREN_CLOSE, StrUtl.CHAR_UNDERLINE); fieldName = StringUtils.replaceChars(fieldName, StrUtl.CHAR_BRACKET_OPEN, StrUtl.CHAR_UNDERLINE); fieldName = StringUtils.replaceChars(fieldName, StrUtl.CHAR_BRACKET_CLOSE, StrUtl.CHAR_UNDERLINE); fieldName = StrUtl.removeDuplicateChar(fieldName, StrUtl.CHAR_UNDERLINE); if (StrUtl.endsWithChar(fieldName, StrUtl.CHAR_UNDERLINE)) fieldName = StrUtl.trimLastChar(fieldName); return fieldName; } else return aTitle; }
From source file:com.joyent.manta.util.MantaUtils.java
/** * Naively converts a collection of objects to a single CSV string. * Warning: this doesn't escape./*from w ww .ja v a2 s . co m*/ * @param stringable collection of objects with implemented toString methods * @return CSV string or empty string */ public static String csv(final Iterable<?> stringable) { if (stringable == null) { return ""; } final StringBuilder builder = new StringBuilder(); Iterator<?> itr = stringable.iterator(); while (itr.hasNext()) { final Object o = itr.next(); if (o == null) { continue; } final String value; if (o instanceof InetAddress) { value = ((InetAddress) o).getHostAddress(); } else if (o instanceof Map) { StringBuilder sb = new StringBuilder(); @SuppressWarnings({ "unchecked", "rawtypes" }) final Map map = (Map) o; @SuppressWarnings("unchecked") final Iterator<Map.Entry<?, ?>> mapItr = (Iterator<Map.Entry<?, ?>>) map.entrySet().iterator(); while (mapItr.hasNext()) { Map.Entry<?, ?> entry = mapItr.next(); sb.append("[").append(String.valueOf(entry.getKey())).append("=").append(entry.getValue()) .append("]"); if (mapItr.hasNext()) { sb.append(" "); } } value = sb.toString(); } else { value = o.toString(); } // Strip any commas out of the string builder.append(StringUtils.replaceChars(value, ',', ' ')); if (itr.hasNext()) { builder.append(", "); } } return builder.toString(); }