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.

Note that this is for the legacy "javax" Servlet/JSP API; for Jakarta (that is, in modern Servlet containers), use freemarker.ext.jakarta.jsp.TaglibFactory instead (since 2.3.33).

  • Field Details

  • Constructor Details

    • 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)).

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

    • 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
      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, 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.
      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.
    • isEmpty

      public boolean isEmpty()
      Returns false.
      Specified by:
      isEmpty in interface TemplateHashModel
    • getObjectWrapper

      public ObjectWrapper getObjectWrapper()
    • 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).
    • getMetaInfTldSources

      public List getMetaInfTldSources()
    • setMetaInfTldSources

      public void setMetaInfTldSources(List metaInfTldSources)
      Sets the list of places where we will look for META-INF/**/*.tld files. By default this is a list that only contains TaglibFactory.WebInfPerLibJarMetaInfTldSource.INSTANCE. This corresponds to the behavior that the JSP specification describes. See the TaglibFactory.MetaInfTldSource subclasses for the possible values and their meanings.

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

      metaInfTldSources - The list of TaglibFactory.MetaInfTldSource subclass instances. Their order matters if multiple TLD-s define a taglib with the same taglib-uri. In that case, the one found by the earlier TaglibFactory.MetaInfTldSource wins.
      See Also:
    • getClasspathTlds

      public List getClasspathTlds()
    • 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. Otherwise it defaults to an empty list.

      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.)
      See Also: