List of usage examples for org.apache.commons.collections ExtendedProperties containsKey
public synchronized boolean containsKey(Object key)
From source file:it.unimi.di.big.mg4j.query.HttpQueryServer.java
/** Sets the given extended properties so that velocity finds its files either * by classpath, or by absolute filename, or by relative filename. * // w ww. j a v a2 s . c o m * @param p the extended properties of the servlet, obtained <i>via</i> * <samp>super.loadConfiguration()</samp>. * * @return <code>p</code> the additional items setting a liberal scheme for resource loading. */ public static ExtendedProperties setLiberalResourceLoading(final ExtendedProperties p) { // TODO: This is ugly. If anybody can find how to set the ServletConfig from Jetty, just let me know. if (!p.containsKey("resource.loader")) { p.setProperty("resource.loader", "class, current, absolute"); p.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); p.setProperty("current.resource.loader.class", FileResourceLoader.class.getName()); p.setProperty("current.resource.loader.path", System.getProperty("user.dir")); p.setProperty("absolute.resource.loader.class", FileResourceLoader.class.getName()); p.setProperty("absolute.resource.loader.path", ""); p.setProperty("input.encoding", "utf-8"); p.setProperty("output.encoding", "utf-8"); p.setProperty("default.contentType", "text/html; charset=UTF-8"); } return p; }
From source file:autohit.call.Call_GET_SPROP.java
/** * Execute it.// www .j a v a 2 s . c o m * @return the result or null if there is no result */ public String call() throws CallException { String name; String result = Constants.EMPTY_LEFT; try { name = this.requiredString("name"); ExtendedProperties ep = sc.getPropertiesSet(); if (ep.containsKey(name)) { result = ep.getString(name); } } catch (CallException e) { throw e; } catch (Exception ex) { //any other is REAL bad throw new CallException(this.format("Serious fault. error=" + ex.getMessage()), CallException.CODE_CALL_UNRECOVERABLE_FAULT, ex); } return result; }
From source file:autohit.common.Utils.java
/** * Merge a file with properties. It will overwrite an existing file. * This is not exactly FAST./* ww w .j a v a2 s. com*/ * @param source source file * @param dest destination file * @param props properties that are candidates for substitution * @return string containing errors or messages */ public static String merge(String source, String dest, ExtendedProperties props) { int state = STATE_FRESH; BufferedReader inBR = null; BufferedWriter outT = null; int workingC; StringBuffer cBuf = null; String theVar = null; String ts = null; StringBuffer messages = new StringBuffer(); String overwrite = " "; // Read and fix try { // Clear an existing file File destf = new File(dest); if (destf.exists()) { destf.delete(); overwrite = " [overwrite] "; } inBR = new BufferedReader(new FileReader(source)); outT = new BufferedWriter(new FileWriter(dest)); // start the engine workingC = inBR.read(); while ((workingC >= 0) && (workingC < MORONIC_TOP_VALUE)) { switch (state) { case STATE_FRESH: if (workingC == Constants.CONFIG_OPEN) state = STATE_FRONT; else outT.write(workingC); break; case STATE_FRONT: if (workingC == Constants.CONFIG_OPEN) { state = STATE_READ; cBuf = new StringBuffer(); } else { state = STATE_FRESH; outT.write(Constants.CONFIG_OPEN); outT.write(workingC); } break; case STATE_READ: if (workingC == Constants.CONFIG_CLOSE) { state = STATE_TAIL; } else { cBuf.append((char) workingC); } break; case STATE_TAIL: if (workingC == Constants.CONFIG_CLOSE) { state = STATE_FRESH; theVar = cBuf.toString(); if (props.containsKey(theVar)) { ts = (String) props.get(theVar); outT.write(ts, 0, ts.length()); } else { outT.write(Constants.CONFIG_BLANK); } } else { outT.write(Constants.CONFIG_CLOSE); outT.write(workingC); } break; } // end case workingC = inBR.read(); } } catch (Exception e) { // Might just be EOF //System.out.println(e); } finally { try { inBR.close(); outT.close(); if (state != STATE_FRESH) { messages.append( "Bad File. Incomplete escape <<>> in file=" + source + Constants.CRUDE_SEPERATOR); messages.append("......... Destination file might be corrupt. file=" + dest + Constants.CRUDE_SEPERATOR); } messages.append("Merged file to=" + dest + overwrite + Constants.CRUDE_SEPERATOR); } catch (Exception e) { messages.append("Catastrophic error merging" + source + Constants.CRUDE_SEPERATOR); messages.append( "......... Destination file might be corrupt. file=" + dest + Constants.CRUDE_SEPERATOR); } } return messages.toString(); }
From source file:org.opencms.configuration.TestParameterConfiguration.java
/** * Test reading the parameter configuration.<p> * /*from w ww . j a v a 2s. co m*/ * @throws Exception */ public void testReadParameterConfiguration() throws Exception { String testPropPath = "org/opencms/configuration/opencms-test.properties"; URL url = this.getClass().getClassLoader().getResource(testPropPath); File file = new File(url.getPath()); System.out.println("URL: " + url); System.out.println("File: " + file); // make sure the test properties file is found assertTrue("Test property file '" + file.getAbsolutePath() + "' not found", file.exists()); CmsParameterConfiguration cmsProp = new CmsParameterConfiguration(file.getAbsolutePath()); assertEquals("C:\\dev\\workspace\\opencms-core\\test\\data", cmsProp.get("test.path.one")); // test some of the more advanced features assertEquals(4, cmsProp.getList("test.list").size()); assertEquals(3, cmsProp.getList("test.otherlist").size()); assertEquals("comma, escaped with \\ backslash", cmsProp.get("test.escaping")); assertEquals("this is a long long long long long long line!", cmsProp.get("test.multiline")); // test compatibility with Collection Extended Properties ExtendedProperties extProp = new ExtendedProperties(file.getAbsolutePath()); assertEquals(extProp.size(), cmsProp.size()); for (String key : cmsProp.keySet()) { Object value = cmsProp.getObject(key); assertTrue("Key '" + key + "' not found in CmsConfiguration", extProp.containsKey(key)); assertTrue("Objects for '" + key + "' not equal", value.equals(extProp.getProperty(key))); } }