freemarker.ext.jsp.TaglibFactory Java Examples

The following examples show how to use freemarker.ext.jsp.TaglibFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FreeMarkerInlineRenderBootstrap.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Initialize FreeMarker elements after servlet context and FreeMarker configuration have both
 * been populated.
 */
private static void finishConfig() {
    if (freeMarkerConfig != null && servletContext != null) {
        taglibFactory = new TaglibFactory(servletContext);
        
        objectWrapper = freeMarkerConfig.getObjectWrapper();
        if (objectWrapper == null) {
            objectWrapper = ObjectWrapper.DEFAULT_WRAPPER;
        }

        GenericServlet servlet = new ServletAdapter();
        try {
            servlet.init(new DelegatingServletConfig());
        } catch (ServletException ex) {
            throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
        }
        
        servletContextHashModel = new ServletContextHashModel(servlet, ObjectWrapper.DEFAULT_WRAPPER);
        
        LOG.info("Freemarker configuration complete");
    }
}
 
Example #2
Source File: AbstractTestExecutorService.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected TemplateModel createModel(ObjectWrapper wrapper) throws Throwable {
	HttpServletRequest request = super.getRequestContext().getRequest();
	HttpServletResponse response = super.getRequestContext().getResponse();
	ServletContext servletContext = request.getSession().getServletContext();
	AllHttpScopesHashModel hashModel = new AllHttpScopesHashModel(wrapper, servletContext, request); //super.createModel(wrapper, servletContext, request, response);
	ControllerServlet servlet = new ControllerServlet();
	MockServletConfig config = new MockServletConfig(servletContext);
	servlet.init(config);
	ServletContextHashModel newServletContextModel = new ServletContextHashModel(servlet, wrapper);
	ServletContextHashModel servletContextModel = new ServletContextHashModel(servlet, wrapper);
	servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel);
	TaglibFactory taglibs = new TaglibFactory(servletContext);
	servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_APPLICATION, newServletContextModel);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_APPLICATION_PRIVATE, newServletContextModel);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_JSP_TAGLIBS, taglibs);
	HttpRequestHashModel requestModel = new HttpRequestHashModel(request, response, wrapper);
       request.setAttribute(ATTR_REQUEST_MODEL, requestModel);
	hashModel.putUnlistedModel(FreemarkerServlet.KEY_REQUEST_PRIVATE, requestModel);
	return hashModel;
}
 
Example #3
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #4
Source File: FreeMarkerView.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #5
Source File: FreeMarkerView.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #6
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Invoked on startup. Looks for a single FreeMarkerConfig bean to
 * find the relevant Configuration for this factory.
 * <p>Checks that the template for the default Locale can be found:
 * FreeMarker will check non-Locale-specific templates if a
 * locale-specific one is not found.
 * @see freemarker.cache.TemplateCache#getTemplate
 */
@Override
protected void initServletContext(ServletContext servletContext) throws BeansException {
	if (getConfiguration() != null) {
		this.taglibFactory = new TaglibFactory(servletContext);
	}
	else {
		FreeMarkerConfig config = autodetectConfiguration();
		setConfiguration(config.getConfiguration());
		this.taglibFactory = config.getTaglibFactory();
	}

	GenericServlet servlet = new GenericServletAdapter();
	try {
		servlet.init(new DelegatingServletConfig());
	}
	catch (ServletException ex) {
		throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex);
	}
	this.servletContextHashModel = new ServletContextHashModel(servlet, getObjectWrapper());
}
 
