Class TilesTool
- java.lang.Object
-
- org.apache.velocity.tools.view.ImportSupport
-
- org.apache.velocity.tools.struts.TilesTool
-
@DefaultKey("tiles") @ValidScope("request") public class TilesTool extends ImportSupport
The TilesTool is used to interact with the Struts-Tiles framework that is part of Struts 1.
Template example(s): <!-- insert a tile --> $tiles.myTileDefinition <!-- get named attribute value from the current tiles-context --> $tiles.getAttribute("myTileAttribute") <!-- import all attributes of the current tiles-context into the velocity-context. --> $tiles.importAttributes() Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.struts.TilesTool"/> </toolbox> </tools>
This tool may only be used in the request scope.
- Since:
- VelocityTools 1.1
- Version:
- $Revision: 601976 $ $Date: 2007-12-06 19:50:51 -0800 (Thu, 06 Dec 2007) $
- Author:
- Marino A. Jonsson
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.velocity.tools.view.ImportSupport
ImportSupport.ImportResponseWrapper, ImportSupport.SafeClosingHttpURLConnectionReader
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
APPLICATION_SCOPE
protected boolean
catchExceptions
Indicates if there is a MethodExceptionEventHandler presentprotected java.util.Stack
contextStack
A stack to hold ComponentContexts while nested tile-definitions are rendered.(package private) static java.lang.String
PAGE_SCOPE
(package private) static java.lang.String
REQUEST_SCOPE
(package private) static java.lang.String
SESSION_SCOPE
protected org.apache.velocity.context.Context
velocityContext
-
Fields inherited from class org.apache.velocity.tools.view.ImportSupport
application, DEFAULT_ENCODING, LOG, request, response, VALID_SCHEME_CHARS
-
-
Constructor Summary
Constructors Constructor Description TilesTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected java.lang.String
doInsert(ComponentContext subCompContext, java.lang.String page, java.lang.String role, Controller controller)
An extension of the other two doInsert functionsprotected java.lang.String
doInsert(java.lang.String page, java.lang.String role, Controller controller)
Use this if there is no nested tile.protected java.lang.String
doInsert(java.util.Map attributes, java.lang.String page, java.lang.String role, Controller controller)
Use this if there is a nested tile.java.lang.String
get(java.lang.Object obj)
A generic tiles insert function.java.lang.Object
getAttribute(java.lang.String name)
Fetches a named attribute-value from the current tiles-context.protected ComponentContext
getCurrentContext()
Retrieve the current tiles component context.void
importAttribute(java.lang.String name)
Imports the named attribute-value from the current tiles-context into the current Velocity context.void
importAttribute(java.lang.String name, java.lang.String scope)
Imports the named attribute-value from the current tiles-context into the named context ("page", "request", "session", or "application").void
importAttributes()
Imports all attributes in the current tiles-context into the current velocity-context.void
importAttributes(java.lang.String scope)
Imports all attributes in the current tiles-context into the named context ("page", "request", "session", or "application").void
init(java.lang.Object obj)
Deprecated.protected void
popTilesContext()
Pops the tiles sub-context off the context-stack after the lower level tiles have been rendered.protected java.lang.String
processAsDefinitionOrURL(java.lang.String name)
Try to process name as a definition, or as an URL if not found.protected java.lang.String
processDefinition(ComponentDefinition definition)
End of Process for definition.protected java.lang.String
processObjectValue(java.lang.Object value)
Process an object retrieved as a bean or attribute.protected java.lang.String
processTypedAttribute(AttributeDefinition value)
Process typed attribute according to its type.protected java.lang.String
processUrl(java.lang.String url)
Processes an urlprotected void
pushTilesContext()
pushes the current tiles context onto the context-stack.void
setCatchExceptions(boolean catchExceptions)
void
setVelocityContext(org.apache.velocity.context.Context context)
Initializes this tool.-
Methods inherited from class org.apache.velocity.tools.view.ImportSupport
acquireReader, acquireString, getContentTypeAttribute, isAbsoluteUrl, setLog, setRequest, setResponse, setServletContext, stripSession
-
-
-
-
Field Detail
-
PAGE_SCOPE
static final java.lang.String PAGE_SCOPE
- See Also:
- Constant Field Values
-
REQUEST_SCOPE
static final java.lang.String REQUEST_SCOPE
- See Also:
- Constant Field Values
-
SESSION_SCOPE
static final java.lang.String SESSION_SCOPE
- See Also:
- Constant Field Values
-
APPLICATION_SCOPE
static final java.lang.String APPLICATION_SCOPE
- See Also:
- Constant Field Values
-
velocityContext
protected org.apache.velocity.context.Context velocityContext
-
contextStack
protected java.util.Stack contextStack
A stack to hold ComponentContexts while nested tile-definitions are rendered.
-
catchExceptions
protected boolean catchExceptions
Indicates if there is a MethodExceptionEventHandler present
-
-
Method Detail
-
init
@Deprecated public void init(java.lang.Object obj)
Deprecated.Constructors
-
setVelocityContext
public void setVelocityContext(org.apache.velocity.context.Context context)
Initializes this tool.- Parameters:
context
- the currentContext
- Throws:
java.lang.IllegalArgumentException
- if the param is not aContext
-
setCatchExceptions
public void setCatchExceptions(boolean catchExceptions)
-
get
public java.lang.String get(java.lang.Object obj) throws java.lang.Exception
A generic tiles insert function.This is functionally equivalent to
<tiles:insert attribute="foo" />
.- Parameters:
obj
- Can be any of the following: AttributeDefinition, tile-definition name, tile-attribute name, regular uri. (checked in that order)- Returns:
- the rendered template or value as a String
- Throws:
java.lang.Exception
- on failure
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Fetches a named attribute-value from the current tiles-context.This is functionally equivalent to
<tiles:getAsString name="foo" />
.- Parameters:
name
- the name of the tiles-attribute to fetch- Returns:
- attribute value for the named attribute
-
importAttribute
public void importAttribute(java.lang.String name)
Imports the named attribute-value from the current tiles-context into the current Velocity context.This is functionally equivalent to
<tiles:importAttribute name="foo" />
- Parameters:
name
- the name of the tiles-attribute to import
-
importAttribute
public void importAttribute(java.lang.String name, java.lang.String scope)
Imports the named attribute-value from the current tiles-context into the named context ("page", "request", "session", or "application").This is functionally equivalent to
<tiles:importAttribute name="foo" scope="scopeValue" />
- Parameters:
name
- the name of the tiles-attribute to importscope
- the named context scope to put the attribute into.
-
importAttributes
public void importAttributes()
Imports all attributes in the current tiles-context into the current velocity-context.This is functionally equivalent to
<tiles:importAttribute />
.
-
importAttributes
public void importAttributes(java.lang.String scope)
Imports all attributes in the current tiles-context into the named context ("page", "request", "session", or "application").This is functionally equivalent to
<tiles:importAttribute scope="scopeValue" />
.- Parameters:
scope
- the named context scope to put the attributes into.
-
processObjectValue
protected java.lang.String processObjectValue(java.lang.Object value) throws java.lang.Exception
Process an object retrieved as a bean or attribute.- Parameters:
value
- - Object can be a typed attribute, a String, or anything else. If typed attribute, use associated type. Otherwise, apply toString() on object, and use returned string as a name.- Returns:
- the fully processed value as String
- Throws:
java.lang.Exception
- - Throws by underlying nested call to processDefinitionName()
-
processTypedAttribute
protected java.lang.String processTypedAttribute(AttributeDefinition value) throws java.lang.Exception
Process typed attribute according to its type.- Parameters:
value
- Typed attribute to process.- Returns:
- the fully processed attribute value as String.
- Throws:
java.lang.Exception
- - Throws by underlying nested call to processDefinitionName()
-
processAsDefinitionOrURL
protected java.lang.String processAsDefinitionOrURL(java.lang.String name) throws java.lang.Exception
Try to process name as a definition, or as an URL if not found.- Parameters:
name
- Name to process.- Returns:
- the fully processed definition or URL
- Throws:
java.lang.Exception
-
processDefinition
protected java.lang.String processDefinition(ComponentDefinition definition) throws java.lang.Exception
End of Process for definition.- Parameters:
definition
- Definition to process.- Returns:
- the fully processed definition.
- Throws:
java.lang.Exception
- from InstantiationException Can't create requested controller
-
processUrl
protected java.lang.String processUrl(java.lang.String url) throws java.lang.Exception
Processes an url- Parameters:
url
- the URI to process.- Returns:
- the rendered template as String.
- Throws:
java.lang.Exception
-
doInsert
protected java.lang.String doInsert(java.lang.String page, java.lang.String role, Controller controller) throws java.lang.Exception
Use this if there is no nested tile.- Parameters:
page
- the page to process.role
- possible user-rolecontroller
- possible tiles-controller- Returns:
- the rendered template as String.
- Throws:
java.lang.Exception
-
doInsert
protected java.lang.String doInsert(java.util.Map attributes, java.lang.String page, java.lang.String role, Controller controller) throws java.lang.Exception
Use this if there is a nested tile.- Parameters:
attributes
- attributes for the sub-contextpage
- the page to process.role
- possible user-rolecontroller
- possible tiles-controller- Returns:
- the rendered template as String.
- Throws:
java.lang.Exception
-
doInsert
protected java.lang.String doInsert(ComponentContext subCompContext, java.lang.String page, java.lang.String role, Controller controller) throws java.lang.Exception
An extension of the other two doInsert functions- Parameters:
subCompContext
- the sub-context to set in scope when the template is rendered.page
- the page to process.role
- possible user-rolecontroller
- possible tiles-controller- Returns:
- the rendered template as String.
- Throws:
java.lang.Exception
-
getCurrentContext
protected ComponentContext getCurrentContext()
Retrieve the current tiles component context. This is pretty much just a convenience method.
-
pushTilesContext
protected void pushTilesContext()
pushes the current tiles context onto the context-stack. preserving the context is necessary so that a sub-context can be put into request scope and lower level tiles can be rendered
-
popTilesContext
protected void popTilesContext()
Pops the tiles sub-context off the context-stack after the lower level tiles have been rendered.
-
-