List of usage examples for org.apache.commons.lang StringUtils replaceChars
public static String replaceChars(String str, String searchChars, String replaceChars)
Replaces multiple characters in a String in one go.
From source file:com.haulmont.cuba.web.toolkit.ui.CubaDateField.java
@Override protected Date handleUnparsableDateString(String dateString) throws Converter.ConversionException { if (Objects.equals(dateString, StringUtils.replaceChars(getState(false).dateMask, "#U", "__"))) { return null; }/*from w w w . j a va 2 s . c om*/ markAsDirty(); return MARKER_DATE; }
From source file:info.magnolia.content2bean.impl.DescriptorFileBasedTypeMapping.java
protected void processFile(String fileName) { Properties props = new Properties(); InputStream stream = null;/*w ww.j ava2 s.c o m*/ try { stream = ClasspathResourcesUtil.getStream(fileName); props.load(stream); } catch (IOException e) { log.error("can't read collection to bean information " + fileName, e); } IOUtils.closeQuietly(stream); String className = StringUtils.replaceChars(fileName, File.separatorChar, '.'); className = StringUtils.removeStart(className, "."); className = StringUtils.removeEnd(className, ".content2bean"); try { Class<?> typeClass = Classes.getClassFactory().forName(className); TypeDescriptor typeDescriptor = processProperties(typeClass, props); addTypeDescriptor(typeClass, typeDescriptor); } catch (Exception e) { log.error("can't instantiate type descriptor for " + className, e); } }
From source file:hydrograph.ui.parametergrid.utils.ParameterFileManager.java
private Map<String, String> updatePropertyMap(Map<String, String> parameterMap) { Map<String, String> map = new LinkedHashMap<>(parameterMap); for (Entry<String, String> entry : parameterMap.entrySet()) { if (StringUtils.contains(entry.getValue(), ESCAPE_CHAR)) { map.put(entry.getKey(), StringUtils.replaceChars(entry.getValue(), ESCAPE_CHAR, BACKWARD_SLASH)); }// w w w. ja v a 2s . c om } return map; }
From source file:de.tudarmstadt.ukp.clarin.webanno.brat.project.PreferencesUtil.java
/** * Set annotation preferences of users for a given project such as window size, annotation * layers,... reading from the file system. * * @param aUsername/*from w ww . j a v a 2 s. c o m*/ * The {@link User} for whom we need to read the preference (preferences are stored * per user) * @param aRepositoryService the repository service. * @param aAnnotationService the annotation service. * @param aBModel * The {@link BratAnnotatorModel} that will be populated with preferences from the * file * @param aMode the mode. * @throws BeansException hum? * @throws IOException hum? */ public static void setAnnotationPreference(String aUsername, RepositoryService aRepositoryService, AnnotationService aAnnotationService, BratAnnotatorModel aBModel, Mode aMode) throws BeansException, IOException { AnnotationPreference preference = new AnnotationPreference(); BeanWrapper wrapper = new BeanWrapperImpl(preference); // get annotation preference from file system try { for (Entry<Object, Object> entry : aRepositoryService.loadUserSettings(aUsername, aBModel.getProject()) .entrySet()) { String property = entry.getKey().toString(); int index = property.lastIndexOf("."); String propertyName = property.substring(index + 1); String mode = property.substring(0, index); if (wrapper.isWritableProperty(propertyName) && mode.equals(aMode.getName())) { if (AnnotationPreference.class.getDeclaredField(propertyName) .getGenericType() instanceof ParameterizedType) { List<String> value = Arrays .asList(StringUtils.replaceChars(entry.getValue().toString(), "[]", "").split(",")); if (!value.get(0).equals("")) { wrapper.setPropertyValue(propertyName, value); } } else { wrapper.setPropertyValue(propertyName, entry.getValue()); } } } aBModel.setPreferences(preference); // Get tagset using the id, from the properties file aBModel.getAnnotationLayers().clear(); if (preference.getAnnotationLayers() != null) { for (Long id : preference.getAnnotationLayers()) { aBModel.getAnnotationLayers().add(aAnnotationService.getLayer(id)); } } } // no preference found catch (Exception e) { /* * // disable corefernce annotation for correction/curation pages for 0.4.0 release * List<TagSet> tagSets = aAnnotationService.listTagSets(aBModel.getProject()); * List<TagSet> corefTagSets = new ArrayList<TagSet>(); List<TagSet> noFeatureTagSet = * new ArrayList<TagSet>(); for (TagSet tagSet : tagSets) { if (tagSet.getLayer() == * null || tagSet.getFeature() == null) { noFeatureTagSet.add(tagSet); } else if * (tagSet.getLayer().getType().equals(ChainAdapter.CHAIN)) { corefTagSets.add(tagSet); * } } * * if (aMode.equals(Mode.CORRECTION) || aMode.equals(Mode.AUTOMATION) || * aMode.equals(Mode.CURATION)) { tagSets.removeAll(corefTagSets); } * tagSets.remove(noFeatureTagSet); aBModel.setAnnotationLayers(new * HashSet<TagSet>(tagSets)); */ /* * abAnnotatorModel.setAnnotationLayers(new HashSet<TagSet>(aAnnotationService * .listTagSets(abAnnotatorModel.getProject()))); */ List<AnnotationLayer> layers = aAnnotationService.listAnnotationLayer(aBModel.getProject()); aBModel.setAnnotationLayers(layers); } }
From source file:net.mikaboshi.intra_mart.tools.log_stats.ant.ParserParameterDataType.java
public void setEnd(String end) throws BuildException { end = AntParameterUtil.parseToday(end); if (end != null) { end = StringUtils.replaceChars(end, '/', '-'); if (end.length() == 10) { end += " 24:00"; }// w w w .ja v a 2 s. co m } try { this.end = this.dateFormat.parse(end); } catch (ParseException e) { throw new BuildException("end's date format is invalid : " + end); } }
From source file:com.marvelution.bamboo.plugins.sonar.tasks.SonarRunnerConfig.java
/** * Constructor//from w ww. j av a 2 s. c o m * * @param taskContext the {@link TaskContext} * @param capabilityContext the {@link CapabilityContext} * @param environmentVariableAccessor the {@link EnvironmentVariableAccessor} implementation */ public SonarRunnerConfig(TaskContext taskContext, CapabilityContext capabilityContext, EnvironmentVariableAccessor environmentVariableAccessor) { builderLabel = ((String) Preconditions.checkNotNull( taskContext.getConfigurationMap().get(CFG_BUILDER_LABEL), "Builder label is not defined")); builderPath = ((String) Preconditions.checkNotNull( capabilityContext.getCapabilityValue(SONAR_RUNNER_PREFIX + "." + builderLabel), "Builder path is not defined")); environmentVariables = ((String) taskContext.getConfigurationMap().get(CFG_ENVIRONMENT_VARIABLES)); workingDirectory = taskContext.getWorkingDirectory(); commandline.add(getSonarRunnerExecutable(builderPath)); if (StringUtils.isNotBlank(taskContext.getConfigurationMap().get(CFG_SONAR_EXTRA_CUSTOM_PARAMETERS))) { commandline.addAll(CommandlineStringUtils.tokeniseCommandline(StringUtils.replaceChars( (String) taskContext.getConfigurationMap().get(CFG_SONAR_EXTRA_CUSTOM_PARAMETERS), "\r\n", " "))); } environment.putAll(environmentVariableAccessor.splitEnvironmentAssignments(environmentVariables, false)); environment.put(SONAR_RUNNER_HOME, builderPath); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimeField.java
private Object validateRawValue(String value) throws NumberFormatException, ParseException { if (value.equals(StringUtils.replaceChars(mask, "#U", "__"))) { return null; }// w ww .java 2 s . c om SimpleDateFormat sdf = new SimpleDateFormat(timeFormat); sdf.setLenient(false); try { Date parsedValue = sdf.parse(value); Class targetType = null; if (datasource != null && metaPropertyPath != null) { targetType = metaPropertyPath.getRangeJavaClass(); } if (targetType == java.sql.Time.class) { return new Time(parsedValue.getTime()); } if (targetType == java.sql.Date.class) { log.warn("Do not use java.sql.Date with time field"); return new java.sql.Date(parsedValue.getTime()); } return parsedValue; } catch (ParseException e) { showValidationMessage(); return prevValue; } }
From source file:gov.nih.nci.caarray.magetab.sdrf.SdrfColumnType.java
static SdrfColumnType get(String name) { String enumName = StringUtils.replaceChars(name, ' ', '_').toUpperCase(); return valueOf(enumName); }
From source file:com.redhat.rhn.taskomatic.task.repomd.RepomdWriter.java
/** * Removes all control characters from passed in String. * @param pkgId package id/* w ww.ja va 2s . co m*/ * @param input char input */ protected static String sanitize(Long pkgId, String input) { if (StringUtils.containsNone(input, CONTROL_CHARS)) { return input; } if (log.isDebugEnabled()) { log.debug("Package " + pkgId + " metadata contains control chars, cleanup required: " + input); } return StringUtils.replaceChars(input, CONTROL_CHARS, CONTROL_CHARS_REPLACEMENT); }
From source file:de.anhquan.codegen.ClassGenerator.java
protected void generate(ClassTableType tbl) { if (tbl == null) throw new IllegalArgumentException("ClassTableType cannot be NULL"); List<ClassDescriptionType> classes = tbl.getClassDescriptions(); String targetDir = tbl.getTargetDirectory(); for (ClassDescriptionType cls : classes) { ctx.put(CLASS, cls);//from www .j av a 2s.c om ctx.put(CLASS_TABLE, tbl); String template = cls.getTemplate(); if (template == null) { log.warn("Template to generate class " + cls.getName() + " has not been found. SKIP IT"); continue; } String className = cls.getName(); if (!StringUtils.isEmpty(className)) { log.info("Generating class '" + cls.getName() + "'"); String packageName = cls.getPackage(); String targetPackageDir = StringUtils.replaceChars(packageName, ".", "/"); String path = targetDir + "/" + targetPackageDir + "/"; try { generate(template, path, className, ".java"); } catch (IOException e) { log.error(e.getMessage()); } } } }