List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:nl.armatiek.xslweb.web.servlet.XSLWebServlet.java
private void executeRequest(WebApp webApp, HttpServletRequest req, HttpServletResponse resp, OutputStream respOs) throws Exception { boolean developmentMode = webApp.getDevelopmentMode(); String requestXML = (String) req.getAttribute(Definitions.ATTRNAME_REQUESTXML); PipelineHandler pipelineHandler = (PipelineHandler) req.getAttribute(Definitions.ATTRNAME_PIPELINEHANDLER); ErrorListener errorListener = new TransformationErrorListener(resp, developmentMode); MessageWarner messageWarner = new MessageWarner(); List<PipelineStep> steps = pipelineHandler.getPipelineSteps(); if (steps == null || steps.isEmpty()) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource not found"); return;// w w w .j a v a 2s .c om } OutputStream os = (developmentMode) ? new ByteArrayOutputStream() : respOs; Properties outputProperties = getOutputProperties(webApp, errorListener, steps); Map<QName, XdmValue> baseStylesheetParameters = XSLWebUtils.getStylesheetParameters(webApp, req, resp, homeDir); addResponseTransformationStep(steps); Map<QName, XdmValue> extraStylesheetParameters = null; Source source = new StreamSource(new StringReader(requestXML)); Destination destination = null; for (int i = 0; i < steps.size(); i++) { PipelineStep step = steps.get(i); if (step instanceof SerializerStep) { break; } PipelineStep nextStep = (i < steps.size() - 1) ? steps.get(i + 1) : null; if (step instanceof TransformerStep) { String xslPath = null; if (step instanceof SystemTransformerStep) { xslPath = new File(homeDir, "common/xsl/" + ((TransformerStep) step).getXslPath()) .getAbsolutePath(); } else { xslPath = ((TransformerStep) step).getXslPath(); } XsltExecutable templates = webApp.getTemplates(xslPath, errorListener); Xslt30Transformer transformer = templates.load30(); transformer.getUnderlyingController().setMessageEmitter(messageWarner); transformer.setErrorListener(errorListener); Map<QName, XdmValue> stylesheetParameters = new HashMap<QName, XdmValue>(); stylesheetParameters.putAll(baseStylesheetParameters); XSLWebUtils.addStylesheetParameters(stylesheetParameters, ((TransformerStep) step).getParameters()); if (extraStylesheetParameters != null) { stylesheetParameters.putAll(extraStylesheetParameters); extraStylesheetParameters.clear(); } transformer.setStylesheetParameters(stylesheetParameters); destination = getDestination(webApp, req, resp, os, outputProperties, step, nextStep); transformer.applyTemplates(source, destination); } else if (step instanceof SchemaValidatorStep) { SchemaValidatorStep svStep = (SchemaValidatorStep) step; List<String> schemaPaths = svStep.getSchemaPaths(); Schema schema = webApp.getSchema(schemaPaths, errorListener); source = makeNodeInfoSource(source, webApp, errorListener); destination = null; Serializer serializer = webApp.getProcessor().newSerializer(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); serializer.setOutputStream(outputStream); serializer.setOutputProperty(Property.INDENT, "yes"); serializer.serializeNode(new XdmNode((NodeInfo) source)); Source validationSource = new StreamSource(new ByteArrayInputStream(outputStream.toByteArray())); Validator validator = schema.newValidator(); ValidatorErrorHandler errorHandler = new ValidatorErrorHandler( "Step: " + ((step.getName() != null) ? step.getName() : "noname")); validator.setErrorHandler(errorHandler); Properties properties = svStep.getProperties(); if (properties != null) { @SuppressWarnings("rawtypes") Enumeration names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); validator.setProperty(name, properties.getProperty(name)); } } Properties features = svStep.getProperties(); if (features != null) { @SuppressWarnings("rawtypes") Enumeration names = features.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); validator.setProperty(name, features.getProperty(name)); } } validator.validate(validationSource); Source resultsSource = errorHandler.getValidationResults(); if (resultsSource != null) { NodeInfo resultsNodeInfo = webApp.getConfiguration().buildDocumentTree(resultsSource) .getRootNode(); String xslParamName = svStep.getXslParamName(); if (xslParamName != null) { if (extraStylesheetParameters == null) { extraStylesheetParameters = new HashMap<QName, XdmValue>(); } extraStylesheetParameters.put(new QName(svStep.getXslParamNamespace(), xslParamName), new XdmNode(resultsNodeInfo)); } } } else if (step instanceof SchematronValidatorStep) { SchematronValidatorStep svStep = (SchematronValidatorStep) step; source = makeNodeInfoSource(source, webApp, errorListener); destination = null; /* Execute schematron validation */ XsltExecutable templates = webApp.getSchematron(svStep.getSchematronPath(), svStep.getPhase(), errorListener); Xslt30Transformer transformer = templates.load30(); transformer.getUnderlyingController().setMessageEmitter(messageWarner); transformer.setErrorListener(errorListener); XdmDestination svrlDest = new XdmDestination(); transformer.applyTemplates(source, svrlDest); String xslParamName = svStep.getXslParamName(); if (xslParamName != null) { if (extraStylesheetParameters == null) { extraStylesheetParameters = new HashMap<QName, XdmValue>(); } extraStylesheetParameters.put(new QName(svStep.getXslParamNamespace(), xslParamName), svrlDest.getXdmNode()); } } else if (step instanceof ResponseStep) { source = new StreamSource(new StringReader(((ResponseStep) step).getResponse())); continue; } if (destination instanceof SourceDestination) { /* Set source for next pipeline step: */ source = ((SourceDestination) destination).asSource(); } } if (developmentMode) { byte[] body = ((ByteArrayOutputStream) os).toByteArray(); IOUtils.copy(new ByteArrayInputStream(body), respOs); } }
From source file:org.eu.gasp.core.bootstrap.Bootstrap.java
@SuppressWarnings("unchecked") private void loadProperties() { InputStream input = null;/*from ww w .j a v a2 s .c o m*/ try { final File propFile = new File(propertyFilePath); if (!propFile.exists()) { log.debug("Properties file doesn't exist: " + propFile.getPath()); return; } input = new BufferedInputStream(new FileInputStream(propFile)); final Properties properties = new Properties(); properties.load(input); final String pluginsToStartProp = properties.getProperty("gasp.plugins.start"); if (!StringUtils.isBlank(pluginsToStartProp)) { pluginsToStart.addAll(Arrays.asList(pluginsToStartProp.split(" "))); } for (final Enumeration<String> elements = (Enumeration<String>) properties.propertyNames(); elements .hasMoreElements();) { final String key = elements.nextElement(); System.setProperty(key, properties.getProperty(key)); } log.info("Properties loaded from file: " + propFile.getPath()); } catch (Exception e) { log.warn("Error while loading properties", e); } finally { if (input != null) { try { input.close(); } catch (Exception ignore) { } } } }
From source file:NanoHTTPD.java
/** * Override this to customize the server. * <p>/*from ww w.j a v a 2s .c o m*/ * * (By default, this delegates to serveFile() and allows directory listing.) * * @parm uri Percent-decoded URI without parameters, for example "/index.cgi" * @parm method "GET", "POST" etc. * @parm parms Parsed, percent decoded parameters from URI and, in case of * POST, data. * @parm header Header entries, percent decoded * @return HTTP response, see class Response for details */ public Response serve(String uri, String method, Properties header, Properties parms) { System.out.println(method + " '" + uri + "' "); Enumeration e = header.propertyNames(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); System.out.println(" HDR: '" + value + "' = '" + header.getProperty(value) + "'"); } e = parms.propertyNames(); while (e.hasMoreElements()) { String value = (String) e.nextElement(); System.out.println(" PRM: '" + value + "' = '" + parms.getProperty(value) + "'"); } return serveFile(uri, header, new File("."), true); }
From source file:org.nuxeo.launcher.commons.text.TextTemplate.java
public Properties preprocessVars(Properties unprocessedVars) { Properties newVars = new Properties(unprocessedVars); boolean doneProcessing = false; int recursionLevel = 0; while (!doneProcessing) { doneProcessing = true;//from w w w . j a va 2s .c o m @SuppressWarnings("rawtypes") Enumeration newVarsEnum = newVars.propertyNames(); while (newVarsEnum.hasMoreElements()) { String newVarsKey = (String) newVarsEnum.nextElement(); String newVarsValue = newVars.getProperty(newVarsKey); Matcher m = PATTERN.matcher(newVarsValue); StringBuffer sb = new StringBuffer(); while (m.find()) { String embeddedVar = m.group(1); String value = newVars.getProperty(embeddedVar); if (value != null) { if (trim) { value = value.trim(); } String escapedValue = Matcher.quoteReplacement(value); m.appendReplacement(sb, escapedValue); } } m.appendTail(sb); String replacementValue = sb.toString(); if (!replacementValue.equals(newVarsValue)) { doneProcessing = false; newVars.put(newVarsKey, replacementValue); } } recursionLevel++; // Avoid infinite replacement loops if ((!doneProcessing) && (recursionLevel > MAX_RECURSION_LEVEL)) { break; } } return unescape(newVars); }
From source file:wicket.resource.PropertiesFactory.java
/** * Helper method to do the actual loading of resources if required. * //from w w w . jav a 2 s. com * @param key * The key for the resource * @param resourceStream * The properties file stream to load and begin to watch * @param componentClass * The class that resources are bring loaded for * @param style * The style to load resources for (see {@link wicket.Session}) * @param locale * The locale to load reosurces for * @return The map of loaded resources */ private synchronized Properties loadPropertiesFile(final String key, final IResourceStream resourceStream, final Class componentClass, final String style, final Locale locale) { // Make sure someone else didn't load our resources while we were // waiting for the synchronized lock on the method Properties props = propertiesCache.get(key); if (props != null) { return props; } // Do the resource load final java.util.Properties properties = new java.util.Properties(); if (resourceStream == null) { props = new Properties(key, ValueMap.EMPTY_MAP); } else { ValueMap strings = null; try { try { properties.load(new BufferedInputStream(resourceStream.getInputStream())); strings = new ValueMap(); Enumeration<?> enumeration = properties.propertyNames(); while (enumeration.hasMoreElements()) { String property = (String) enumeration.nextElement(); strings.put(property, properties.getProperty(property)); } } finally { resourceStream.close(); } } catch (ResourceStreamNotFoundException e) { log.warn("Unable to find resource " + resourceStream, e); strings = ValueMap.EMPTY_MAP; } catch (IOException e) { log.warn("Unable to access resource " + resourceStream, e); strings = ValueMap.EMPTY_MAP; } props = new Properties(key, strings); } return props; }
From source file:org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration.java
/** * Constructs a new <code>ExtenderConfiguration</code> instance. Locates the extender configuration, creates an * application context which will returned the extender items. * * @param extenderBundleContext extender OSGi bundle context */// w w w.j a va2 s . c om public void start(BundleContext extenderBundleContext) { Bundle bundle = extenderBundleContext.getBundle(); Properties properties = new Properties(createDefaultProperties()); Enumeration<?> enm = bundle.findEntries(EXTENDER_CFG_LOCATION, XML_PATTERN, false); if (enm == null) { log.info("No custom extender configuration detected; using defaults..."); synchronized (lock) { taskExecutor = createDefaultTaskExecutor(); shutdownTaskExecutor = createDefaultShutdownTaskExecutor(); eventMulticaster = createDefaultEventMulticaster(); contextEventListener = createDefaultApplicationContextListener(); } classLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle); } else { String[] configs = copyEnumerationToList(enm); log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs)); // create OSGi specific XML context ConfigurableOsgiBundleApplicationContext extenderAppCtx = new OsgiBundleXmlApplicationContext(configs); extenderAppCtx.setBundleContext(extenderBundleContext); extenderAppCtx.refresh(); synchronized (lock) { extenderConfiguration = extenderAppCtx; // initialize beans taskExecutor = extenderConfiguration.containsBean(TASK_EXECUTOR_NAME) ? extenderConfiguration.getBean(TASK_EXECUTOR_NAME, TaskExecutor.class) : createDefaultTaskExecutor(); shutdownTaskExecutor = extenderConfiguration.containsBean(SHUTDOWN_TASK_EXECUTOR_NAME) ? extenderConfiguration.getBean(SHUTDOWN_TASK_EXECUTOR_NAME, TaskExecutor.class) : createDefaultShutdownTaskExecutor(); eventMulticaster = extenderConfiguration.containsBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME) ? extenderConfiguration.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, OsgiBundleApplicationContextEventMulticaster.class) : createDefaultEventMulticaster(); contextCreator = extenderConfiguration.containsBean(CONTEXT_CREATOR_NAME) ? extenderConfiguration.getBean(CONTEXT_CREATOR_NAME, OsgiApplicationContextCreator.class) : null; contextEventListener = extenderConfiguration.containsBean(CONTEXT_LISTENER_NAME) ? extenderConfiguration.getBean(CONTEXT_LISTENER_NAME, OsgiBundleApplicationContextListener.class) : createDefaultApplicationContextListener(); } // get post processors postProcessors .addAll(extenderConfiguration.getBeansOfType(OsgiBeanFactoryPostProcessor.class).values()); // get dependency factories dependencyFactories .addAll(extenderConfiguration.getBeansOfType(OsgiServiceDependencyFactory.class).values()); classLoader = extenderConfiguration.getClassLoader(); // extender properties using the defaults as backup if (extenderConfiguration.containsBean(PROPERTIES_NAME)) { Properties customProperties = extenderConfiguration.getBean(PROPERTIES_NAME, Properties.class); Enumeration<?> propertyKey = customProperties.propertyNames(); while (propertyKey.hasMoreElements()) { String property = (String) propertyKey.nextElement(); properties.setProperty(property, customProperties.getProperty(property)); } } } synchronized (lock) { shutdownWaitTime = getShutdownWaitTime(properties); shutdownAsynchronously = getShutdownAsynchronously(properties); dependencyWaitTime = getDependencyWaitTime(properties); processAnnotation = getProcessAnnotations(properties); } // load default dependency factories addDefaultDependencyFactories(); // allow post processing contextCreator = postProcess(contextCreator); }
From source file:org.sakaiproject.status.StatusServlet.java
protected void reportSystemProperties(HttpServletResponse response) throws Exception { PrintWriter pw = response.getWriter(); Properties props = System.getProperties(); Enumeration propNames = props.propertyNames(); SortedSet sortedPropNames = new TreeSet(); while (propNames.hasMoreElements()) { sortedPropNames.add((String) propNames.nextElement()); }//from w ww . j a va2 s . co m for (Object pName : sortedPropNames) { String propertyName = (String) pName; String value = props.getProperty(propertyName); if (propertyName.startsWith("password")) { value = "********"; } pw.print(propertyName + "=" + value + "\n"); } }
From source file:org.sakaiproject.status.StatusServlet.java
protected void reportSakaiProperties(HttpServletResponse response) throws Exception { PrintWriter pw = response.getWriter(); SakaiProperties sp = (SakaiProperties) ComponentManager.get("org.sakaiproject.component.SakaiProperties"); if (sp == null) { throw new Exception("Could not get SakaiProperties bean."); }/*from w w w . j a v a2 s . c om*/ Properties props = sp.getRawProperties(); Enumeration propNames = props.propertyNames(); SortedSet sortedPropNames = new TreeSet(); while (propNames.hasMoreElements()) { sortedPropNames.add((String) propNames.nextElement()); } for (Object pName : sortedPropNames) { String propertyName = (String) pName; String value = props.getProperty(propertyName); if (propertyName.startsWith("password") || propertyName.endsWith("password")) { value = "********"; } pw.print(propertyName + "=" + value + "\n"); } }
From source file:com.spoledge.audao.generator.Generator.java
private String[] createJavaResourceKeys() { ArrayList<String> list = new ArrayList<String>(); Properties props = new Properties(); try {/*w w w . j a va2s.com*/ props.load(getClass().getResourceAsStream(JAVA_RESOURCES + "/sources.properties")); } catch (IOException e) { log.error("createJavaResourceKeys()", e); } // NOTE: JDK 1.5 compatibility - we cannot use stringPropertyNames(): // for (String key : props.stringPropertyNames()) { for (Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) { String key = (String) en.nextElement(); String[] vals = props.getProperty(key).split("\\|"); if (vals.length == 1) { list.add(vals[0]); } else { String tname = target.getIdentifier().toLowerCase(); for (int i = 1; i < vals.length; i++) { if (tname.equals(vals[i])) { list.add(vals[0]); break; } } } } String[] ret = new String[list.size()]; return list.toArray(ret); }
From source file:org.elasticsearch.hadoop.cfg.Settings.java
public Settings merge(Properties properties) { if (properties == null || properties.isEmpty()) { return this; }/*from w w w. j a va 2 s. c o m*/ Enumeration<?> propertyNames = properties.propertyNames(); Object prop = null; for (; propertyNames.hasMoreElements();) { prop = propertyNames.nextElement(); if (prop instanceof String) { Object value = properties.get(prop); setProperty((String) prop, value.toString()); } } return this; }