org.apache.beehive.netui.pageflow.internal
Class InternalUtils

Object
  extended by InternalUtils
All Implemented Interfaces:
PageFlowConstants

public class InternalUtils
extends Object
implements PageFlowConstants


Field Summary
 
Fields inherited from interface PageFlowConstants
ACTION_EXTENSION, ACTION_OVERRIDE, AUTO_VIEW_RENDER_FORWARD_NAME, BEGIN_ACTION_NAME, DEFAULT_FORWARD_OVERFLOW_COUNT, DEFAULT_NESTING_OVERFLOW_COUNT, FORWARD_OVERFLOW_COUNT_PARAM, GLOBALAPP_CLASSNAME, GLOBALAPP_SOURCEFILE_NAME, JPF_EXTENSION, JPF_MODULE_CONFIG_EXTENSION, JPF_MODULE_CONFIG_GEN_DIR, JPF_MODULE_CONFIG_PREFIX, NESTING_OVERFLOW_COUNT_PARAM, PAGEFLOW_EXTENSION, PAGEFLOW_MODULE_CONFIG_EXTENSION, PAGEFLOW_MODULE_CONFIG_GEN_DIR, PAGEFLOW_MODULE_CONFIG_PREFIX, SECURE_FORWARDS_PARAM
 
Constructor Summary
InternalUtils()
           
 
Method Summary
static void addActionError(String propertyName, ActionMessage error, ServletRequest request)
           
static void addActionOutputs(Map toAdd, ServletRequest request, boolean overwrite)
           
static void addBindingUpdateError(ServletRequest request, String expression, String message, Throwable cause)
          Add a BindingUpdateError to the request.
static String addParam(String url, String paramName, String paramVal)
          Add a parameter to the given URL.
static boolean avoidDirectResponseOutput(ServletRequest request)
          Tell whether a special request attribute was set, indicating that we should avoid writing to the response (or setting response error codes).
static ActionForm createActionForm(ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet actionServlet, ServletContext servletContext)
           
static String createActionPath(ServletRequest request, String qualifiedAction)
           
static String createActionURL(HttpServletRequest servletRequest, String qualifiedAction)
           
static ModuleConfig ensureModuleConfig(String modulePath, ServletRequest request, ServletContext context)
          Get the Struts ModuleConfig for the given module path.
static ActionConfig findActionConfig(String actionConfigPath, String modulePath, ServletContext context)
          Get the Struts ActionConfig for the given action config path and module path.
static String getActionMappingName(String action)
          Return the form action converted into an action mapping path.
static String getActionMappingPath(ServletRequest request)
          Get the Struts ActionMapping path from the ActionMapping that is in the request under the key Globals.MAPPING_KEY.
static String getActionName(ActionMapping mapping)
           
static Map getActionOutputMap(ServletRequest request, boolean createIfNotExist)
           
static ActionServlet getActionServlet(ServletContext context)
          Get the current ActionServlet.
static Map getBindingUpdateErrors(ServletRequest request)
          Get a map of BindingUpdateErrors stored in the request.
static String getCleanActionName(String action, boolean prependSlash)
           
static ActionForm getCurrentActionForm(ServletRequest request)
           
static ActionMapping getCurrentActionMapping(ServletRequest request)
           
static String getDecodedServletPath(HttpServletRequest request)
           
static String getDecodedURI(HttpServletRequest request)
           
static FacesBackingBean getFacesBackingBean(ServletRequest request)
           
static String getFlowControllerClassName(ModuleConfig mc)
           
static String getFlowControllerClassName(String modulePath, ServletRequest request, ServletContext context)
           
static ActionForm getFormBean(ActionMapping mapping, ServletRequest request)
           
static String getFormBeanType(FormBeanConfig formBeanConfig)
           
static ActionForm getForwardedFormBean(ServletRequest request, boolean removeFromRequest)
           
static String getForwardingModule(ServletRequest request)
          Set the module prefix for the ModuleConfig that is performing a forward in this request.
