org.apache.struts.taglib
クラス TagUtils

java.lang.Object
  拡張org.apache.struts.taglib.TagUtils

public class TagUtils
extends java.lang.Object

Provides helper methods for JSP tags.

導入されたバージョン:
Struts 1.2
バージョン:
$Revision: 1.1 $

フィールドの概要
private static java.lang.reflect.Method encode
          Java 1.4 encode method to use instead of deprecated 1.3 version.
private static TagUtils instance
          The Singleton instance.
private static org.apache.commons.logging.Log log
          Commons logging instance.
private static MessageResources messages
          The message resources for this package.
private static java.util.Map scopes
          Maps lowercase JSP scope names to their PageContext integer constant values.
 
コンストラクタの概要
protected TagUtils()
          Constructor for TagUtils.
 
メソッドの概要
 java.util.Map computeParameters(javax.servlet.jsp.PageContext pageContext, java.lang.String paramId, java.lang.String paramName, java.lang.String paramProperty, java.lang.String paramScope, java.lang.String name, java.lang.String property, java.lang.String scope, boolean transaction)
          Compute a set of query parameters that will be dynamically added to a generated URL.
 java.lang.String computeURL(javax.servlet.jsp.PageContext pageContext, java.lang.String forward, java.lang.String href, java.lang.String page, java.lang.String action, java.lang.String module, java.util.Map params, java.lang.String anchor, boolean redirect)
           
 java.lang.String computeURL(javax.servlet.jsp.PageContext pageContext, java.lang.String forward, java.lang.String href, java.lang.String page, java.lang.String action, java.lang.String module, java.util.Map params, java.lang.String anchor, boolean redirect, boolean encodeSeparator)
           
 java.lang.String computeURLWithCharEncoding(javax.servlet.jsp.PageContext pageContext, java.lang.String forward, java.lang.String href, java.lang.String page, java.lang.String action, java.lang.String module, java.util.Map params, java.lang.String anchor, boolean redirect, boolean useLocalEncoding)
          Compute a hyperlink URL based on the forward, href, action or page parameter that is not null.
 java.lang.String computeURLWithCharEncoding(javax.servlet.jsp.PageContext pageContext, java.lang.String forward, java.lang.String href, java.lang.String page, java.lang.String action, java.lang.String module, java.util.Map params, java.lang.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.
 java.lang.String encodeURL(java.lang.String url)
          URLencodes a string assuming the character encoding is UTF-8.
 java.lang.String encodeURL(java.lang.String url, java.lang.String enc)
          Use the new URLEncoder.encode() method from Java 1.4 if available, else use the old deprecated version.
 java.lang.String filter(java.lang.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.
 ActionErrors getActionErrors(javax.servlet.jsp.PageContext pageContext, java.lang.String paramName)
          推奨されていません。 Use getActionMessages() instead. This will be removed after Struts 1.2.
 java.lang.String getActionMappingName(java.lang.String action)
          Return the form action converted into an action mapping path.
 java.lang.String getActionMappingURL(java.lang.String action, javax.servlet.jsp.PageContext pageContext)
          Return the form action converted into a server-relative URL.
 java.lang.String getActionMappingURL(java.lang.String action, java.lang.String module, javax.servlet.jsp.PageContext pageContext, boolean contextRelative)
          Return the form action converted into a server-relative URL.
 ActionMessages getActionMessages(javax.servlet.jsp.PageContext pageContext, java.lang.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(javax.servlet.jsp.PageContext pageContext)
          Return the ModuleConfig object if it exists, null if otherwise.
 ModuleConfig getModuleConfig(java.lang.String module, javax.servlet.jsp.PageContext pageContext)
          Return the ModuleConfig object for the given prefix if it exists, null if otherwise.
 int getScope(java.lang.String scopeName)
          Converts the scope name into its corresponding PageContext constant value.
 java.util.Locale getUserLocale(javax.servlet.jsp.PageContext pageContext, java.lang.String locale)
          Look up and return current user locale, based on the specified parameters.
 boolean isXhtml(javax.servlet.jsp.PageContext pageContext)
          Returns true if the custom tags are in XHTML mode.
 java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext, java.lang.String name, java.lang.String scopeName)
          Locate and return the specified bean, from an optionally specified scope, in the specified page context.
 java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext, java.lang.String name, java.lang.String property, java.lang.String scope)
          Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context.
 java.lang.String message(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key)
          Look up and return a message string, based on the specified parameters.
 java.lang.String message(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key, java.lang.Object[] args)
          Look up and return a message string, based on the specified parameters.
 java.lang.String pageURL(javax.servlet.http.HttpServletRequest request, java.lang.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(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key)
          Return true if a message string for the specified message key is present for the specified Locale.
private  MessageResources retrieveMessageResources(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, boolean checkPageScope)
          Returns the appropriate MessageResources object for the current module and the given bundle.
 void saveException(javax.servlet.jsp.PageContext pageContext, java.lang.Throwable exception)
          Save the specified exception as a request attribute for later use.
 void write(javax.servlet.jsp.PageContext pageContext, java.lang.String text)
          Write the specified text as the response to the writer associated with this page.
 void writePrevious(javax.servlet.jsp.PageContext pageContext, java.lang.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.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

instance

private static final TagUtils instance
The Singleton instance.


log

private static final org.apache.commons.logging.Log log
Commons logging instance.


messages

private static final MessageResources messages
The message resources for this package. TODO We need to move the relevant messages out of this properties file.


encode

private static java.lang.reflect.Method encode
Java 1.4 encode method to use instead of deprecated 1.3 version.


scopes

private static final java.util.Map scopes
Maps lowercase JSP scope names to their PageContext integer constant values.

コンストラクタの詳細

TagUtils

protected TagUtils()
Constructor for TagUtils.

メソッドの詳細

getInstance

public static TagUtils getInstance()
Returns the Singleton instance of TagUtils.


computeParameters

public java.util.Map computeParameters(javax.servlet.jsp.PageContext pageContext,
                                       java.lang.String paramId,
                                       java.lang.String paramName,
                                       java.lang.String paramProperty,
                                       java.lang.String paramScope,
                                       java.lang.String name,
                                       java.lang.String property,
                                       java.lang.String scope,
                                       boolean transaction)
                                throws javax.servlet.jsp.JspException
Compute a set of query parameters that will be dynamically added to a generated URL. The returned Map is keyed by parameter name, and the values are either null (no value specified), a String (single value specified), or a String[] array (multiple values specified). Parameter names correspond to the corresponding attributes of the <html:link> tag. If no query parameters are identified, return null.

パラメータ:
pageContext - PageContext we are operating in
paramId - Single-value request parameter name (if any)
paramName - Bean containing single-value parameter value
paramProperty - Property (of bean named by paramName containing single-value parameter value
paramScope - 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 Map
scope - Scope containing bean named by name
transaction - Should we add our transaction control token?
戻り値:
Map of query parameters
例外:
javax.servlet.jsp.JspException - if we cannot look up the required beans
javax.servlet.jsp.JspException - if a class cast exception occurs on a looked-up bean or property

computeURL

public java.lang.String computeURL(javax.servlet.jsp.PageContext pageContext,
                                   java.lang.String forward,
                                   java.lang.String href,
                                   java.lang.String page,
                                   java.lang.String action,
                                   java.lang.String module,
                                   java.util.Map params,
                                   java.lang.String anchor,
                                   boolean redirect)
                            throws java.net.MalformedURLException
例外:
java.net.MalformedURLException

computeURLWithCharEncoding

public java.lang.String computeURLWithCharEncoding(javax.servlet.jsp.PageContext pageContext,
                                                   java.lang.String forward,
                                                   java.lang.String href,
                                                   java.lang.String page,
                                                   java.lang.String action,
                                                   java.lang.String module,
                                                   java.util.Map params,
                                                   java.lang.String anchor,
                                                   boolean redirect,
                                                   boolean useLocalEncoding)
                                            throws java.net.MalformedURLException
Compute a hyperlink URL based on the 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 call
forward - 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()?
戻り値:
URL with session identifier
例外:
java.net.MalformedURLException - if a URL cannot be created for the specified parameters

computeURL

public java.lang.String computeURL(javax.servlet.jsp.PageContext pageContext,
                                   java.lang.String forward,
                                   java.lang.String href,
                                   java.lang.String page,
                                   java.lang.String action,
                                   java.lang.String module,
                                   java.util.Map params,
                                   java.lang.String anchor,
                                   boolean redirect,
                                   boolean encodeSeparator)
                            throws java.net.MalformedURLException
例外:
java.net.MalformedURLException

computeURLWithCharEncoding

public java.lang.String computeURLWithCharEncoding(javax.servlet.jsp.PageContext pageContext,
                                                   java.lang.String forward,
                                                   java.lang.String href,
                                                   java.lang.String page,
                                                   java.lang.String action,
                                                   java.lang.String module,
                                                   java.util.Map params,
                                                   java.lang.String anchor,
                                                   boolean redirect,
                                                   boolean encodeSeparator,
                                                   boolean useLocalEncoding)
                                            throws java.net.MalformedURLException
Compute a hyperlink URL based on the 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 call
forward - 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.
戻り値:
URL with session identifier
例外:
java.net.MalformedURLException - if a URL cannot be created for the specified parameters

encodeURL

public java.lang.String encodeURL(java.lang.String url)
URLencodes a string assuming the character encoding is UTF-8.

パラメータ:
url -
戻り値:
String The encoded url in UTF-8

encodeURL

public java.lang.String encodeURL(java.lang.String url,
                                  java.lang.String enc)
Use the new URLEncoder.encode() method from Java 1.4 if available, else use the old deprecated version. This method uses reflection to find the appropriate method; if the reflection operations throw exceptions, this will return the url encoded with the old URLEncoder.encode() method.

パラメータ:
enc - The character encoding the urlencode is performed on.
戻り値:
String The encoded url.

filter

public java.lang.String filter(java.lang.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.

パラメータ:
value - The string to be filtered and returned

getActionErrors

public ActionErrors getActionErrors(javax.servlet.jsp.PageContext pageContext,
                                    java.lang.String paramName)
                             throws javax.servlet.jsp.JspException
推奨されていません。 Use getActionMessages() instead. This will be removed after Struts 1.2.

Retrieves the value from request scope and if it isn't already an ErrorMessages some classes are converted to one.

パラメータ:
pageContext - The PageContext for the current page
paramName - Key for parameter value
戻り値:
ActionErrors from request scope
例外:
javax.servlet.jsp.JspException

getActionMappingName

public java.lang.String getActionMappingName(java.lang.String action)
Return the form action converted into an action mapping path. The value of the action property is manipulated as follows in computing the name of the requested mapping:


getActionMappingURL

public java.lang.String getActionMappingURL(java.lang.String action,
                                            javax.servlet.jsp.PageContext pageContext)
Return the form action converted into a server-relative URL.


getActionMappingURL

public java.lang.String getActionMappingURL(java.lang.String action,
                                            java.lang.String module,
                                            javax.servlet.jsp.PageContext pageContext,
                                            boolean contextRelative)
Return the form action converted into a server-relative URL.


getActionMessages

public ActionMessages getActionMessages(javax.servlet.jsp.PageContext pageContext,
                                        java.lang.String paramName)
                                 throws javax.servlet.jsp.JspException
Retrieves the value from request scope and if it isn't already an ActionMessages, some classes are converted to one.

パラメータ:
pageContext - The PageContext for the current page
paramName - Key for parameter value
戻り値:
ActionErrors in page context.
例外:
javax.servlet.jsp.JspException

getModuleConfig

public ModuleConfig getModuleConfig(javax.servlet.jsp.PageContext pageContext)
Return the ModuleConfig object if it exists, null if otherwise.

パラメータ:
pageContext - The page context.
戻り値:
the ModuleConfig object

getModuleConfig

public ModuleConfig getModuleConfig(java.lang.String module,
                                    javax.servlet.jsp.PageContext pageContext)
Return the ModuleConfig object for the given prefix if it exists, null if otherwise.

パラメータ:
module - The module prefix
pageContext - The page context.
戻り値:
the ModuleConfig object

getScope

public int getScope(java.lang.String scopeName)
             throws javax.servlet.jsp.JspException
Converts the scope name into its corresponding PageContext constant value.

パラメータ:
scopeName - Can be "page", "request", "session", or "application" in any case.
戻り値:
The constant representing the scope (ie. PageContext.REQUEST_SCOPE).
例外:
javax.servlet.jsp.JspException - if the scopeName is not a valid name.

getUserLocale

public java.util.Locale getUserLocale(javax.servlet.jsp.PageContext pageContext,
                                      java.lang.String locale)
Look up and return current user locale, based on the specified parameters.

パラメータ:
pageContext - The PageContext associated with this request
locale - Name of the session attribute for our user's Locale. If this is null, the default locale key is used for the lookup.
戻り値:
current user locale

isXhtml

public boolean isXhtml(javax.servlet.jsp.PageContext pageContext)
Returns true if the custom tags are in XHTML mode.


lookup

public java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext,
                               java.lang.String name,
                               java.lang.String scopeName)
                        throws javax.servlet.jsp.JspException
Locate and return the specified bean, from an optionally specified scope, in the specified page context. If no such bean is found, return null instead. If an exception is thrown, it will have already been saved via a call to saveException().

パラメータ:
pageContext - Page context to be searched
name - Name of the bean to be retrieved
scopeName - Scope to be searched (page, request, session, application) or null to use findAttribute() instead
戻り値:
JavaBean in the specified page context
例外:
javax.servlet.jsp.JspException - if an invalid scope name is requested

lookup

public java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext,
                               java.lang.String name,
                               java.lang.String property,
                               java.lang.String scope)
                        throws javax.servlet.jsp.JspException
Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context. If an exception is thrown, it will have already been saved via a call to saveException().

パラメータ:
pageContext - Page context to be searched
name - Name of the bean to be retrieved
property - Name of the property to be retrieved, or null to retrieve the bean itself
scope - Scope to be searched (page, request, session, application) or null to use findAttribute() instead
戻り値:
property of specified JavaBean
例外:
javax.servlet.jsp.JspException - if an invalid scope name is requested
javax.servlet.jsp.JspException - if the specified bean is not found
javax.servlet.jsp.JspException - if accessing this property causes an IllegalAccessException, IllegalArgumentException, InvocationTargetException, or NoSuchMethodException

message

public java.lang.String message(javax.servlet.jsp.PageContext pageContext,
                                java.lang.String bundle,
                                java.lang.String locale,
                                java.lang.String key)
                         throws javax.servlet.jsp.JspException
Look up and return a message string, based on the specified parameters.

パラメータ:
pageContext - The PageContext associated with this request
bundle - Name of the servlet context attribute for our message resources bundle
locale - Name of the session attribute for our user's Locale
key - Message key to be looked up and returned
戻り値:
message string
例外:
javax.servlet.jsp.JspException - if a lookup error occurs (will have been saved in the request already)

message

public java.lang.String message(javax.servlet.jsp.PageContext pageContext,
                                java.lang.String bundle,
                                java.lang.String locale,
                                java.lang.String key,
                                java.lang.Object[] args)
                         throws javax.servlet.jsp.JspException
Look up and return a message string, based on the specified parameters.

パラメータ:
pageContext - The PageContext associated with this request
bundle - Name of the servlet context attribute for our message resources bundle
locale - Name of the session attribute for our user's Locale
key - Message key to be looked up and returned
args - Replacement parameters for this message
戻り値:
message string
例外:
javax.servlet.jsp.JspException - if a lookup error occurs (will have been saved in the request already)

pageURL

public java.lang.String pageURL(javax.servlet.http.HttpServletRequest request,
                                java.lang.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 processing
page - The module-relative URL to be substituted in to the pagePattern pattern for the current module (MUST start with a slash)
戻り値:
context-relative URL

present

public boolean present(javax.servlet.jsp.PageContext pageContext,
                       java.lang.String bundle,
                       java.lang.String locale,
                       java.lang.String key)
                throws javax.servlet.jsp.JspException
Return true if a message string for the specified message key is present for the specified Locale.

パラメータ:
pageContext - The PageContext associated with this request
bundle - Name of the servlet context attribute for our message resources bundle
locale - Name of the session attribute for our user's Locale
key - Message key to be looked up and returned
戻り値:
true if a message string for message key exists
例外:
javax.servlet.jsp.JspException - if a lookup error occurs (will have been saved in the request already)

retrieveMessageResources

private MessageResources retrieveMessageResources(javax.servlet.jsp.PageContext pageContext,
                                                  java.lang.String bundle,
                                                  boolean checkPageScope)
                                           throws javax.servlet.jsp.JspException
Returns the appropriate MessageResources object for the current module and the given bundle.

パラメータ:
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.
戻り値:
MessageResources The bundle's resources stored in some scope.
例外:
javax.servlet.jsp.JspException - if the MessageResources object could not be found.

saveException

public void saveException(javax.servlet.jsp.PageContext pageContext,
                          java.lang.Throwable exception)
Save the specified exception as a request attribute for later use.

パラメータ:
pageContext - The PageContext for the current page
exception - The exception to be saved

write

public void write(javax.servlet.jsp.PageContext pageContext,
                  java.lang.String text)
           throws javax.servlet.jsp.JspException
Write the specified text as the response to the writer associated with this page. WARNING - If you are writing body content from the doAfterBody() method of a custom tag class that implements BodyTag, you should be calling writePrevious() instead.

パラメータ:
pageContext - The PageContext object for this page
text - The text to be written
例外:
javax.servlet.jsp.JspException - if an input/output error occurs (already saved)

writePrevious

public void writePrevious(javax.servlet.jsp.PageContext pageContext,
                          java.lang.String text)
                   throws javax.servlet.jsp.JspException
Write the specified text as the response to the writer associated with the body content for the tag within which we are currently nested.

パラメータ:
pageContext - The PageContext object for this page
text - The text to be written
例外:
javax.servlet.jsp.JspException - if an input/output error occurs (already saved)


このドキュメントは、Ja-Jakartaにより訳されました。コメントがある場合は、report@jajakarta.orgまでお願いします。
Copyright (C) 2000-2004 - Apache Software Foundation