/** * Searches for a configuration file at the specified path and returns * it in the form of a {@link FactoryConfiguration}. This method will * look for a matching file in both the classpath and the file system. * If perchance a match is found in both, then both are loaded and the * configuration loaded from the file system is given precedence (i.e. * it is added onto the other). If no match is found in either, then * this will return {@code null}. * @param path configuration classpath or filesystem path * @return new {@link FactoryConfiguration} for the given path */ public static FactoryConfiguration find(String path) { FactoryConfiguration cp = findInClasspath(path); FactoryConfiguration fs = findInFileSystem(path); if (cp != null) { if (fs != null) { cp.addConfiguration(fs); } return cp; } else { return fs; } }
public EasyFactoryConfiguration autoLoad(boolean includeDefaults) { addConfiguration(ConfigurationUtils.getDefaultTools()); addedDefaults = true; return this; }
/** * @param path configuration classpath * @return new {@link FactoryConfiguration} for the given classpath * @see #findInClasspath(String path, Object caller) */ public static FactoryConfiguration findInClasspath(String path) { // pretend this was called by a non-static ConfigurationUtils return findInClasspath(path, new ConfigurationUtils()); }
private FactoryConfiguration loadFromClassPath(String location) { FactoryConfiguration factoryConfiguration = ConfigurationUtils.findInClasspath(location, this); if (logger.isInfoEnabled()) { String message = "The Toolbox Configuration can't be found In ServletContext , " + "thus try to locate in classpath[" + location + "], result : " + (factoryConfiguration != null ? "found !" : "not found !"); logger.info(message); } return factoryConfiguration; }
private FactoryConfiguration loadFromServletContext(ServletContext servletContext, String contextPath) { String realPath = servletContext.getRealPath(contextPath); FactoryConfiguration factoryConfiguration = ConfigurationUtils.findInFileSystem(realPath); if (logger.isInfoEnabled()) { String message = "To find Toolbox Configuration[ context path : " + contextPath + " ] under Servlet Context[ path : " + realPath + "] , result : " + (factoryConfiguration != null ? "found !" : "not found !"); logger.info(message); } return factoryConfiguration; }
/** * Returns a {@link FactoryConfiguration} including all default * "GenericTools" available and no others. * @return the generic tools default {@link FactoryConfiguration} */ public static FactoryConfiguration getGenericTools() { FileFactoryConfiguration config = new XmlFactoryConfiguration("ConfigurationUtils.getGenericTools()"); config.read(GENERIC_DEFAULTS_PATH); // defaults should *always* be clean! clean(config); return config; }
/** * init logger */ protected void initLog() { if (velocity == null) { log = LoggerFactory.getLogger(ToolManager.class); } else { log = ConfigurationUtils.getLog(velocity, "tools"); } }
/** * Find a configuration file * @param path path to a configuration file * @return toolbox factory configuration */ protected FactoryConfiguration findConfig(String path) { return ConfigurationUtils.find(path); }
/** * Autoconfiguration using the configuration file potentially found * in the <code>org.apache.velocity.tools</code> system property. * @param includeDefaults whether to include default tools */ public void autoConfigure(boolean includeDefaults) { // look for any specified via system property FactoryConfiguration sys = ConfigurationUtils.findFromSystemProperty(); if (sys != null) { configure(sys); } }
/** * Get a specific {@link FactoryConfiguration} class * @param classname FacotyConfiguration class * @return new FactoryConfiguration instance */ public static FactoryConfiguration getFromClass(String classname) { try { Class configFactory = ClassUtils.getClass(classname); return getFromClass(configFactory); } catch (ClassNotFoundException cnfe) { throw new IllegalArgumentException("Could not find class "+classname, cnfe); } }
private FactoryConfiguration loadFromClassPath(String location) { FactoryConfiguration factoryConfiguration = ConfigurationUtils.findInClasspath(location, this); if (logger.isInfoEnabled()) { String message = "The Toolbox Configuration can't be found In ServletContext , " + "thus try to locate in classpath[" + location + "], result : " + (factoryConfiguration != null ? "found !" : "not found !"); logger.info(message); } return factoryConfiguration; }
private FactoryConfiguration loadFromServletContext(ServletContext servletContext, String contextPath) { String realPath = servletContext.getRealPath(contextPath); FactoryConfiguration factoryConfiguration = ConfigurationUtils.findInFileSystem(realPath); if (logger.isInfoEnabled()) { String message = "To find Toolbox Configuration[ context path : " + contextPath + " ] under Servlet Context[ path : " + realPath + "] , result : " + (factoryConfiguration != null ? "found !" : "not found !"); logger.info(message); } return factoryConfiguration; }
/** * <p>Returns a {@link FactoryConfiguration} including all default * "VelocityView" tools available as well as the default "GenericTools".</p> * @return all default tools {@link FactoryConfiguration} * @throws ConfigurationException if a tools.xml is not found at the {@link #VIEW_DEFAULTS_PATH}. */ public static FactoryConfiguration getVelocityView() { FileFactoryConfiguration config = new XmlFactoryConfiguration("ConfigurationUtils.getVelocityView()"); config.read(GENERIC_DEFAULTS_PATH); config.read(VIEW_DEFAULTS_PATH); // defaults should *always* be clean! clean(config); return config; }
if (engine != null && key != null) log = ConfigurationUtils.getLog(engine, "tools." + key);
/** * Returns a {@link FactoryConfiguration} loaded from a configuration file * at the specified path. If no such file is found at that path, this * will throw a {@link ResourceNotFoundException}. * * @param path configuration path * @return new {@link FactoryConfiguration} * @see #find(String path) */ public static FactoryConfiguration load(String path) { FactoryConfiguration config = find(path); if (config == null) { throw new ResourceNotFoundException("Could not find configuration at "+path); } return config; }
/** * Returns a new, standard {@link ToolboxFactory} configured * with the results of {@link #findFromSystemProperty()}. * @return new {@link ToolboxFactory} */ public static ToolboxFactory createFactory() { // include any config specified via system property FactoryConfiguration sys = findFromSystemProperty(); ToolboxFactory factory = new ToolboxFactory(); if (sys != null) { factory.configure(sys); } return factory; }
.tool( XmlTool.class ); FactoryConfiguration customConfig = ConfigurationUtils.findInClasspath( TOOLS_LOCATION );
/** * Adds the {@link ConfigurationUtils#getDefaultTools()} configuration to this * the current configuration. * @return new EasyFacotryConfiguration instance with all default tools */ public EasyFactoryConfiguration addDefaultTools() { if (!addedDefaults) { addConfiguration(ConfigurationUtils.getDefaultTools()); addedDefaults = true; } return this; }
/** * Returns the "default" {@link FactoryConfiguration}. This includes * all the standard tools developed by this project and available in * the jar being used. In other words, if the velocity-tools-generic-2.x.jar * is being used, then only the generic tools will be included. If * the velocity-tools-struts-2.x.jar is being used, then all VelocityTools * will be available. This also means that subclasses in the larger jars * will override their superclasses. So, if you are using the VelocityStruts * jar, then your $link reference will be a StrutsLinkTool. If you are using * the VelocityView jar, it will be a standard LinkTool. * @return the default {@link FactoryConfiguration} */ public static FactoryConfiguration getDefaultTools() { FileFactoryConfiguration config = new XmlFactoryConfiguration("ConfigurationUtils.getDefaultTools()"); config.read(GENERIC_DEFAULTS_PATH); // view tools may not be available config.read(VIEW_DEFAULTS_PATH, false); // defaults should *always* be clean! clean(config); return config; }