public static ExtendedProperties getResourceAsExtendedProperties(String resource) { if (StringUtils.isBlank(resource)) { return null; } ExtendedProperties properties = new ExtendedProperties(); try (InputStream stream = PropertiesHandler.class.getResourceAsStream(resource)) { if (stream == null) { logger.error("resource " + resource + " is missing"); } else { properties.load(stream); logger.info("resource " + resource + " loaded (" + properties.size() + " properties)"); } } catch (Exception ex) { logger.fatal(ex); } return properties; }
@Override public void init(ExtendedProperties configuration) { this.resourceLoader = (org.springframework.core.io.ResourceLoader) this.rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER); String resourceLoaderPath = (String) this.rsvc.getApplicationAttribute(SPRING_RESOURCE_LOADER_PATH); if (this.resourceLoader == null) { throw new IllegalArgumentException( "'resourceLoader' application attribute must be present for SpringResourceLoader"); } if (resourceLoaderPath == null) { throw new IllegalArgumentException( "'resourceLoaderPath' application attribute must be present for SpringResourceLoader"); } this.resourceLoaderPaths = StringUtils.commaDelimitedListToStringArray(resourceLoaderPath); for (int i = 0; i < this.resourceLoaderPaths.length; i++) { String path = this.resourceLoaderPaths[i]; if (!path.endsWith("/")) { this.resourceLoaderPaths[i] = path + "/"; } } if (logger.isInfoEnabled()) { logger.info("SpringResourceLoader for Velocity: using resource loader [" + this.resourceLoader + "] and resource loader paths " + Arrays.asList(this.resourceLoaderPaths)); } }
private static void log(ExtendedProperties properties, Level level) { Object next; 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)); } }
public static ExtendedProperties getExtendedProperties(File file, Level badFileLogLevel, Level goodFileLogLevel) { ExtendedProperties extendedProperties = new ExtendedProperties(); String filename = file == null ? "" : file.getPath(); if (file == null) { logger.error("null properties file"); } else if (file.isFile()) { try { logger.trace("loading " + filename); try (InputStream inStream = new FileInputStream(filename)) { extendedProperties.load(inStream); } logger.log(goodFileLogLevel, "file " + filename + " loaded (" + extendedProperties.size() + " properties)"); printExtendedProperties(extendedProperties); } catch (Exception ex) { logger.fatal(ThrowableUtils.getString(ex), ex); } } else { logger.log(badFileLogLevel, filename + " does not exist or is not a normal file"); } return extendedProperties; }
public static ExtendedProperties getExtendedProperties(byte[] buffer) { ExtendedProperties extendedProperties = new ExtendedProperties(); if (buffer == null) { logger.error("null properties buffer"); } else { try { logger.trace("loading buffer " + Arrays.toString(buffer)); try (InputStream inStream = new ByteArrayInputStream(buffer)) { extendedProperties.load(inStream); } printExtendedProperties(extendedProperties); } catch (Exception ex) { logger.fatal(ThrowableUtils.getString(ex), ex); } } return extendedProperties; }
@SuppressWarnings("unchecked") private void deletePreviouslyGeneratedFiles(ExtendedProperties properties) { String[] stringArray; Set<String> stringPropertyNames = properties.keySet(); for (String name : stringPropertyNames) { switch (name) { case DO_CASCADED_DELETE: stringArray = properties.getStringArray(name); deletePreviouslyGeneratedFiles(name, stringArray, true); break; case DO_ISOLATED_DELETE: stringArray = properties.getStringArray(name); deletePreviouslyGeneratedFiles(name, stringArray, false); break; } } }
private Predicate getPredicate(ExtendedProperties properties, List<Predicate> predicates, String keyPreffix) { String key = keyPreffix + ".predicate.join"; String operator = properties.getString(key, "all"); String[] operators = new String[]{"all", "any", "none", "one"}; int i = ArrayUtils.indexOf(operators, operator.toLowerCase()); switch (i) { case 1: return PredicateUtils.anyPredicate(predicates); case 2: return PredicateUtils.nonePredicate(predicates); case 3: return PredicateUtils.onePredicate(predicates); default: return PredicateUtils.allPredicate(predicates); } }
private static String[] getArguments(Class<?> clazz, ExtendedProperties properties, Level level) { if (properties == null) { logger.log(level, ARGS_FAILED + "; properties is null"); } else if (properties.isEmpty()) { logger.log(level, ARGS_FAILED + "; properties is empty"); } else { String key = clazz.getName() + ARGS_SUFFIX; try { String[] strings = properties.getStringArray(key); if (strings == null || strings.length == 0) { logger.log(level, ARGS_FAILED + "; property " + key + " not found"); } else { return strings; } } catch (Exception e) { logger.log(level, ARGS_FAILED + "; " + key + " not properly defined (" + e + ")"); } } return null; }
/** * 合併設定 * * properties改成使用 extendedProperties 取屬性 * * @throws Exception */ protected void mergeProperties() throws Exception { Properties props = new Properties(); if (this.configLocation != null) { LOGGER.info(new StringBuilder().append("Loading config from ").append(this.configLocation).toString()); PropertiesLoaderUtils.fillProperties(props, this.configLocation); } if (this.properties != null) { LOGGER.info(new StringBuilder().append("Loading config from properties").toString()); props.putAll(this.properties); // 清除原properties,省mem,因之後會使用extendedProperties了 this.properties.clear(); } // if (props.size() > 0) { this.extendedProperties = ExtendedProperties.convertProperties(props); if (this.extendedProperties.size() > 0) { LOGGER.info(new StringBuilder().append("All properties: " + extendedProperties).toString()); } } }
public void init( ExtendedProperties configuration) { rsvc.info("FileResourceLoader : initialization starting."); paths = configuration.getVector("path"); /* * lets tell people what paths we will be using */ int sz = paths.size(); for( int i=0; i < sz; i++) { rsvc.info("FileResourceLoader : adding path '" + (String) paths.get(i) + "'"); } rsvc.info("FileResourceLoader : initialization complete."); }
/** * This initialization is used by all resource * loaders and must be called to set up common * properties shared by all resource loaders */ public void commonInit( RuntimeServices rs, ExtendedProperties configuration) { this.rsvc = rs; /* * 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... */ isCachingOn = configuration.getBoolean("cache", false); modificationCheckInterval = configuration.getLong("modificationCheckInterval", 0); /* * this is a must! */ className = configuration.getString("class"); }
/** * Allow an external system to set an ExtendedProperties * object to use. This is useful where the external * system also uses the ExtendedProperties class and * the velocity configuration is a subset of * parent application's configuration. This is * the case with Turbine. * * @param ExtendedProperties configuration */ public void setConfiguration( ExtendedProperties configuration) { if (overridingProperties == null) { overridingProperties = configuration; } else { // Avoid possible ConcurrentModificationException if (overridingProperties != configuration) { overridingProperties.combine(configuration); } } }
@Override public void init(ExtendedProperties configuration) { String[] all = configuration.getStringArray(IncludeKey); include = new HashSet<String>(); match = new HashSet<String>(); if (all != null) { for (String s : all) { if (s.endsWith("/*")) { match.add(s.substring(0, s.length() - 1)); } else { include.add(s); } } } if (log.isTraceEnabled()) { log.trace("FixedClasspathResourceLoader : initialization complete with include:" + include); } }
/** * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration() */ 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())); } }
/** * This is abstract in the base class, so we need it. * <br> * NOTE: this expects that the ServletContext has already * been placed in the runtime's application attributes * under its full class name (i.e. "javax.servlet.ServletContext"). * * @param configuration the {@link ExtendedProperties} associated with * this resource loader. */ public void init(ExtendedProperties configuration) { paths = configuration.getStringArray("path"); if (paths == null || paths.length == 0) { paths = new String[1]; paths[0] = "/"; } else { /* make sure the paths end with a '/' */ for (int i = 0; i < paths.length; i++) { if (!paths[i].endsWith("/")) { paths[i] += '/'; } } } //My_System.variable("paths", paths); }
private static VelocityEngine newVelocityEngine() { ExtendedProperties prop = new ExtendedProperties(); prop.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SimpleLog4JLogSystem.class.getName()); prop.addProperty("runtime.log.logsystem.log4j.category", "GenerateToString"); VelocityEngine velocity = new VelocityEngine(); velocity.setExtendedProperties(prop); velocity.init(); return velocity; }
@Override public void init(ExtendedProperties configuration) { String path = (String) configuration.getProperty("path"); if (path != null) { _root = path; } }
@Override public void init(ExtendedProperties configuration) { setCachingOn(configuration.getBoolean("cache", true)); // check interval can be small since the isSourceModified check is fast setModificationCheckInterval(configuration.getLong("modificationCheckInterval", 10L)); this.resourceTemplatesLastModified = System.currentTimeMillis(); }
public void commonInit(RuntimeServices rs, ExtendedProperties configuration) { super.commonInit(rs,configuration); Log.i(LOGTAG,"commonInit"); try { this.assets = (AssetManager) rs.getProperty("asset.resource.loader.manager"); setPath((String) rs.getProperty("asset.resource.loader.path")); Log.d(LOGTAG,"Assets Path:"+path); //list = assets.list(path); } catch (Exception e){ Log.e(LOGTAG,"Exception wile initing",e); throw new RuntimeException("Exception while initing", e); } }
/** * Returns a new instance of the VelocityEngine. * <p/> * The engine is initialized and outputs its logging to IDEA logging. * * @return a new velocity engine that is initialized. */ private static VelocityEngine newVeloictyEngine() { ExtendedProperties prop = new ExtendedProperties(); prop.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SimpleLog4JLogSystem.class.getName()); prop.addProperty("runtime.log.logsystem.log4j.category", "GenerateToString"); prop.addProperty(RuntimeConstants.RESOURCE_LOADER, "includes"); prop.addProperty("includes.resource.loader.class", VelocityIncludesClassLoader.class.getName()); VelocityEngine velocity = new VelocityEngine(); velocity.setExtendedProperties(prop); velocity.init(); return velocity; }
private static synchronized VelocityEngine getEngine() { if (instance == null) { try { VelocityEngine engine = new VelocityEngine(); ExtendedProperties extendedProperties = new ExtendedProperties(); extendedProperties.addProperty(RuntimeConstants.RESOURCE_LOADER, "file"); extendedProperties.addProperty(RuntimeConstants.PARSER_POOL_SIZE, "1"); extendedProperties.addProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); extendedProperties.addProperty("file.resource.loader.path", PathManager.getPluginsPath() + "/Copyright/resources"); extendedProperties.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SimpleLog4JLogSystem.class.getName()); extendedProperties .addProperty("runtime.log.logsystem.log4j.category", CopyrightManager.class.getName()); engine.setExtendedProperties(extendedProperties); engine.init(); instance = engine; } catch (Exception ignored) { } } return instance; }
public static ExtendedProperties getExtendedProperties(String... filename) { if (filename == null || filename.length == 0) { return null; } int last = filename.length - 1; ExtendedProperties properties = null; for (int i = 0; i < filename.length && (properties == null || properties.isEmpty()); i++) { properties = getExtendedProperties(filename[i], i == last ? Level.ERROR : Level.INFO, Level.INFO); } return properties; }
public static void printExtendedProperties(ExtendedProperties extendedProperties) { ArrayList<String> list = new ArrayList<>(); for (Iterator i = extendedProperties.getKeys(); i.hasNext();) { list.add((String) i.next()); } String[] names = new String[list.size()]; list.toArray(names); Arrays.sort(names); String[] values; for (String name : names) { values = extendedProperties.getStringArray(name); logger.trace(name + " = " + (StringUtils.containsIgnoreCase(name, "password") ? "***" : getArrayString(values))); } }
/** * Gets the final properties set using the properties file as a velocity template */ private ExtendedProperties mergeExtendedProperties(VelocityContext context, File propertiesFile) { String template = getTemplate(propertiesFile); StringWriter sw = mergeTemplate(context, template); if (sw != null) { byte[] buffer = sw.toString().getBytes(); ExtendedProperties properties = PropertiesHandler.getExtendedProperties(buffer); return properties; } return null; }
@SuppressWarnings("unchecked") private void createDirectories(ExtendedProperties properties) { String[] stringArray; Set<String> stringPropertyNames = properties.keySet(); for (String name : stringPropertyNames) { switch (name) { case DO_CREATE_DIR: stringArray = properties.getStringArray(name); createDirectories(name, stringArray); break; } } }
private ForEach(File templatePropertiesFile) { ExtendedProperties templateExtendedProperties = PropertiesHandler.getExtendedProperties(templatePropertiesFile); string = templateExtendedProperties.getString(TP_FOR_EACH); String[] tokens = StringUtils.split(string, '.'); if (tokens != null) { String token; ForEachVariable variable; ForEachVariable previous; Map<String, ForEachVariable> variables = new LinkedHashMap<>(); for (int i = 0; i < tokens.length; i++) { token = tokens[i]; if (variables.containsKey(token)) { String pattern = "{0} (token \"{1}\" is used more than once)"; String message = MessageFormat.format(pattern, string, token); throw new IllegalArgumentException(message); } variable = new ForEachVariable(); variable.token = token; variable.getter = templateExtendedProperties.getString(token + ".getter"); variable.predicate = getPredicate(templateExtendedProperties, token); variable.comparator = getComparator(templateExtendedProperties, token); if (i == 0) { start = variable; } else { previous = variables.get(tokens[i - 1]); previous.next = variable; } variables.put(token, variable); } } }
@SuppressWarnings("unchecked") // unchecked cast private Comparator<?> getComparator(ExtendedProperties properties, String keyPreffix) { String key = keyPreffix + ".comparator"; String[] classNames = properties.getStringArray(key); List<Comparator<?>> comparators = new ArrayList<>(); Comparator<?> c; for (String name : classNames) { c = getComparator(name); if (c != null) { comparators.add(c); } } return comparators.isEmpty() ? null : (Comparator<?>) ComparatorUtils.chainedComparator(comparators); // unchecked cast }
public static String[] getArguments(Class<?> clazz) { ExtendedProperties properties; String[] arguments = null; if (clazz == null) { logger.error(ARGS_FAILED + "; null value for clazz parameter"); } else { properties = PropertiesHandler.getPrivateProperties(); arguments = getArguments(clazz, properties, Level.TRACE); if (arguments == null) { properties = PropertiesHandler.getBootstrapping(); arguments = getArguments(clazz, properties, Level.ERROR); } } return arguments == null ? new String[0] : arguments; }
/** * @param configuration the {@link ExtendedProperties} associated with this resource * loader. */ @Override public void init(ExtendedProperties configuration) { rsvc.debug("WebappLoader : initialization starting."); getLibraryWebappResourceManager(); /* init the template paths map */ templatePaths = new HashMap(); rsvc.debug("WebappLoader : initialization complete."); }
/** * Set an entire configuration at once. This is * useful in cases where the parent application uses * the Configuration class and the velocity configuration * is a subset of the parent application's configuration. * * @param Configuration configuration * * @deprecated Use * {@link #setExtendedProperties( ExtendedProperties ) } */ public static void setConfiguration(Configuration configuration) { /* * Yuk. We added a little helper to Configuration to * help with deprecation. The Configuration class * contains a 'shadow' ExtendedProperties */ ExtendedProperties ep = configuration.getExtendedProperties(); RuntimeSingleton.setConfiguration( ep ); }
/** * Set an entire configuration at once. This is * useful in cases where the parent application uses * the Configuration class and the velocity configuration * is a subset of the parent application's configuration. * * @param Configuration configuration * * @deprecated Use * {@link #setExtendedProperties( ExtendedProperties ) } */ public void setConfiguration(Configuration configuration) { /* * Yuk. We added a little helper to Configuration to * help with deprecation. The Configuration class * contains a 'shadow' ExtendedProperties */ ExtendedProperties ep = configuration.getExtendedProperties(); ri.setConfiguration( ep ); }
public void init( ExtendedProperties configuration) { dataSourceName = configuration.getString("resource.datasource"); tableName = configuration.getString("resource.table"); keyColumn = configuration.getString("resource.keycolumn"); templateColumn = configuration.getString("resource.templatecolumn"); timestampColumn = configuration.getString("resource.timestampcolumn"); Runtime.info("Resources Loaded From: " + dataSourceName + "/" + tableName); Runtime.info( "Resource Loader using columns: " + keyColumn + ", " + templateColumn + " and " + timestampColumn); Runtime.info("Resource Loader Initalized."); }
/** * Called by Velocity to initialize the loader */ public void init( ExtendedProperties configuration) { rsvc.info("JarResourceLoader : initialization starting."); Vector paths = configuration.getVector("path"); /* * support the old version but deprecate with a log message */ if( paths == null || paths.size() == 0) { paths = configuration.getVector("resource.path"); if (paths != null && paths.size() > 0) { rsvc.warn("JarResourceLoader : you are using a deprecated configuration" + " property for the JarResourceLoader -> '<name>.resource.loader.resource.path'." + " Please change to the conventional '<name>.resource.loader.path'."); } } rsvc.info("JarResourceLoader # of paths : " + paths.size() ); for ( int i=0; i<paths.size(); i++ ) { loadJar( (String)paths.get(i) ); } rsvc.info("JarResourceLoader : initialization complete."); }
/** * Initialize the Velocity Runtime with the name of * ExtendedProperties object. * * @param Properties */ public void init(String configurationFile) throws Exception { overridingProperties = new ExtendedProperties(configurationFile); init(); }
private static Properties buildUserAttributes(Properties ldapConfig) { Properties ldapUserAttributes = new Properties(); ExtendedProperties ldapUserAttributesSubset = ExtendedProperties.convertProperties(ldapConfig).subset("LdapUserAttribute"); if (null != ldapUserAttributesSubset) { ldapUserAttributes.putAll(ldapUserAttributesSubset); } return ldapUserAttributes; }