Example #7
Source File: FreeMarkerViewHandler.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static void prepOfbizRoot(Map<String, Object> root, HttpServletRequest request, HttpServletResponse response) {
    ServletContext servletContext = request.getServletContext(); // SCIPIO: get context using servlet API 3.0
    HttpSession session = request.getSession();

    // add in the OFBiz objects
    root.put("delegator", request.getAttribute("delegator"));
    root.put("dispatcher", request.getAttribute("dispatcher"));
    root.put("security", request.getAttribute("security"));
    root.put("userLogin", session.getAttribute("userLogin"));

    // add the response object (for transforms) to the context as a BeanModel
    root.put("response", response);

    // add the application object (for transforms) to the context as a BeanModel
    root.put("application", servletContext);

    // add the servlet context -- this has been deprecated, and now requires servlet, do we really need it?
    //root.put("applicationAttributes", new ServletContextHashModel(servletContext, FreeMarkerWorker.getDefaultOfbizWrapper()));

    // add the session object (for transforms) to the context as a BeanModel
    root.put("session", session);

    // add the session
    root.put("sessionAttributes", new HttpSessionHashModel(session, FreeMarkerWorker.getDefaultOfbizWrapper()));

    // add the request object (for transforms) to the context as a BeanModel
    root.put("request", request);

    // add the request
    root.put("requestAttributes", new HttpRequestHashModel(request, FreeMarkerWorker.getDefaultOfbizWrapper()));

    // add the request parameters -- this now uses a Map from UtilHttp
    Map<String, Object> requestParameters = UtilHttp.getParameterMap(request);
    root.put("requestParameters", requestParameters);

    // add the TabLibFactory
    TaglibFactory JspTaglibs = new TaglibFactory(servletContext);
    root.put("JspTaglibs", JspTaglibs);

}
 
Example #8
Source File: FreeMarkerConfigurer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the TaglibFactory object wrapped by this bean.
 */
@Override
public TaglibFactory getTaglibFactory() {
	return this.taglibFactory;
}
 
Example #9
Source File: FreeMarkerConfigurer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the TaglibFactory object wrapped by this bean.
 */
@Override
public TaglibFactory getTaglibFactory() {
	return this.taglibFactory;
}
 
Example #10
Source File: FreeMarkerConfigurer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the {@link TaglibFactory} for the given ServletContext.
 */
@Override
public void setServletContext(ServletContext servletContext) {
	this.taglibFactory = new TaglibFactory(servletContext);
}
 
Example #11
Source File: FreeMarkerConfigurer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the {@link TaglibFactory} for the given ServletContext.
 */
@Override
public void setServletContext(ServletContext servletContext) {
	this.taglibFactory = new TaglibFactory(servletContext);
}
 
Example #12
Source File: FreeMarkerConfigurer.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the TaglibFactory object wrapped by this bean.
 */
@Override
public TaglibFactory getTaglibFactory() {
	Assert.state(this.taglibFactory != null, "No TaglibFactory available");
	return this.taglibFactory;
}
 
Example #13
Source File: FreeMarkerConfigurer.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Initialize the {@link TaglibFactory} for the given ServletContext.
 */
@Override
public void setServletContext(ServletContext servletContext) {
	this.taglibFactory = new TaglibFactory(servletContext);
}
 
Example #14
Source File: FreeMarkerConfigurer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the TaglibFactory object wrapped by this bean.
 */
@Override
public TaglibFactory getTaglibFactory() {
	Assert.state(this.taglibFactory != null, "No TaglibFactory available");
	return this.taglibFactory;
}
 
Example #15
Source File: FreeMarkerConfigurer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Initialize the {@link TaglibFactory} for the given ServletContext.
 */
@Override
public void setServletContext(ServletContext servletContext) {
	this.taglibFactory = new TaglibFactory(servletContext);
}
 
Example #16
Source File: FreeMarkerConfig.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the {@link TaglibFactory} used to enable JSP tags to be
 * accessed from FreeMarker templates.
 */
TaglibFactory getTaglibFactory();
 
Example #17
Source File: FreeMarkerConfig.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Return the {@link TaglibFactory} used to enable JSP tags to be
 * accessed from FreeMarker templates.
 */
TaglibFactory getTaglibFactory();
 
Example #18
Source File: FreeMarkerConfig.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return the {@link TaglibFactory} used to enable JSP tags to be
 * accessed from FreeMarker templates.
 */
TaglibFactory getTaglibFactory();
 
Example #19
Source File: FreeMarkerConfig.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the {@link TaglibFactory} used to enable JSP tags to be
 * accessed from FreeMarker templates.
 */
TaglibFactory getTaglibFactory();
 
Example #20
Source File: FreeMarkerInlineRenderBootstrap.java    From rice with Educational Community License v2.0 2 votes vote down vote up
/**
 * Get the tablib factory for use in the component rendering phase.
 * 
 * @return The tablib factory for use in the component rendering phase.
 */
public static TaglibFactory getTaglibFactory() {
    return taglibFactory;
}