Package freemarker.ext.jsp
Class TaglibFactory
- java.lang.Object
-
- freemarker.ext.jsp.TaglibFactory
-
- All Implemented Interfaces:
TemplateHashModel
,TemplateModel
public class TaglibFactory extends java.lang.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 byFreemarkerServlet
under keyJspTaglibs
. It can be added to custom servlets as well to enable JSP taglib integration in them as well.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TaglibFactory.ClasspathMetaInfTldSource
To search TLD-s underMETA-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 theTaglibFactory.MetaInfTldSource
list, allTaglibFactory.MetaInfTldSource
-s before it will be disabled.static class
TaglibFactory.MetaInfTldSource
A location within which we will look forMETA-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 java.util.List
DEFAULT_CLASSPATH_TLDS
The default ofgetClasspathTlds()
; an empty list.static java.util.List
DEFAULT_META_INF_TLD_SOURCES
The default ofgetMetaInfTldSources()
; a list that containsTaglibFactory.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(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 inServletContext
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TemplateModel
get(java.lang.String taglibUri)
Retrieves a JSP tag library identified by an URI.java.util.List
getClasspathTlds()
java.util.List
getMetaInfTldSources()
ObjectWrapper
getObjectWrapper()
boolean
isEmpty()
Returns false.void
setClasspathTlds(java.util.List classpathTlds)
Sets the class-loader resource paths of the TLD-s that aren't inside the locations covered bysetMetaInfTldSources(List)
, yet you want them to be discovered.void
setMetaInfTldSources(java.util.List metaInfTldSources)
Sets the list of places where we will look forMETA-INF/**
/*.tld
files.void
setObjectWrapper(ObjectWrapper objectWrapper)
Sets theObjectWrapper
used when building the JSP tag libraryTemplateHashModel
-s from the TLD-s.
-
-
-
Field Detail
-
DEFAULT_CLASSPATH_TLDS
public static final java.util.List DEFAULT_CLASSPATH_TLDS
The default ofgetClasspathTlds()
; an empty list.- Since:
- 2.3.22
-
DEFAULT_META_INF_TLD_SOURCES
public static final java.util.List DEFAULT_META_INF_TLD_SOURCES
The default ofgetMetaInfTldSources()
; a list that containsTaglibFactory.WebInfPerLibJarMetaInfTldSource.INSTANCE
, which gives the behavior described in the JSP 2.2 specification.- Since:
- 2.3.22
-
-
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 inServletContext
. You should at least callsetObjectWrapper(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(java.lang.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 interfaceTemplateHashModel
- 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 (likehttp://example.com/foo
), root relative URI (like/bar/foo.tld
) and non-root relative URI (likebar/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 aHttpRequestHashModel
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 aTemplateTransformModel
orTemplateMethodModelEx
, respectively. - Throws:
TemplateModelException
-
isEmpty
public boolean isEmpty()
Returns false.- Specified by:
isEmpty
in interfaceTemplateHashModel
-
getObjectWrapper
public ObjectWrapper getObjectWrapper()
- Since:
- 2.3.22
-
setObjectWrapper
public void setObjectWrapper(ObjectWrapper objectWrapper)
Sets theObjectWrapper
used when building the JSP tag libraryTemplateHashModel
-s from the TLD-s. Usually, it should be the sameObjectWrapper
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 anintanceof
BeansWrapper
(like typically, aDefaultObjectWrapper
).- Since:
- 2.3.22
-
getMetaInfTldSources
public java.util.List getMetaInfTldSources()
- Since:
- 2.3.22
-
setMetaInfTldSources
public void setMetaInfTldSources(java.util.List metaInfTldSources)
Sets the list of places where we will look forMETA-INF/**
/*.tld
files. By default this is a list that only containsTaglibFactory.WebInfPerLibJarMetaInfTldSource.INSTANCE
. This corresponds to the behavior that the JSP specification describes. See theTaglibFactory.MetaInfTldSource
subclasses for the possible values and their meanings.This is usually set via the init-params of
FreemarkerServlet
.- Parameters:
metaInfTldSources
- The list ofTaglibFactory.MetaInfTldSource
subclass instances. Their order matters if multiple TLD-s define a taglib with the sametaglib-uri
. In that case, the one found by the earlierTaglibFactory.MetaInfTldSource
wins.- Since:
- 2.3.22
- See Also:
setClasspathTlds(List)
-
getClasspathTlds
public java.util.List getClasspathTlds()
- Since:
- 2.3.22
-
setClasspathTlds
public void setClasspathTlds(java.util.List classpathTlds)
Sets the class-loader resource paths of the TLD-s that aren't inside the locations covered bysetMetaInfTldSources(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 ofString
-s, maybenull
. 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)
-
-