@Test public void nullValue() { PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(null); Properties p = (Properties) pe.getValue(); assertEquals(0, p.size()); }
@Test public void usingMapAsValueSource() throws Exception { Map<String, String> map = new HashMap<>(); map.put("one", "1"); map.put("two", "2"); map.put("three", "3"); PropertiesEditor pe = new PropertiesEditor(); pe.setValue(map); Object value = pe.getValue(); assertNotNull(value); assertTrue(value instanceof Properties); Properties props = (Properties) value; assertEquals(3, props.size()); assertEquals("1", props.getProperty("one")); assertEquals("2", props.getProperty("two")); assertEquals("3", props.getProperty("three")); }
this.defaultEditors.put(Path.class, new PathEditor()); this.defaultEditors.put(Pattern.class, new PatternEditor()); this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Reader.class, new ReaderEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor());
super.setAsText( text );
/** * Convert {@link String} into {@link Properties}, considering it as * properties content. * @param text the text to be so converted */ @Override public void setAsText(@Nullable String text) throws IllegalArgumentException { Properties props = new Properties(); if (text != null) { try { // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. props.load(new ByteArrayInputStream(text.getBytes(StandardCharsets.ISO_8859_1))); } catch (IOException ex) { // Should never happen. throw new IllegalArgumentException( "Failed to parse [" + text + "] into Properties", ex); } } setValue(props); }
/** * Convert String into Properties. */ public void setAsText(String text) throws IllegalArgumentException { if (text == null) { throw new IllegalArgumentException("Cannot set Properties to null"); } Properties props = new Properties(); try { props.load(new ByteArrayInputStream(text.getBytes())); dropComments(props); } catch (IOException ex) { // shouldn't happen throw new IllegalArgumentException("Failed to parse [" + text + "] into Properties"); } setValue(props); }
@Override public void setAsText(@Nullable String text) throws IllegalArgumentException { if (text == null) { throw new IllegalArgumentException("JndiTemplate cannot be created from null string"); } if ("".equals(text)) { // empty environment setValue(new JndiTemplate()); } else { // we have a non-empty properties string this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new JndiTemplate(props)); } }
this.defaultEditors.put(Path.class, new PathEditor()); this.defaultEditors.put(Pattern.class, new PatternEditor()); this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Reader.class, new ReaderEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor());
super.setAsText( text );
/** * Convert {@link String} into {@link Properties}, considering it as * properties content. * @param text the text to be so converted */ @Override public void setAsText(@Nullable String text) throws IllegalArgumentException { Properties props = new Properties(); if (text != null) { try { // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. props.load(new ByteArrayInputStream(text.getBytes(StandardCharsets.ISO_8859_1))); } catch (IOException ex) { // Should never happen. throw new IllegalArgumentException( "Failed to parse [" + text + "] into Properties", ex); } } setValue(props); }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
this.defaultEditors.put(Locale.class, new LocaleEditor()); this.defaultEditors.put(Pattern.class, new PatternEditor()); this.defaultEditors.put(Properties.class, new PropertiesEditor()); this.defaultEditors.put(Resource[].class, new ResourceArrayPropertyEditor()); this.defaultEditors.put(TimeZone.class, new TimeZoneEditor());
/** * Convert {@link String} into {@link Properties}, considering it as * properties content. * @param text the text to be so converted */ @Override public void setAsText(String text) throws IllegalArgumentException { Properties props = new Properties(); if (text != null) { try { // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. props.load(new ByteArrayInputStream(text.getBytes("ISO-8859-1"))); } catch (IOException ex) { // Should never happen. throw new IllegalArgumentException( "Failed to parse [" + text + "] into Properties", ex); } } setValue(props); }
@Test public void emptyString() { PropertiesEditor pe = new PropertiesEditor(); pe.setAsText(""); Properties p = (Properties) pe.getValue(); assertTrue("empty string means empty properties", p.isEmpty()); }
@Override public void setAsText(@Nullable String text) throws IllegalArgumentException { if (text == null) { throw new IllegalArgumentException("JndiTemplate cannot be created from null string"); } if ("".equals(text)) { // empty environment setValue(new JndiTemplate()); } else { // we have a non-empty properties string this.propertiesEditor.setAsText(text); Properties props = (Properties) this.propertiesEditor.getValue(); setValue(new JndiTemplate(props)); } }
public void registerCustomEditors(PropertyEditorRegistry registry) { for (Map.Entry<Class<?>, Class<? extends PropertyEditor>> entry : editors.entrySet()) { Class<?> type = entry.getKey(); PropertyEditor editorInstance; editorInstance = BeanUtils.instantiate(entry.getValue()); registry.registerCustomEditor(type, editorInstance); } // register non-externalized types registry.registerCustomEditor(Dictionary.class, new CustomMapEditor(Hashtable.class)); registry.registerCustomEditor(Properties.class, new PropertiesEditor()); registry.registerCustomEditor(Class.class, new ClassEditor(userClassLoader)); registry.registerCustomEditor(Class[].class, new ClassArrayEditor(userClassLoader)); } }
/** * Convert {@link String} into {@link Properties}, considering it as * properties content. * @param text the text to be so converted */ @Override public void setAsText(String text) throws IllegalArgumentException { Properties props = new Properties(); if (text != null) { try { // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. props.load(new ByteArrayInputStream(text.getBytes("ISO-8859-1"))); } catch (IOException ex) { // Should never happen. throw new IllegalArgumentException( "Failed to parse [" + text + "] into Properties", ex); } } setValue(props); }
@Test public void oneProperty() { String s = "foo=bar"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); Properties p = (Properties) pe.getValue(); assertTrue("contains one entry", p.entrySet().size() == 1); assertTrue("foo=bar", p.get("foo").equals("bar")); }