public class TaglibFactory extends java.lang.Object implements TemplateHashModel
FreemarkerServlet
under key JspTaglibs
. It can be added to custom servlets as
well to enable JSP taglib integration in them as well.Modifier and Type | Class and 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.
|
Modifier and Type | Field and Description |
---|---|
static java.util.List |
DEFAULT_CLASSPATH_TLDS
The default of
getClasspathTlds() ; an empty list. |
static java.util.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. |
NOTHING
Constructor and 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 in
ServletContext . |
Modifier and Type | Method and 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 by
setMetaInfTldSources(List) , yet you want them to be discovered. |
void |
setMetaInfTldSources(java.util.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. |
public static final java.util.List DEFAULT_CLASSPATH_TLDS
getClasspathTlds()
; an empty list.public static final java.util.List DEFAULT_META_INF_TLD_SOURCES
getMetaInfTldSources()
; a list that contains
TaglibFactory.WebInfPerLibJarMetaInfTldSource.INSTANCE
, which gives the behavior described in the JSP 2.2
specification.public TaglibFactory(javax.servlet.ServletContext ctx)
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.public TemplateModel get(java.lang.String taglibUri) throws TemplateModelException
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
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.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.TemplateModelException
public boolean isEmpty()
isEmpty
in interface TemplateHashModel
public ObjectWrapper getObjectWrapper()
public void setObjectWrapper(ObjectWrapper objectWrapper)
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
).public java.util.List getMetaInfTldSources()
public void setMetaInfTldSources(java.util.List metaInfTldSources)
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.setClasspathTlds(List)
public java.util.List getClasspathTlds()
public void setClasspathTlds(java.util.List classpathTlds)
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.)setMetaInfTldSources(List)