|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.struts.taglib.TagUtils
public class TagUtils
Provides helper methods for JSP tags.
Constructor Summary | |
---|---|
protected |
TagUtils()
Constructor for TagUtils. |
Method Summary | |
---|---|
Map |
computeParameters(PageContext pageContext,
String paramId,
String paramName,
String paramProperty,
String paramScope,
String name,
String property,
String scope,
boolean transaction)
Compute a set of query parameters that will be dynamically added to a generated URL. |
String |
computeURL(PageContext pageContext,
String forward,
String href,
String page,
String action,
String module,
Map params,
String anchor,
boolean redirect)
|
String |
computeURL(PageContext pageContext,
String forward,
String href,
String page,
String action,
String module,
Map params,
String anchor,
boolean redirect,
boolean encodeSeparator)
|
String |
computeURLWithCharEncoding(PageContext pageContext,
String forward,
String href,
String page,
String action,
String module,
Map params,
String anchor,
boolean redirect,
boolean useLocalEncoding)
Compute a hyperlink URL based on the forward ,
href , action or page parameter
that is not null. |
String |
computeURLWithCharEncoding(PageContext pageContext,
String forward,
String href,
String page,
String action,
String module,
Map params,
String anchor,
boolean redirect,
boolean encodeSeparator,
boolean useLocalEncoding)
Compute a hyperlink URL based on the forward ,
href , action or page parameter
that is not null. |
String |
encodeURL(String url)
URLencodes a string assuming the character encoding is UTF-8. |
String |
encodeURL(String url,
String enc)
Use the new URLEncoder.encode() method from Java 1.4 if available, else use the old deprecated version. |
String |
filter(String value)
Filter the specified string for characters that are senstive to HTML interpreters, returning the string with these characters replaced by the corresponding character entities. |
String |
getActionMappingName(String action)
Return the form action converted into an action mapping path. |
String |
getActionMappingURL(String action,
PageContext pageContext)
Return the form action converted into a server-relative URL. |
String |
getActionMappingURL(String action,
String module,
PageContext pageContext,
boolean contextRelative)
Return the form action converted into a server-relative URL. |
ActionMessages |
getActionMessages(PageContext pageContext,
String paramName)
Retrieves the value from request scope and if it isn't already an ActionMessages , some classes are converted to one. |
static TagUtils |
getInstance()
Returns the Singleton instance of TagUtils. |
ModuleConfig |
getModuleConfig(PageContext pageContext)
Return the default ModuleConfig object if it exists, null if otherwise. |
ModuleConfig |
getModuleConfig(String module,
PageContext pageContext)
Return the specified ModuleConfig object for the given prefix if it exists, otherwise a NullPointerException will be thrown. |
int |
getScope(String scopeName)
Converts the scope name into its corresponding PageContext constant value. |
Locale |
getUserLocale(PageContext pageContext,
String locale)
Look up and return current user locale, based on the specified parameters. |
boolean |
isXhtml(PageContext pageContext)
Returns true if the custom tags are in XHTML mode. |
Object |
lookup(PageContext pageContext,
String name,
String scopeName)
Locate and return the specified bean, from an optionally specified scope, in the specified page context. |
Object |
lookup(PageContext pageContext,
String name,
String property,
String scope)
Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context. |
String |
message(PageContext pageContext,
String bundle,
String locale,
String key)
Look up and return a message string, based on the specified parameters. |
String |
message(PageContext pageContext,
String bundle,
String locale,
String key,
Object[] args)
Look up and return a message string, based on the specified parameters. |
String |
pageURL(HttpServletRequest request,
String page,
ModuleConfig moduleConfig)
Return the context-relative URL that corresponds to the specified page attribute value, calculated based on the
pagePattern property of the current module's ModuleConfig . |
boolean |
present(PageContext pageContext,
String bundle,
String locale,
String key)
Return true if a message string for the specified message key is present for the specified Locale and bundle. |
MessageResources |
retrieveMessageResources(PageContext pageContext,
String bundle,
boolean checkPageScope)
Returns the appropriate MessageResources object for the current module and the given bundle. |
void |
saveException(PageContext pageContext,
Throwable exception)
Save the specified exception as a request attribute for later use. |
static void |
setInstance(TagUtils instance)
Set the instance. |
void |
write(PageContext pageContext,
String text)
Write the specified text as the response to the writer associated with this page. |
void |
writePrevious(PageContext pageContext,
String text)
Write the specified text as the response to the writer associated with the body content for the tag within which we are currently nested. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected TagUtils()
Method Detail |
---|
public static TagUtils getInstance()
public static void setInstance(TagUtils instance)
instance
- The instance to set.public Map computeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction) throws JspException
<html:link>
tag. If no query parameters are
identified, return null
.
pageContext
- PageContext we are operating inparamId
- Single-value request parameter name (if any)paramName
- Bean containing single-value parameter valueparamProperty
- Property (of bean named by paramName
containing single-value parameter valueparamScope
- Scope containing bean named by paramName
name
- Bean containing multi-value parameters Map (if
any)property
- Property (of bean named by name
containing multi-value parameters Mapscope
- Scope containing bean named by name
transaction
- Should we add our transaction control token?
JspException
- if we cannot look up the required beans
JspException
- if a class cast exception occurs on a looked-up
bean or propertypublic String computeURL(PageContext pageContext, String forward, String href, String page, String action, String module, Map params, String anchor, boolean redirect) throws MalformedURLException
MalformedURLException
public String computeURLWithCharEncoding(PageContext pageContext, String forward, String href, String page, String action, String module, Map params, String anchor, boolean redirect, boolean useLocalEncoding) throws MalformedURLException
forward
,
href
, action
or page
parameter
that is not null. The returned URL will have already been passed to
response.encodeURL()
for adding a session identifier.
pageContext
- PageContext for the tag making this callforward
- Logical forward name for which to look up the
context-relative URI (if specified)href
- URL to be utilized unmodified (if specified)page
- Module-relative page for which a URL should be
created (if specified)action
- Logical action name for which to look up the
context-relative URI (if specified)params
- Map of parameters to be dynamically included (if
any)anchor
- Anchor to be dynamically included (if any)redirect
- Is this URL for a response.sendRedirect()
?
MalformedURLException
- if a URL cannot be created for
the specified parameterspublic String computeURL(PageContext pageContext, String forward, String href, String page, String action, String module, Map params, String anchor, boolean redirect, boolean encodeSeparator) throws MalformedURLException
MalformedURLException
public String computeURLWithCharEncoding(PageContext pageContext, String forward, String href, String page, String action, String module, Map params, String anchor, boolean redirect, boolean encodeSeparator, boolean useLocalEncoding) throws MalformedURLException
forward
,
href
, action
or page
parameter
that is not null. The returned URL will have already been passed to
response.encodeURL()
for adding a session identifier.
pageContext
- PageContext for the tag making this callforward
- Logical forward name for which to look up the
context-relative URI (if specified)href
- URL to be utilized unmodified (if specified)page
- Module-relative page for which a URL should be
created (if specified)action
- Logical action name for which to look up the
context-relative URI (if specified)params
- Map of parameters to be dynamically included
(if any)anchor
- Anchor to be dynamically included (if any)redirect
- Is this URL for a response.sendRedirect()
?encodeSeparator
- This is only checked if redirect is set to
false (never encoded for a redirect). If true,
query string parameter separators are encoded
as >amp;, else & is used.useLocalEncoding
- If set to true, urlencoding is done on the
bytes of character encoding from
ServletResponse#getCharacterEncoding. Use UTF-8
otherwise.
MalformedURLException
- if a URL cannot be created for
the specified parameterspublic String encodeURL(String url)
url
-
public String encodeURL(String url, String enc)
enc
- The character encoding the urlencode is performed on.
public String filter(String value)
value
- The string to be filtered and returnedpublic String getActionMappingName(String action)
action
property is manipulated as follows in
computing the name of the requested mapping:
public String getActionMappingURL(String action, PageContext pageContext)
public String getActionMappingURL(String action, String module, PageContext pageContext, boolean contextRelative)
public ActionMessages getActionMessages(PageContext pageContext, String paramName) throws JspException
ActionMessages
, some classes are converted to one.
pageContext
- The PageContext for the current pageparamName
- Key for parameter value
JspException
public ModuleConfig getModuleConfig(PageContext pageContext)
pageContext
- The page context.
public ModuleConfig getModuleConfig(String module, PageContext pageContext)
module
- The module prefixpageContext
- The page context.
NullPointerException
- Thrown when module cannot be foundpublic int getScope(String scopeName) throws JspException
scopeName
- Can be "page", "request", "session", or "application"
in any case.
JspException
- if the scopeName is not a valid name.public Locale getUserLocale(PageContext pageContext, String locale)
pageContext
- The PageContext associated with this requestlocale
- Name of the session attribute for our user's Locale.
If this is null
, the default locale key
is used for the lookup.
public boolean isXhtml(PageContext pageContext)
public Object lookup(PageContext pageContext, String name, String scopeName) throws JspException
null
instead. If an exception is thrown, it will have
already been saved via a call to saveException()
.
pageContext
- Page context to be searchedname
- Name of the bean to be retrievedscopeName
- Scope to be searched (page, request, session,
application) or null
to use
findAttribute()
instead
JspException
- if an invalid scope name is requestedpublic Object lookup(PageContext pageContext, String name, String property, String scope) throws JspException
saveException()
.
pageContext
- Page context to be searchedname
- Name of the bean to be retrievedproperty
- Name of the property to be retrieved, or
null
to retrieve the bean itselfscope
- Scope to be searched (page, request, session,
application) or null
to use
findAttribute()
instead
JspException
- if an invalid scope name is requested
JspException
- if the specified bean is not found
JspException
- if accessing this property causes an
IllegalAccessException, IllegalArgumentException,
InvocationTargetException, or NoSuchMethodExceptionpublic String message(PageContext pageContext, String bundle, String locale, String key) throws JspException
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our
message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returned
JspException
- if a lookup error occurs (will have been saved in
the request already)public String message(PageContext pageContext, String bundle, String locale, String key, Object[] args) throws JspException
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our
message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returnedargs
- Replacement parameters for this message
JspException
- if a lookup error occurs (will have been saved in
the request already)public String pageURL(HttpServletRequest request, String page, ModuleConfig moduleConfig)
Return the context-relative URL that corresponds to the specified
page
attribute value, calculated based on the
pagePattern
property of the current module's ModuleConfig
.
request
- The servlet request we are processingpage
- The module-relative URL to be substituted in to the
pagePattern
pattern for the current module
(MUST start with a slash)
public boolean present(PageContext pageContext, String bundle, String locale, String key) throws JspException
Locale
and bundle.
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our
message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returned
JspException
- if a lookup error occurs (will have been saved in
the request already)public MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope) throws JspException
pageContext
- Search the context's scopes for the resources.bundle
- The bundle name to look for. If this is
null
, the default bundle name is
used.checkPageScope
- Whether to check page scope
JspException
- if the MessageResources object could not be
found.public void saveException(PageContext pageContext, Throwable exception)
pageContext
- The PageContext for the current pageexception
- The exception to be savedpublic void write(PageContext pageContext, String text) throws JspException
doAfterBody()
method of a custom tag class that
implements BodyTag
, you should be calling
writePrevious()
instead.
pageContext
- The PageContext object for this pagetext
- The text to be written
JspException
- if an input/output error occurs (already saved)public void writePrevious(PageContext pageContext, String text) throws JspException
pageContext
- The PageContext object for this pagetext
- The text to be written
JspException
- if an input/output error occurs (already saved)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |