Java 类org.apache.velocity.tools.Scope 实例源码

项目: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;
}
项目:beyondj    文件:AbstractLocalisedServlet.java   
private Context createContextForLocale(Locale locale) {
    EasyFactoryConfiguration config = new EasyFactoryConfiguration();
    config.toolbox(Scope.APPLICATION)
            .tool(MSG, ResourceTool.class)
            .property(BUNDLES, MESSAGES)
            .property(LOCALE, locale);

    ToolManager manager = new ToolManager(false, false);
    manager.configure(config);
    return manager.createContext();
}
项目:communote-server    文件:ExtendableViewToolManager.java   
public ExtendableViewToolManager(ServletContext servletContext, boolean autoConfig,
        boolean includeDefaults) {
    super(servletContext, autoConfig, includeDefaults);
    this.applicationToolboxConfiguration = new ToolboxConfiguration();
    this.applicationToolboxConfiguration.setScope(Scope.APPLICATION);
    this.requestToolboxConfiguration = new ToolboxConfiguration();
    this.requestToolboxConfiguration.setScope(Scope.REQUEST);
    applicationTools = new HashMap<>();
    requestTools = new HashMap<>();
}