public class JellyContext extends Object
JellyContext
represents the Jelly context.
Modifier and Type | Field and Description |
---|---|
protected ClassLoader |
classLoader
The class loader to use for instantiating application objects.
|
protected boolean |
useContextClassLoader
Do we want to use the Context ClassLoader when loading classes
for instantiating new objects? Default is
false . |
Constructor and Description |
---|
JellyContext()
Create a new context with the currentURL set to the rootURL
|
JellyContext(JellyContext parent)
Create a new context with the given parent context.
|
JellyContext(JellyContext parentJellyContext,
URL currentURL)
Create a new context with the given parent context.
|
JellyContext(JellyContext parentJellyContext,
URL rootURL,
URL currentURL)
Create a new context with the given parent context.
|
JellyContext(URL rootURL)
Create a new context with the given rootURL
|
JellyContext(URL rootURL,
URL currentURL)
Create a new context with the given rootURL and currentURL
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears variables set by Tags.
|
protected void |
clearVariables()
Clears variables set by Tags (variables set while running a Jelly script)
|
Script |
compileScript(InputSource source)
Attempts to parse the script from the given InputSource using the
getResource(java.lang.String) method then returns the compiled script. |
Script |
compileScript(String uri)
Attempts to parse the script from the given uri using the
getResource(java.lang.String) method then returns the compiled script. |
Script |
compileScript(URL url)
Attempts to parse the script from the given URL using the
getResource(java.lang.String) method then returns the compiled script. |
protected JellyContext |
createChildContext()
Factory method to create a new child of this context
|
protected URL |
createRelativeURL(URL rootURL,
String relativeURI) |
protected XMLParser |
createXMLParser()
Factory method to allow JellyContext implementations to overload how an XMLParser
is created - such as to overload what the default ExpressionFactory should be.
|
Object |
findVariable(String name)
Finds the variable value of the given name in this context or in any other parent context.
|
ClassLoader |
getClassLoader()
Return the class loader to be used for instantiating application objects
when required.
|
URL |
getCurrentURL() |
protected URL |
getJellyContextURL(InputSource source)
Strips off the name of a script to create a new context URL
|
protected URL |
getJellyContextURL(URL url)
Strips off the name of a script to create a new context URL
|
JellyContext |
getParent() |
URL |
getResource(String uri)
Returns a URL for the given resource from the specified path.
|
InputStream |
getResourceAsStream(String uri)
Attempts to open an InputStream to the given resource at the specified path.
|
URL |
getRootURL() |
JellyContext |
getScope(String name) |
TagLibrary |
getTagLibrary(String namespaceURI) |
boolean |
getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.
|
Object |
getVariable(String name) |
Object |
getVariable(String name,
String scopeName) |
Iterator |
getVariableNames() |
Map |
getVariables() |
Object |
getVariableWithDefaultValue(String name,
Object defaultValue)
Gets the value of the variable, or if it's not defined, return the given default value object.
|
protected XMLParser |
getXMLParser() |
boolean |
isCacheTags()
Returns whether caching of Tag instances, per thread, is enabled.
|
boolean |
isExport() |
boolean |
isExportLibraries()
Returns whether we export tag libraries to our parents context
|
boolean |
isInherit() |
boolean |
isTagLibraryRegistered(String namespaceURI) |
JellyContext |
newJellyContext()
A factory method to create a new child context of the
current context.
|
JellyContext |
newJellyContext(Map newVariables)
A factory method to create a new child context of the
current context.
|
void |
registerTagLibrary(String namespaceURI,
String className)
Registers the given tag library class name against the given namespace URI.
|
void |
registerTagLibrary(String namespaceURI,
TagLibrary taglib)
Registers the given tag library against the given namespace URI.
|
void |
removeVariable(String name)
Removes the given variable
|
void |
removeVariable(String name,
String scopeName)
Removes the given variable in the specified scope.
|
JellyContext |
runScript(File file,
XMLOutput output)
Parses the script from the given File then compiles it and runs it.
|
JellyContext |
runScript(File file,
XMLOutput output,
boolean export,
boolean inherit)
Parses the script from the given file then compiles it and runs it.
|
JellyContext |
runScript(InputSource source,
XMLOutput output)
Parses the script from the given InputSource then compiles it and runs it.
|
JellyContext |
runScript(InputSource source,
XMLOutput output,
boolean export,
boolean inherit)
Parses the script from the given InputSource then compiles it and runs it.
|
JellyContext |
runScript(String uri,
XMLOutput output)
Parses the script from the given uri using the
JellyContext.getResource() API then compiles it and runs it.
|
JellyContext |
runScript(String uri,
XMLOutput output,
boolean export,
boolean inherit)
Parses the script from the given uri using the
JellyContext.getResource() API then compiles it and runs it.
|
JellyContext |
runScript(URL url,
XMLOutput output)
Parses the script from the given URL then compiles it and runs it.
|
JellyContext |
runScript(URL url,
XMLOutput output,
boolean export,
boolean inherit)
Parses the script from the given URL then compiles it and runs it.
|
void |
setCacheTags(boolean cacheTags)
Sets whether caching of Tag instances, per thread, is enabled.
|
void |
setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects
when required.
|
void |
setCurrentURL(URL currentURL)
Sets the current URL context of the current script that is executing.
|
void |
setExport(boolean export)
Sets whether we should export variable definitions to our parent context
|
void |
setExportLibraries(boolean exportLibraries)
Sets whether we export tag libraries to our parents context
|
void |
setInherit(boolean inherit)
Sets whether we should inherit variables from our parent context
|
protected void |
setParent(JellyContext context)
Change the parent context to the one provided
|
void |
setRootURL(URL rootURL)
Sets the current root context URL from which all absolute resource URIs
will be relative to.
|
void |
setUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by
calling
Thread.currentThread().getContextClassLoader() )
to resolve/load classes. |
void |
setVariable(String name,
Object value)
Sets the value of the named variable
|
void |
setVariable(String name,
String scopeName,
Object value)
Sets the value of the given variable name in the given variable scope
|
void |
setVariables(Map variables)
Sets the Map of variables to use
|
protected ClassLoader classLoader
useContextClassLoader
variable.protected boolean useContextClassLoader
false
.public JellyContext()
public JellyContext(URL rootURL)
rootURL
- the root URL used in resolving absolute resources i.e. those starting with '/'public JellyContext(URL rootURL, URL currentURL)
rootURL
- the root URL used in resolving absolute resources i.e. those starting with '/'currentURL
- the root URL used in resolving relative resourcespublic JellyContext(JellyContext parent)
parentScope
.parent
- the parent context for the newly created context.public JellyContext(JellyContext parentJellyContext, URL currentURL)
parentScope
.parentJellyContext
- the parent context for the newly created context.currentURL
- the root URL used in resolving relative resourcespublic JellyContext(JellyContext parentJellyContext, URL rootURL, URL currentURL)
parentScope
.parentJellyContext
- the parent context for the newly created context.rootURL
- the root URL used in resolving absolute resources i.e. those starting with '/'currentURL
- the root URL used in resolving relative resourcespublic JellyContext getParent()
public JellyContext getScope(String name)
public Object findVariable(String name)
public Object getVariableWithDefaultValue(String name, Object defaultValue)
public Object getVariable(String name, String scopeName)
name
- is the name of the variablescopeName
- is the optional scope name such as 'parent'. For servlet environments
this could be 'application', 'session' or 'request'.public void setVariable(String name, String scopeName, Object value)
name
- is the name of the variablescopeName
- is the optional scope name such as 'parent'. For servlet environments
this could be 'application', 'session' or 'request'.value
- is the value of the attributepublic void removeVariable(String name)
public void removeVariable(String name, String scopeName)
name
- is the name of the variablescopeName
- is the optional scope name such as 'parent'. For servlet environments
this could be 'application', 'session' or 'request'.public Iterator getVariableNames()
public Map getVariables()
public void setVariables(Map variables)
public JellyContext newJellyContext(Map newVariables)
public JellyContext newJellyContext()
public void clear()
clearVariables()
protected void clearVariables()
clear()
public void registerTagLibrary(String namespaceURI, TagLibrary taglib)
public void registerTagLibrary(String namespaceURI, String className)
public boolean isTagLibraryRegistered(String namespaceURI)
public TagLibrary getTagLibrary(String namespaceURI)
public Script compileScript(String uri) throws JellyException
getResource(java.lang.String)
method then returns the compiled script.JellyException
public Script compileScript(URL url) throws JellyException
getResource(java.lang.String)
method then returns the compiled script.JellyException
public Script compileScript(InputSource source) throws JellyException
getResource(java.lang.String)
method then returns the compiled script.JellyException
protected XMLParser getXMLParser()
protected XMLParser createXMLParser()
public JellyContext runScript(File file, XMLOutput output) throws JellyException
JellyException
public JellyContext runScript(URL url, XMLOutput output) throws JellyException
JellyException
public JellyContext runScript(InputSource source, XMLOutput output) throws JellyException
JellyException
public JellyContext runScript(String uri, XMLOutput output) throws JellyException
JellyException
public JellyContext runScript(String uri, XMLOutput output, boolean export, boolean inherit) throws JellyException
JellyException
public JellyContext runScript(File file, XMLOutput output, boolean export, boolean inherit) throws JellyException
JellyException
public JellyContext runScript(URL url, XMLOutput output, boolean export, boolean inherit) throws JellyException
JellyException
public JellyContext runScript(InputSource source, XMLOutput output, boolean export, boolean inherit) throws JellyException
JellyException
public URL getResource(String uri) throws MalformedURLException
MalformedURLException
public InputStream getResourceAsStream(String uri)
public URL getRootURL()
public void setRootURL(URL rootURL)
public URL getCurrentURL()
getResource(java.lang.String)
to process relative scripts.public void setCurrentURL(URL currentURL)
getResource(java.lang.String)
to process relative scripts.public boolean isCacheTags()
public void setCacheTags(boolean cacheTags)
cacheTags
- Whether caching should be enabled or disabled.public boolean isExportLibraries()
public void setExportLibraries(boolean exportLibraries)
exportLibraries
- The exportLibraries to setpublic void setExport(boolean export)
public boolean isExport()
public void setInherit(boolean inherit)
public boolean isInherit()
public ClassLoader getClassLoader()
setClassLoader()
, if anyuseContextClassLoader
property is set to truepublic void setClassLoader(ClassLoader classLoader)
classLoader
- The new class loader to use, or null
to revert to the standard rulespublic boolean getUseContextClassLoader()
public void setUseContextClassLoader(boolean use)
Thread.currentThread().getContextClassLoader()
)
to resolve/load classes. If not
using Context ClassLoader, then the class-loading defaults to
using the calling-class' ClassLoader.use
- determines whether to use JellyContext ClassLoader.protected URL createRelativeURL(URL rootURL, String relativeURI) throws MalformedURLException
rootURL
- is the root context from which the relative URI will be appliedrelativeURI
- is the relative URI (without a leading "/")MalformedURLException
- if the URL is invalid.protected URL getJellyContextURL(URL url) throws MalformedURLException
MalformedURLException
protected URL getJellyContextURL(InputSource source) throws MalformedURLException
MalformedURLException
protected JellyContext createChildContext()
protected void setParent(JellyContext context)
context
- the new parent contextCopyright © 2014 Apache Software Foundation. All rights reserved.