Java 类org.apache.velocity.tools.view.ViewToolContext 实例源码

项目: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;
}
项目:communote-server    文件:VelocityToolbox2View.java   
/**
 * {@inheritDoc}
 */
@Override
protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // create view context that contains tools, request, response and servlet context
    ViewToolContext context = getToolManager().createContext(request, response);
    context.putAll(model);
    return context;
}
项目:mblog    文件:RenderHandler.java   
public HttpServletRequest getRequest() {
    ViewToolContext viewContext = (ViewToolContext)context.getInternalUserContext();
       return viewContext.getRequest();

}