List of usage examples for org.apache.commons.collections ExtendedProperties getString
public String getString(String key)
From source file:com.cyclopsgroup.waterview.jelly.JellyScriptsRunner.java
/** * Main entry to run a script// www .j a v a2 s . c om * * @param args Script paths * @throws Exception Throw it out */ public static final void main(String[] args) throws Exception { List scripts = new ArrayList(); for (int i = 0; i < args.length; i++) { String path = args[i]; File file = new File(path); if (file.isFile()) { scripts.add(file.toURL()); } else { Enumeration enu = JellyScriptsRunner.class.getClassLoader().getResources(path); CollectionUtils.addAll(scripts, enu); } } if (scripts.isEmpty()) { System.out.println("No script to run, return!"); return; } String basedir = new File("").getAbsolutePath(); Properties initProperties = new Properties(System.getProperties()); initProperties.setProperty("basedir", basedir); initProperties.setProperty("plexus.home", basedir); WaterviewPlexusContainer container = new WaterviewPlexusContainer(); for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) { String initPropertyName = (String) j.next(); container.addContextValue(initPropertyName, initProperties.get(initPropertyName)); } container.addContextValue(Waterview.INIT_PROPERTIES, initProperties); container.initialize(); container.start(); JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE); JellyContext jc = new JellyContext(je.getGlobalContext()); XMLOutput output = XMLOutput.createXMLOutput(System.out); for (Iterator i = scripts.iterator(); i.hasNext();) { URL script = (URL) i.next(); System.out.print("Running script " + script); ExtendedProperties ep = new ExtendedProperties(); ep.putAll(initProperties); ep.load(script.openStream()); for (Iterator j = ep.getKeys("script"); j.hasNext();) { String name = (String) j.next(); if (name.endsWith(".file")) { File file = new File(ep.getString(name)); if (file.exists()) { System.out.println("Runner jelly file " + file); jc.runScript(file, output); } } else if (name.endsWith(".resource")) { Enumeration k = JellyScriptsRunner.class.getClassLoader().getResources(ep.getString(name)); while (j != null && k.hasMoreElements()) { URL s = (URL) k.nextElement(); System.out.println("Running jelly script " + s); jc.runScript(s, output); } } } //jc.runScript( script, XMLOutput.createDummyXMLOutput() ); System.out.println("... Done!"); } container.dispose(); }
From source file:adalid.commons.properties.PropertiesHandler.java
private static void log(ExtendedProperties properties, Level level) { Object next;/*w ww.j a v a 2 s .c o m*/ Set<String> names = new TreeSet<>(); Iterator iterator = properties.getKeys(); if (iterator != null) { while (iterator.hasNext()) { next = iterator.next(); if (next instanceof String) { names.add((String) next); } } } String value; for (String name : names) { value = properties.getString(name); logger.log(level, name + " = " + (StringUtils.containsIgnoreCase(name, "password") ? "***" : value)); } }
From source file:autohit.call.Call_GET_SPROP.java
/** * Execute it./*from www. j a va 2 s. com*/ * @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:com.alibaba.citrus.service.velocity.impl.SpringResourceLoaderAdapter.java
/** ?resource loader. */ @Override/*from ww w . j a v a 2s. c o m*/ public void init(ExtendedProperties configuration) { rsvc.getLog().info(getLogID() + " : initialization starting."); springLoader = assertNotNull((ResourceLoader) rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_KEY), SPRING_RESOURCE_LOADER_KEY); path = normalizeAbsolutePath(configuration.getString("path"), true); assertTrue(!isEmpty(path), "path"); path += "/"; rsvc.getLog().info(getLogID() + " : set path '" + path + "'"); rsvc.getLog().info(getLogID() + " : initialization complete."); }
From source file:com.metamesh.opencms.rfs.RfsAwareDumpLoader.java
/** * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration() *//*from w w w . ja va 2 s . c om*/ public void initConfiguration() { ExtendedProperties config = new ExtendedProperties(); config.putAll(m_configuration); String maxAge = config.getString("client.cache.maxage"); if (maxAge == null) { m_clientCacheMaxAge = -1; } else { m_clientCacheMaxAge = Long.parseLong(maxAge); } if (CmsLog.INIT.isInfoEnabled()) { if (maxAge != null) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_CLIENT_CACHE_MAX_AGE_1, maxAge)); } CmsLog.INIT.info( Messages.get().getBundle().key(Messages.INIT_LOADER_INITIALIZED_1, this.getClass().getName())); } }
From source file:bboss.org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader.java
/** * @see bboss.org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties) */// w w w .j a v a 2s .c om public void init(ExtendedProperties configuration) { dataSourceName = StringUtils.nullTrim(configuration.getString("resource.datasource")); tableName = StringUtils.nullTrim(configuration.getString("resource.table")); keyColumn = StringUtils.nullTrim(configuration.getString("resource.keycolumn")); templateColumn = StringUtils.nullTrim(configuration.getString("resource.templatecolumn")); timestampColumn = StringUtils.nullTrim(configuration.getString("resource.timestampcolumn")); if (dataSource != null) { if (log.isDebugEnabled()) { log.debug("DataSourceResourceLoader: using dataSource instance with table \"" + tableName + "\""); log.debug("DataSourceResourceLoader: using columns \"" + keyColumn + "\", \"" + templateColumn + "\" and \"" + timestampColumn + "\""); } log.trace("DataSourceResourceLoader initialized."); } else if (dataSourceName != null) { if (log.isDebugEnabled()) { log.debug("DataSourceResourceLoader: using \"" + dataSourceName + "\" datasource with table \"" + tableName + "\""); log.debug("DataSourceResourceLoader: using columns \"" + keyColumn + "\", \"" + templateColumn + "\" and \"" + timestampColumn + "\""); } log.trace("DataSourceResourceLoader initialized."); } else { String msg = "DataSourceResourceLoader not properly initialized. No DataSource was identified."; log.error(msg); throw new RuntimeException(msg); } }
From source file:com.arcbees.plugin.velocity.ResourceManagerImplCustom.java
/** * Initialize the ResourceManager./*ww w . j av a2 s . c o m*/ * * @param rsvc The Runtime Services object which is associated with this Resource Manager. * * @throws Exception */ public synchronized void initialize(final RuntimeServices rsvc) throws Exception { if (isInit) { log.warn("Re-initialization of ResourceLoader attempted!"); return; } ResourceLoader resourceLoader = null; this.rsvc = rsvc; log = rsvc.getLog(); log.debug("Default ResourceManager initializing. (" + this.getClass() + ")"); assembleResourceLoaderInitializers(); for (Iterator it = sourceInitializerList.iterator(); it.hasNext();) { /** * Resource loader can be loaded either via class name or be passed * in as an instance. */ ExtendedProperties configuration = (ExtendedProperties) it.next(); String loaderClass = StringUtils.nullTrim(configuration.getString("class")); ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance"); if (loaderInstance != null) { resourceLoader = loaderInstance; } else if (loaderClass != null) { resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass); } else { log.error("Unable to find '" + configuration.getString(RESOURCE_LOADER_IDENTIFIER) + ".resource.loader.class' specification in configuration." + " This is a critical value. Please adjust configuration."); continue; // for(... } resourceLoader.commonInit(rsvc, configuration); resourceLoader.init(configuration); resourceLoaders.add(resourceLoader); } /* * now see if this is overridden by configuration */ logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true); /* * now, is a global cache specified? */ String cacheClassName = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS); Object cacheObject = null; if (org.apache.commons.lang.StringUtils.isNotEmpty(cacheClassName)) { try { cacheObject = ClassUtils.getNewInstance(cacheClassName); } catch (ClassNotFoundException cnfe) { log.error("The specified class for ResourceCache (" + cacheClassName + ") does not exist or is not accessible to the current classloader."); cacheObject = null; } if (!(cacheObject instanceof ResourceCache)) { log.error("The specified class for ResourceCache (" + cacheClassName + ") does not implement " + ResourceCache.class.getName() + " ResourceManager. Using default ResourceCache implementation."); cacheObject = null; } } /* * if we didn't get through that, just use the default. */ if (cacheObject == null) { cacheObject = new ResourceCacheImpl(); } globalCache = (ResourceCache) cacheObject; globalCache.initialize(rsvc); log.trace("Default ResourceManager initialization complete."); }
From source file:bboss.org.apache.velocity.runtime.resource.ResourceManagerImpl.java
/** * Initialize the ResourceManager.//from w w w .j a v a 2 s . c o m * * @param rsvc The Runtime Services object which is associated with this Resource Manager. */ public synchronized void initialize(final RuntimeServices rsvc) { if (isInit) { log.debug("Re-initialization of ResourceLoader attempted and ignored."); return; } ResourceLoader resourceLoader = null; this.rsvc = rsvc; log = rsvc.getLog(); log.trace("Default ResourceManager initializing. (" + this.getClass() + ")"); assembleResourceLoaderInitializers(); for (Iterator it = sourceInitializerList.iterator(); it.hasNext();) { /** * Resource loader can be loaded either via class name or be passed * in as an instance. */ ExtendedProperties configuration = (ExtendedProperties) it.next(); String loaderClass = StringUtils.nullTrim(configuration.getString("class")); ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance"); if (loaderInstance != null) { resourceLoader = loaderInstance; } else if (loaderClass != null) { resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass); } else { String msg = "Unable to find '" + configuration.getString(RESOURCE_LOADER_IDENTIFIER) + ".resource.loader.class' specification in configuration." + " This is a critical value. Please adjust configuration."; log.error(msg); throw new VelocityException(msg); } resourceLoader.commonInit(rsvc, configuration); resourceLoader.init(configuration); resourceLoaders.add(resourceLoader); } /* * now see if this is overridden by configuration */ logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true); /* * now, is a global cache specified? */ String cacheClassName = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS); Object cacheObject = null; if (org.apache.commons.lang.StringUtils.isNotEmpty(cacheClassName)) { try { cacheObject = ClassUtils.getNewInstance(cacheClassName); } catch (ClassNotFoundException cnfe) { String msg = "The specified class for ResourceCache (" + cacheClassName + ") does not exist or is not accessible to the current classloader."; log.error(msg, cnfe); throw new VelocityException(msg, cnfe); } catch (IllegalAccessException ae) { throw new VelocityException("Could not access class '" + cacheClassName + "'", ae); } catch (InstantiationException ie) { throw new VelocityException("Could not instantiate class '" + cacheClassName + "'", ie); } if (!(cacheObject instanceof ResourceCache)) { String msg = "The specified resource cache class (" + cacheClassName + ") must implement " + ResourceCache.class.getName(); log.error(msg); throw new RuntimeException(msg); } } /* * if we didn't get through that, just use the default. */ if (cacheObject == null) { cacheObject = new ResourceCacheImpl(); } globalCache = (ResourceCache) cacheObject; globalCache.initialize(rsvc); log.trace("Default ResourceManager initialization complete."); }
From source file:bboss.org.apache.velocity.runtime.resource.loader.ResourceLoader.java
/** * This initialization is used by all resource * loaders and must be called to set up common * properties shared by all resource loaders * @param rs/*from w w w . jav a 2s .co m*/ * @param configuration */ public void commonInit(RuntimeServices rs, ExtendedProperties configuration) { this.rsvc = rs; this.log = rsvc.getLog(); /* * these two properties are not required for all loaders. * For example, for ClasspathLoader, what would cache mean? * so adding default values which I think are the safest * * don't cache, and modCheckInterval irrelevant... */ try { isCachingOn = configuration.getBoolean("cache", false); } catch (Exception e) { isCachingOn = false; String msg = "Exception parsing cache setting: " + configuration.getString("cache"); log.error(msg, e); throw new VelocityException(msg, e); } try { modificationCheckInterval = configuration.getLong("modificationCheckInterval", 0); } catch (Exception e) { modificationCheckInterval = 0; String msg = "Exception parsing modificationCheckInterval setting: " + configuration.getString("modificationCheckInterval"); log.error(msg, e); throw new VelocityException(msg, e); } /* * this is a must! */ className = ResourceCacheImpl.class.getName(); try { className = configuration.getString("class", className); } catch (Exception e) { String msg = "Exception retrieving resource cache class name"; log.error(msg, e); throw new VelocityException(msg, e); } }
From source file:com.metamesh.opencms.rfs.RfsVfsDriver.java
@Override public void init(CmsDbContext dbc, CmsConfigurationManager configurationManager, List successiveDrivers, CmsDriverManager driverManager) throws CmsException { debug();/* w w w .jav a 2 s . c o m*/ rfsService = new RfsService(); initContext = dbc; this.driverManager = driverManager; // // TODO: substitute with refresh context menu entry OpenCms.getMemoryMonitor().setCacheResourceList(false); try { ExtendedProperties configuration = CmsPropertyUtils.loadProperties( OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf("config/xyz.properties")); //ldap = new LDAPConnection(configuration); } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); } ExtendedProperties config = (ExtendedProperties) configurationManager.getConfiguration(); if (successiveDrivers != null && successiveDrivers.size() > 0) { String driverKey = (String) successiveDrivers.get(0) + ".vfs.driver"; String driverName = config.getString(driverKey); List drivers = (successiveDrivers.size() > 1) ? successiveDrivers.subList(1, successiveDrivers.size()) : null; successiveDriver = (I_CmsVfsDriver) driverManager.newDriverInstance(configurationManager, driverName, drivers); } else { throw new RuntimeException("driver needs successive DB driver."); } }