Class TaglibFactory

  • All Implemented Interfaces:
    TemplateHashModel, TemplateModel

    public class TaglibFactory
    extends Object
    implements TemplateHashModel
    A hash model associated with a servlet context that can load JSP tag libraries associated with that servlet context. An instance of this class is made available in the root data model of templates executed by FreemarkerServlet under key JspTaglibs. It can be added to custom servlets as well to enable JSP taglib integration in them as well.
    • Constructor Detail

      • TaglibFactory

        public TaglibFactory​(javax.servlet.ServletContext ctx)
        /** Creates a new JSP taglib factory that will be used to load JSP tag libraries and functions for the web application represented by the passed in ServletContext. You should at least call setObjectWrapper(ObjectWrapper) before start using this object.

        This object is only thread-safe after you have stopped calling its setter methods (and it was properly published to the other threads; see JSR 133 (Java Memory Model)).

        Parameters:
        ctx - The servlet context whose JSP tag libraries this factory will load.
    • Method Detail

      • get

        public TemplateModel get​(String taglibUri)
                          throws TemplateModelException
        Retrieves a JSP tag library identified by an URI. The matching of the URI to a JSP taglib is done as described in the JSP 1.2 FCS specification.
        Specified by:
        get in interface TemplateHashModel
        Parameters:
        taglibUri - The URI used in templates to refer to the taglib (like <%@ taglib uri="..." ... %> in JSP). It can be any of the three forms allowed by the JSP specification: absolute URI (like http://example.com/foo), root relative URI (like /bar/foo.tld) and non-root relative URI (like bar/foo.tld). Note that if a non-root relative URI is used it's resolved relative to the URL of the current request. In this case, the current request is obtained by looking up a HttpRequestHashModel object named Request in the root data model. FreemarkerServlet provides this object under the expected name, and custom servlets that want to integrate JSP taglib support should do the same.
        Returns:
        a TemplateHashModel representing the JSP taglib. Each element of this hash represents a single custom tag or EL function from the library, implemented as a TemplateTransformModel or TemplateMethodModelEx, respectively.
        Throws:
        TemplateModelException
      • setObjectWrapper

        public void setObjectWrapper​(ObjectWrapper objectWrapper)
        Sets the ObjectWrapper used when building the JSP tag library TemplateHashModel-s from the TLD-s. Usually, it should be the same ObjectWrapper that will be used inside the templates. null value is only supported for backward compatibility. For custom EL functions to be exposed, it must be non-null and an intanceof BeansWrapper (like typically, a DefaultObjectWrapper).
        Since:
        2.3.22
      • setClasspathTlds

        public void setClasspathTlds​(List classpathTlds)
        Sets the class-loader resource paths of the TLD-s that aren't inside the locations covered by setMetaInfTldSources(List), yet you want them to be discovered. They will be loaded with the class loader provided by the servlet container.

        This is usually set via the init-params of FreemarkerServlet.

        Parameters:
        classpathTlds - List of String-s, maybe null. Each item is a resource path, like "/META-INF/my.tld". (Relative resource paths will be interpreted as root-relative.)
        Since:
        2.3.22
        See Also:
        setMetaInfTldSources(List)