/** * Convert a standard properties class into a configuration class. * <p> * NOTE: From Commons Collections 3.2 this method will pick up * any default parent Properties of the specified input object. * * @param props the properties object to convert * @return new ExtendedProperties created from props */ public static ExtendedProperties convertProperties(Properties props) { ExtendedProperties c = new ExtendedProperties(); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String s = (String) e.nextElement(); c.setProperty(s, props.getProperty(s)); } return c; }
/** * Convert a standard properties class into a configuration class. * <p> * NOTE: From Commons Collections 3.2 this method will pick up * any default parent Properties of the specified input object. * * @param props the properties object to convert * @return new ExtendedProperties created from props */ public static ExtendedProperties convertProperties(Properties props) { ExtendedProperties c = new ExtendedProperties(); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String s = (String) e.nextElement(); c.setProperty(s, props.getProperty(s)); } return c; }
/** * Creates and loads the extended properties from the specified file. * * @param file the filename to load * @param defaultFile a second filename to load default values from * @throws IOException if a file error occurs */ public ExtendedProperties(String file, String defaultFile) throws IOException { this.file = file; basePath = new File(file).getAbsolutePath(); basePath = basePath.substring(0, basePath.lastIndexOf(fileSeparator) + 1); FileInputStream in = null; try { in = new FileInputStream(file); this.load(in); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) {} } if (defaultFile != null) { defaults = new ExtendedProperties(defaultFile); } }
/** * Creates and loads the extended properties from the specified file. * * @param file the filename to load * @param defaultFile a second filename to load default values from * @throws IOException if a file error occurs */ public ExtendedProperties(String file, String defaultFile) throws IOException { this.file = file; basePath = new File(file).getAbsolutePath(); basePath = basePath.substring(0, basePath.lastIndexOf(fileSeparator) + 1); FileInputStream in = null; try { in = new FileInputStream(file); this.load(in); } finally { try { if (in != null) { in.close(); } } catch (IOException ex) {} } if (defaultFile != null) { defaults = new ExtendedProperties(defaultFile); } }
ExtendedProperties c = new ExtendedProperties(); Iterator keys = getKeys(); boolean validSubset = false;
ExtendedProperties c = new ExtendedProperties(); Iterator keys = getKeys(); boolean validSubset = false;
public void testActiveSecurityManager() { SecurityManager manager = new SecurityManager() { public void checkPropertyAccess(String key) { if ("file.separator".equals(key)) { throw new SecurityException(); } } public void checkPermission(Permission perm) { } }; System.setSecurityManager(manager); try { ExtendedProperties properties = new ExtendedProperties(); assertNotNull(properties); } catch (Exception ex) { fail("failed to instantiate ExtendedProperties"); } finally { System.setSecurityManager(null); } }
public void testTrailingBackSlash() { ExtendedProperties ep1 = new ExtendedProperties(); try { /* initialize using: one=ONE two=TWO \\ three=THREE */ String s1 = "one=ONE\ntwo=TWO \\\\\nthree=THREE"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals("Trailing back-slashes not interpreted properly", 3, ep1.size()); assertEquals("Back-slash not escaped properly", "TWO \\", ep1.getString("two")); } catch (IOException ioe) { fail("There was an exception loading the EP"); } }
public void testMultipleSameKey1() throws Exception { ExtendedProperties ep1 = new ExtendedProperties(); /* initialize using: one=a one=b,c */ String s1 = "one=a\none=b,c\n"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); assertEquals(3, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals(3, ep1.getList("one").size()); assertEquals("a", ep1.getList("one").get(0)); assertEquals("b", ep1.getList("one").get(1)); assertEquals("c", ep1.getList("one").get(2)); }
public void testMultipleSameKey3() throws Exception { ExtendedProperties ep1 = new ExtendedProperties(); /* initialize using: one=a,b one=c */ String s1 = "one=a,b\none=c\n"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); assertEquals(3, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals(3, ep1.getList("one").size()); assertEquals("a", ep1.getList("one").get(0)); assertEquals("b", ep1.getList("one").get(1)); assertEquals("c", ep1.getList("one").get(2)); }
public void testMultipleSameKey2() throws Exception { ExtendedProperties ep1 = new ExtendedProperties(); /* initialize using: one=a,b one=c,d */ String s1 = "one=a,b\none=c,d\n"; byte[] bytes = s1.getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ep1.load(bais); assertEquals(1, ep1.size()); assertEquals(4, ep1.getVector("one").size()); assertEquals("a", ep1.getVector("one").get(0)); assertEquals("b", ep1.getVector("one").get(1)); assertEquals("c", ep1.getVector("one").get(2)); assertEquals("d", ep1.getVector("one").get(3)); assertEquals(4, ep1.getList("one").size()); assertEquals("a", ep1.getList("one").get(0)); assertEquals("b", ep1.getList("one").get(1)); assertEquals("c", ep1.getList("one").get(2)); assertEquals("d", ep1.getList("one").get(3)); }
public void testSaveAndLoad() { ExtendedProperties ep1 = new ExtendedProperties(); ExtendedProperties ep2 = new ExtendedProperties();
public void testMultipleSameKeyByCode() throws Exception { ExtendedProperties ep1 = new ExtendedProperties();
/** * Initialize the Velocity Runtime with the name of * ExtendedProperties object. * * @param Properties */ public void init(String configurationFile) throws Exception { overridingProperties = new ExtendedProperties(configurationFile); init(); }
ExtendedProperties extended = new ExtendedProperties(); Map<String, String> map = new HashMap<>(); map.put("customField", "customValue"); extended.setShared(map); event.setExtendedProperties(extended);
/** * Allows an external system to set a property in * the Velocity Runtime. * * @param key property key * @param value property value */ public void setProperty(String key, Object value) { if (overridingProperties == null) { overridingProperties = new ExtendedProperties(); } overridingProperties.setProperty(key, value); }
/** * Allows an external system to set a property in * the Velocity Runtime. * * @param key property key * @param value property value */ public void setProperty(String key, Object value) { if (overridingProperties == null) { overridingProperties = new ExtendedProperties(); } overridingProperties.setProperty(key, value); }
/** * Convert Singleton element {@link ExtendedProperties} from {@link Velocity} {@link Properties} * * @param velocityProperties {@link Velocity} {@link Properties} * @param propertyName the name of property * @return non-null {@link ExtendedProperties} */ protected static ExtendedProperties toSingletonExtendedProperties(Map<String, String> velocityProperties, String propertyName) { String library = velocityProperties.get(propertyName); ExtendedProperties extendedProperties = new ExtendedProperties(); if (StringUtils.hasText(library)) { extendedProperties.setProperty(propertyName, library); } return extendedProperties; }
/** * Initialize the Velocity Runtime with the name of * ExtendedProperties object. * * @param configurationFile * @throws Exception When an error occurs during initialization. */ public void init(String configurationFile) throws Exception { setProperties(new ExtendedProperties(configurationFile)); init(); }
/** * Loads an extended property file and performs unescaping of "," and "=" entries.<p> * * @param stream the input stream to read the properties from * * @return the initialized extended properties * * @throws IOException in case of IO errors */ public static ExtendedProperties loadProperties(InputStream stream) throws IOException { ExtendedProperties properties = new ExtendedProperties(); properties.load(stream); unescapeProperties(properties); return properties; }