static HttpSession getHttpSession(ServletRequest request, boolean create)
           
static String getLongLivedFlowAttr(String modulePath)
           
static ModuleConfig getModuleConfig(String modulePath, ServletContext context)
          Get the Struts ModuleConfig for the given module path.
static String getModulePathFromReqAttr(HttpServletRequest request)
          Gets the Struts module path from the input request.
static PageflowConfig.MultipartHandler.Enum getMultipartHandlerType()
           
static Map getPageInputMap(ServletRequest request)
           
static Class getReloadableClass(String className, ServletContext servletContext)
           
static ServletContext getServletContext(ServletRequest req)
           
static String getSharedFlowClassName(HttpServletRequest request, ServletContext servletContext)
           
static String getSharedFlowClassNameForRelativeURI(String relativeURI, ServletRequest request, ServletContext servletContext)
           
static boolean ignoreIncludeServletPath(ServletRequest request)
           
static String inferModulePathFromClassName(String className)
           
static boolean isLongLived(ModuleConfig moduleConfig)
          Tell whether the given module is a long-lived page flow.
static boolean isMultipartHandlingEnabled(ServletRequest request)
           
static boolean isNestable(ModuleConfig moduleConfig)
          Tell whether the given module is a nested page flow.
static boolean isSessionScope(ActionMapping mapping)
           
static boolean isSharedFlowModule(ModuleConfig mc)
           
static Method lookupMethod(Class parentClass, String methodName, Class[] signature)
          Get a Method in a Class.
static Object newReloadableInstance(String className, ServletContext servletContext)
           
static String qualifyAction(ServletContext servletContext, String action)
           
static void removeCurrentPageFlow(HttpServletRequest request)
           
static void sendDevTimeError(String messageKey, Object[] messageArgs, Throwable cause, int productionTimeErrorCode, ServletRequest request, ServletResponse response, ServletContext servletContext)
          If not in production mode, write an error to the response; otherwise, set a response error code.
static void sendDevTimeError(String messageKey, Throwable cause, int productionTimeErrorCode, ServletRequest request, ServletResponse response, ServletContext servletContext, Object... messageArgs)
          If not in production mode, write an error to the response; otherwise, set a response error code.
static void sendError(String messageKey, Object[] messageArgs, ServletRequest request, ServletResponse response, Throwable cause, boolean avoidDirectResponseOutput)
          Write an error to the response.
static void sendError(String messageKey, Throwable cause, ServletRequest request, HttpServletResponse response, Object... messageArgs)
          Write an error to the response.
static boolean sessionExpired(ServletRequest servletRequest)
           
static void setAvoidDirectResponseOutput(ServletRequest request)
          Set a special request attribute to indicate that we should avoid writing to the response (or setting response error codes).
static void setCurrentActionResolver(ActionResolver resolver, HttpServletRequest request)
          Set the current ActionResolver (PageFlowController) in the user session.
static void setCurrentModule(ModuleConfig mc, ServletRequest request)
           
static void setCurrentPageFlow(PageFlowController jpf, HttpServletRequest request)
           
static void setFormInScope(String formName, ActionForm form, ActionMapping mapping, HttpServletRequest request, boolean overwrite)
          Set the given form in either the request or session, as appropriate, so Struts/NetUI tags will have access to it.
static void setForwardedFormBean(ServletRequest request, ActionForm form)
          Set the forwarded form.
static void setForwardingModule(ServletRequest request, String modulePrefix)
          Set the module prefix for the ModuleConfig that is performing a forward in this request.
static void setIgnoreIncludeServletPath(ServletRequest request, boolean ignore)
          Tell getDecodedServletPath(javax.servlet.http.HttpServletRequest) (and all that call it) to ignore the attribute that specifies the Servlet Include path, which is set when a Servlet include is done through RequestDispatcher.
static void setServletContext(ServletRequest request, ServletContext servletContext)
           
