/** * 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 {@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); }
@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")); }
/** * 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); }
/** * 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); }
/** * 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(String text) throws IllegalArgumentException { if (StringUtils.isBlank(text)) { super.setValue(null); } else if(Pattern.matches("\\d+", text)) { setValue(new Date(Long.parseLong(text))); }else { Date value = DatetimeOpt.smartPraseDate(text); setValue(value); } }
@Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.isBlank(text)) { super.setValue(null); } else if(Pattern.matches("\\d+", text)) { setValue(new Timestamp(Long.parseLong(text))); }else { Date dt = DatetimeOpt.smartPraseDate(text); if(dt!=null){ Timestamp value = new Timestamp(dt.getTime() ); setValue(value); }else setValue(null); } }
@Override public void setAsText(String text) throws IllegalArgumentException { if (StringUtils.isBlank(text)) { super.setValue(null); } else if(Pattern.matches("\\d+", text)) { setValue(new Date(Long.parseLong(text))); }else { Date value = DatetimeOpt.convertToSqlDate( DatetimeOpt.smartPraseDate(text)); setValue(value); } }