TaglibFactory (FreeMarker 2.3.35 API)
Description: declaration: package: freemarker.ext.jakarta.jsp, class: TaglibFactory

Package freemarker.ext.jakarta.jsp

# Class TaglibFactory

java.lang.Object
freemarker.ext.jakarta.jsp.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 there are two variants of this class: One for the legacy "javax" Servlet API in the `freemarker.ext``.jsp` package, and another for the newer Jakarta Servlet API in the `freemarker.ext``.jakarta.jsp` package (since 2.3.33). Use the variant that fits your Servlet container!

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `TaglibFactory.ClasspathMetaInfTldSource`
  To search TLD-s under `META-INF/**``/*.tld` inside classpath root containers, that is, in directories and jar-s that are in the classpath (or are visible for the class loader otherwise).
  `static class`
  `TaglibFactory.ClearMetaInfTldSource`
  When it occurs in the `TaglibFactory.MetaInfTldSource` list, all `TaglibFactory.MetaInfTldSource`-s before it will be disabled.
  `static class`
  `TaglibFactory.MetaInfTldSource`
  A location within which we will look for `META-INF/**``/*.tld`-s.
  `static class`
  `TaglibFactory.WebInfPerLibJarMetaInfTldSource`
  To search TLD-s under `sevletContext:/WEB-INF/lib/*.{jar,zip}/META-INF/**``/*.tld`, as requested by the JSP specification.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static List`
  `DEFAULT_CLASSPATH_TLDS`
  The default of `getClasspathTlds()`; an empty list.
  `static List`
  `DEFAULT_META_INF_TLD_SOURCES`
  The default of `getMetaInfTldSources()`; a list that contains `TaglibFactory.WebInfPerLibJarMetaInfTldSource.INSTANCE`, which gives the behavior described in the JSP 2.2 specification.

  ### Fields inherited from interface freemarker.template.TemplateModel

  `NOTHING`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TaglibFactory​(jakarta.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`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TemplateModel`
  `get​(String taglibUri)`
  Retrieves a JSP tag library identified by an URI.
  `List`
  `getClasspathTlds()`
  See `setClasspathTlds(List)`.
  `List`
  `getMetaInfTldSources()`
  See `setMetaInfTldSources(List)`.
  `ObjectWrapper`
  `getObjectWrapper()`
  See `setObjectWrapper(ObjectWrapper)`.
  `boolean`
  `isEmpty()`
  Returns false.
  `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.
  `void`
  `setMetaInfTldSources​(List metaInfTldSources)`
  Sets the list of places where we will look for `META-INF/**``/*.tld` files.
  `void`
  `setObjectWrapper​(ObjectWrapper objectWrapper)`
  Sets the `ObjectWrapper` used when building the JSP tag library `TemplateHashModel`-s from the TLD-s.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DEFAULT_CLASSPATH_TLDS

    public static final List DEFAULT_CLASSPATH_TLDS
    The default of `getClasspathTlds()`; an empty list.
    Since:
      2.3.22

  - ### DEFAULT_META_INF_TLD_SOURCES

    public static final List DEFAULT_META_INF_TLD_SOURCES
    The default of `getMetaInfTldSources()`; a list that contains `TaglibFactory.WebInfPerLibJarMetaInfTldSource.INSTANCE`, which gives the behavior described in the JSP 2.2 specification.
    Since:
      2.3.22

- ## Constructor Details

  - ### TaglibFactory

    public TaglibFactory​(jakarta.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 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`
    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`

  - ### isEmpty

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

  - ### getObjectWrapper

    public ObjectWrapper getObjectWrapper()
    See `setObjectWrapper(ObjectWrapper)`.
    Since:
      2.3.22

  - ### 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

  - ### getMetaInfTldSources

    public List getMetaInfTldSources()
    See `setMetaInfTldSources(List)`.
    Since:
      2.3.22

  - ### 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`.

    Parameters:
      `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.
    Since:
      2.3.22
    See Also:
      `setClasspathTlds(List)`

  - ### getClasspathTlds

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

    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)`