Java 类org.apache.velocity.tools.config.XmlFactoryConfiguration 实例源码

项目:java-template-simple    文件:VelocityToolboxView.java   
@Override
protected Context createVelocityContext(Map<String, Object> model,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ViewToolContext velocityContext = new ViewToolContext(getVelocityEngine(), request, response, getServletContext());
    velocityContext.putAll(model);
    if(getToolboxConfigLocation() != null ||getToolboxConfigResource() != null){
        XmlFactoryConfiguration cfg = new XmlFactoryConfiguration();
        URL cfgUrl;
        if(getToolboxConfigLocation() != null){
            cfgUrl = new ServletContextResource(getServletContext(), getToolboxConfigLocation()).getURL();
            cfg.read(cfgUrl);
        }else if(getToolboxConfigResource() != null){
            cfgUrl = getToolboxConfigResource().getURL();
            cfg.read(cfgUrl);
            ToolboxFactory factory = cfg.createFactory();

            velocityContext.addToolbox(factory.createToolbox(Scope.APPLICATION));
            velocityContext.addToolbox(factory.createToolbox(Scope.REQUEST));
            velocityContext.addToolbox(factory.createToolbox(Scope.SESSION));
        }
    }
    return velocityContext;
}
项目:demyo    文件:Velocity2ToolboxView.java   
@PostConstruct
private void initToolManager() throws IllegalStateException, IOException {
    LOGGER.debug("Configuring toolbox from {}", getToolboxConfigLocation());
    velocityToolManager = new ViewToolManager(getServletContext(), false, true);
    velocityToolManager.setVelocityEngine(getVelocityEngine());
    FileFactoryConfiguration factoryConfig = new XmlFactoryConfiguration(false);
    factoryConfig.read(new ServletContextResource(getServletContext(), getToolboxConfigLocation()).getURL());
    velocityToolManager.configure(factoryConfig);
}
项目:Harvest-JP    文件:VelocityToolsView.java   
@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();

    XmlFactoryConfiguration config = new XmlFactoryConfiguration();
    config.read(getServletContext().getResourceAsStream(getToolboxConfigLocation()));
    toolManager = new ViewToolManager(getServletContext(), false, false);
    toolManager.configure(config);
    toolManager.setVelocityEngine(getVelocityEngine());
}