static void throwPageFlowException(PageFlowException ex)
           
static void throwPageFlowException(PageFlowException effect, ServletRequest request)
           
static Object unwrapFormBean(ActionForm form)
          We unwrap two special form types: XmlBeanActionForm and AnyBeanActionForm.
static ServletRequest unwrapMultipart(ServletRequest request)
          If the given request is a MultipartRequestWrapper (Struts class that doesn't extend HttpServletRequestWrapper), return the wrapped request; otherwise, return the given request.
static ActionForm wrapFormBean(Object formBean)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InternalUtils

public InternalUtils()
Method Detail

sendDevTimeError

public static void sendDevTimeError(String messageKey,
                                    Throwable cause,
                                    int productionTimeErrorCode,
                                    ServletRequest request,
                                    ServletResponse response,
                                    ServletContext servletContext,
                                    Object... messageArgs)
                             throws IOException
If not in production mode, write an error to the response; otherwise, set a response error code.

Throws:
IOException

sendDevTimeError

public static void sendDevTimeError(String messageKey,
                                    Object[] messageArgs,
                                    Throwable cause,
                                    int productionTimeErrorCode,
                                    ServletRequest request,
                                    ServletResponse response,
                                    ServletContext servletContext)
                             throws IOException
If not in production mode, write an error to the response; otherwise, set a response error code.

Throws:
IOException

sendError

public static void sendError(String messageKey,
                             Throwable cause,
                             ServletRequest request,
                             HttpServletResponse response,
                             Object... messageArgs)
                      throws IOException
Write an error to the response.

Throws:
IOException

sendError

public static void sendError(String messageKey,
                             Object[] messageArgs,
                             ServletRequest request,
                             ServletResponse response,
                             Throwable cause,
                             boolean avoidDirectResponseOutput)
                      throws IOException
Write an error to the response.

Throws:
IOException

unwrapFormBean

public static Object unwrapFormBean(ActionForm form)
We unwrap two special form types: XmlBeanActionForm and AnyBeanActionForm.


wrapFormBean

public static ActionForm wrapFormBean(Object formBean)

lookupMethod

public static Method lookupMethod(Class parentClass,
                                  String methodName,
                                  Class[] signature)
Get a Method in a Class.

Parameters:
parentClass - the Class in which to find the Method.
methodName - the name of the Method.
signature - the argument types for the Method.
Returns:
the Method with the given name and signature, or null if the method does not exist.

getFlowControllerClassName

public static String getFlowControllerClassName(String modulePath,
                                                ServletRequest request,
                                                ServletContext context)

getFlowControllerClassName

public static String getFlowControllerClassName(ModuleConfig mc)

isLongLived

public static boolean isLongLived(ModuleConfig moduleConfig)
Tell whether the given module is a long-lived page flow.


isNestable

public static boolean isNestable(ModuleConfig moduleConfig)
Tell whether the given module is a nested page flow.


getLongLivedFlowAttr

public static String getLongLivedFlowAttr(String modulePath)

setCurrentPageFlow

public static void setCurrentPageFlow(PageFlowController jpf,
                                      HttpServletRequest request)

removeCurrentPageFlow

public static void removeCurrentPageFlow(HttpServletRequest request)

getDecodedURI

public static String getDecodedURI(HttpServletRequest request)

getDecodedServletPath

public static String getDecodedServletPath(HttpServletRequest request)

addActionOutputs

public static void addActionOutputs(Map toAdd,
                                    ServletRequest request,
                                    boolean overwrite)

addActionError

public static void addActionError(String propertyName,
                                  ActionMessage error,
                                  ServletRequest request)

newReloadableInstance

public static Object newReloadableInstance(String className,
                                           ServletContext servletContext)
                                    throws ClassNotFoundException,
                                           InstantiationException,
                                           IllegalAccessException
Throws:
ClassNotFoundException
InstantiationException
IllegalAccessException

getReloadableClass

public static Class getReloadableClass(String className,
                                       ServletContext servletContext)
                                throws ClassNotFoundException
Throws:
ClassNotFoundException

getActionOutputMap

public static Map getActionOutputMap(ServletRequest request,
                                     boolean createIfNotExist)

getPageInputMap

public static Map getPageInputMap(ServletRequest request)

getModuleConfig

public static ModuleConfig getModuleConfig(String modulePath,
                                           ServletContext context)
Get the Struts ModuleConfig for the given module path.


ensureModuleConfig

public static ModuleConfig ensureModuleConfig(String modulePath,
                                              ServletRequest request,
                                              ServletContext context)
Get the Struts ModuleConfig for the given module path. If there is none registered, and if it is possible to register one automatically, do so.


getActionServlet

public static ActionServlet getActionServlet(ServletContext context)
Get the current ActionServlet.

Parameters:
context - the current ServletContext
Returns:
the ActionServlet that is stored as an attribute in the ServletContext

addBindingUpdateError

public static void addBindingUpdateError(ServletRequest request,
                                         String expression,
                                         String message,
                                         Throwable cause)
Add a BindingUpdateError to the request.

Parameters:
request - the current ServletRequest.
expression - the expression associated with this error.
message - the error message.
cause - the Throwable that caused the error.

getBindingUpdateErrors

public static Map getBindingUpdateErrors(ServletRequest request)
Get a map of BindingUpdateErrors stored in the request.

Returns:
a Map of expression (String) -> BindingUpdateError.

setCurrentModule

public static void setCurrentModule(ModuleConfig mc,
                                    ServletRequest request)

createActionForm

public static ActionForm createActionForm(ActionMapping mapping,
                                          ModuleConfig moduleConfig,
                                          ActionServlet actionServlet,
                                          ServletContext servletContext)

setFormInScope

public static void setFormInScope(String formName,
                                  ActionForm form,
                                  ActionMapping mapping,
                                  HttpServletRequest request,
                                  boolean overwrite)
Set the given form in either the request or session, as appropriate, so Struts/NetUI tags will have access to it.


isSessionScope

public static boolean isSessionScope(ActionMapping mapping)

getFormBean

public static ActionForm getFormBean(ActionMapping mapping,
                                     ServletRequest request)

setCurrentActionResolver

public static void setCurrentActionResolver(ActionResolver resolver,
                                            HttpServletRequest request)
Set the current ActionResolver (PageFlowController) in the user session.

Parameters:
resolver - the ActionResolver to set as the current one in the user session.
request - the current HttpServletRequest.

getSharedFlowClassName

public static String getSharedFlowClassName(HttpServletRequest request,
                                            ServletContext servletContext)

getSharedFlowClassNameForRelativeURI

public static String getSharedFlowClassNameForRelativeURI(String relativeURI,
                                                          ServletRequest request,
                                                          ServletContext servletContext)

isSharedFlowModule

public static boolean isSharedFlowModule(ModuleConfig mc)

getFacesBackingBean

public static FacesBackingBean getFacesBackingBean(ServletRequest request)

inferModulePathFromClassName

public static String inferModulePathFromClassName(String className)

isMultipartHandlingEnabled

public static boolean isMultipartHandlingEnabled(ServletRequest request)

getMultipartHandlerType

public static PageflowConfig.MultipartHandler.Enum getMultipartHandlerType()

setServletContext

public static void setServletContext(ServletRequest request,
                                     ServletContext servletContext)

getServletContext

public static ServletContext getServletContext(ServletRequest req)

getHttpSession

public static HttpSession getHttpSession(ServletRequest request,
                                         boolean create)

createActionURL

public static String createActionURL(HttpServletRequest servletRequest,
                                     String qualifiedAction)

createActionPath

public static String createActionPath(ServletRequest request,
                                      String qualifiedAction)

qualifyAction

public static String qualifyAction(ServletContext servletContext,
                                   String action)

getActionMappingName

public static String getActionMappingName(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:

Parameters:
action - the action name to be converted.
Returns:
an action path, suitable for lookup in the Struts configuration file.

getCleanActionName

public static String getCleanActionName(String action,
                                        boolean prependSlash)

addParam

public static String addParam(String url,
                              String paramName,
                              String paramVal)
Add a parameter to the given URL. Assumes there is no trailing anchor/fragment indicated with a '#'.

Parameters:
url - the URL to which to append.
paramName - the name of the parameter to add.
paramVal - the value of the parameter to add.
Returns:
the URL, with the given parameter added.

getActionName

public static String getActionName(ActionMapping mapping)

getCurrentActionMapping

public static ActionMapping getCurrentActionMapping(ServletRequest request)

getCurrentActionForm

public static ActionForm getCurrentActionForm(ServletRequest request)

sessionExpired

public static boolean sessionExpired(ServletRequest servletRequest)

throwPageFlowException

public static void throwPageFlowException(PageFlowException ex)

throwPageFlowException

public static void throwPageFlowException(PageFlowException effect,
                                          ServletRequest request)
                                   throws PageFlowException
Throws:
PageFlowException

findActionConfig

public static ActionConfig findActionConfig(String actionConfigPath,
                                            String modulePath,
                                            ServletContext context)
Get the Struts ActionConfig for the given action config path and module path.


getActionMappingPath

public static String getActionMappingPath(ServletRequest request)
Get the Struts ActionMapping path from the ActionMapping that is in the request under the key Globals.MAPPING_KEY.

Returns:
the path for the ActionMapping, as found with ActionMapping.getPath()

getModulePathFromReqAttr

public static String getModulePathFromReqAttr(HttpServletRequest request)
Gets the Struts module path from the input request. If a ModuleConfig object has been populated into the request it is used to get the module prefix, otherwise getModulePath is called, which derives the module path from the request URI.


setForwardedFormBean

public static void setForwardedFormBean(ServletRequest request,
                                        ActionForm form)
Set the forwarded form. This overrides the auto-generated form created by processActionForm and populated by processPopulate (in PageFlowRequestProcessor).


getForwardedFormBean

public static ActionForm getForwardedFormBean(ServletRequest request,
                                              boolean removeFromRequest)

avoidDirectResponseOutput

public static boolean avoidDirectResponseOutput(ServletRequest request)
Tell whether a special request attribute was set, indicating that we should avoid writing to the response (or setting response error codes).


setAvoidDirectResponseOutput

public static void setAvoidDirectResponseOutput(ServletRequest request)
Set a special request attribute to indicate that we should avoid writing to the response (or setting response error codes).


setForwardingModule

public static void setForwardingModule(ServletRequest request,
                                       String modulePrefix)
Set the module prefix for the ModuleConfig that is performing a forward in this request.


getForwardingModule

public static String getForwardingModule(ServletRequest request)
Set the module prefix for the ModuleConfig that is performing a forward in this request.


getFormBeanType

public static String getFormBeanType(FormBeanConfig formBeanConfig)

setIgnoreIncludeServletPath

public static void setIgnoreIncludeServletPath(ServletRequest request,
                                               boolean ignore)
Tell getDecodedServletPath(javax.servlet.http.HttpServletRequest) (and all that call it) to ignore the attribute that specifies the Servlet Include path, which is set when a Servlet include is done through RequestDispatcher. Normally, getDecodedServletPath tries the Servlet Include path before falling back to getServletPath() on the request. Note that this is basically a stack of instructions to ignore the include path, and this method expects each call with ignore==true to be balanced by a call with ignore==false.


ignoreIncludeServletPath

public static boolean ignoreIncludeServletPath(ServletRequest request)

unwrapMultipart

public static ServletRequest unwrapMultipart(ServletRequest request)
If the given request is a MultipartRequestWrapper (Struts class that doesn't extend HttpServletRequestWrapper), return the wrapped request; otherwise, return the given request.