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, BEGIN_ACTION_NAME, DEFAULT_FORWARD_OVERFLOW_COUNT, DEFAULT_NESTING_OVERFLOW_COUNT, FORWARD_OVERFLOW_COUNT_PARAM, GLOBALAPP_CLASSNAME, GLOBALAPP_SOURCEFILE_NAME, HTTP_REDIRECTOR_PARAM, JPF_EXTENSION, JPF_MODULE_CONFIG_EXTENSION, JPF_MODULE_CONFIG_GEN_DIR, JPF_MODULE_CONFIG_PREFIX, LOGIN_HANDLER_PARAM, NESTING_OVERFLOW_COUNT_PARAM, SECURE_FORWARDS_PARAM
 
Constructor Summary
InternalUtils()
           
 
Method Summary
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 void addValidationError(String propertyName, ActionError error, ServletRequest request)
           
static ActionForm createActionForm(HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet actionServlet, ServletContext servletContext)
           
static void deleteCurrentPageFlow(HttpServletRequest request)
           
static void dumpRequest(HttpServletRequest request, PrintStream output)
          Print parameters and attributes in the given request.
static void dumpServletContext(ServletContext context, PrintStream output)
          Print attributes in the given ServletContext.
static PageFlowController ensureCurrentPageFlow(HttpServletRequest request, HttpServletResponse response)
          Get or create the current PageFlowConroller for the given request.
static ModuleConfig ensureModuleConfig(String modulePath, ServletRequest request, ServletContext context)
          Get the Struts ModuleConfig for the given module path.
static SharedFlowController ensureSharedFlow(HttpServletRequest request, HttpServletResponse response)
          Get or create the current SharedFlowController instance.
static SharedFlowController ensureSharedFlow(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
          Get or create the current SharedFlowController instance.
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 ActionResolver getCurrentActionResolver(HttpServletRequest request, boolean warnAboutClassLoaders)
          Get the current ActionResolver (PageFlowController).
static PageFlowController getCurrentPageFlow(HttpServletRequest request, boolean warnAboutClassLoaders)
          Get the current PageFlowController.
static String getDecodedServletPath(HttpServletRequest request)
           
static String getDecodedURI(HttpServletRequest request)
           
static FacesBackingBean getFacesBackingBean(ServletRequest request)
           
static FlowController getFlowController(Class fcClass, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
           
static String getFlowControllerClassName(ModuleConfig mc)
           
static String getFlowControllerClassName(String modulePath, ServletRequest request, ServletContext context)
           
static ActionForm getFormBean(ActionMapping mapping, HttpServletRequest request)
           
static ModuleConfig getModuleConfig(String modulePath, ServletContext context)
          Get the Struts ModuleConfig for the given module path.
static PageflowConfig.MultipartHandler.Enum getMultipartHandlerType()
           
static Map getPageInputMap(ServletRequest request)
           
static Class getReloadableClass(String className, HttpServletRequest request, ServletContext servletContext)
           
static ServletContext getServletContext(HttpServletRequest request)
           
static SharedFlowController getSharedFlow(FlowController pfc, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
           
static String getSharedFlowClassName(HttpServletRequest request, ServletContext servletContext)
           
static String getSharedFlowClassNameForRelativeURI(String relativeURI, HttpServletRequest request, ServletContext servletContext)
           
static ModuleConfig getSharedFlowConfig(ModuleConfig flowControllerConfig, HttpServletRequest request, ServletContext servletContext)
          Get the Struts ModuleConfig associated with the SharedFlowController for the given FlowController module.
static String getSingletonFlowAttr(String modulePath)
           
static PageFlowController getSingletonPageFlow(String modulePath, HttpServletRequest request, boolean warnAboutClassLoaders)
          Get the singleton page flow instance associated with the given module (directory) path.
static String inferModulePathFromClassName(String className)
           
static boolean isMultipartHandlingEnabled(HttpServletRequest 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 boolean isSingleton(ModuleConfig moduleConfig)
          Tell whether the given module is a singleton page flow.
static Method lookupMethod(Class parentClass, String methodName, Class[] signature)
          Get a Method in a Class.
static Object newReloadableInstance(String className, HttpServletRequest request, ServletContext servletContext)
           
static void sendDevTimeError(String messageKey, Object[] messageArgs, Throwable cause, int productionTimeErrorCode, HttpServletRequest request, HttpServletResponse 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, HttpServletRequest request, HttpServletResponse 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, HttpServletRequest request, HttpServletResponse response, Throwable cause)
          Write an error to the response.
static void sendError(String messageKey, Throwable cause, HttpServletRequest request, HttpServletResponse response, Object... messageArgs)
          Write an error to the response.
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 Object unwrapFormBean(ActionForm form)
          We unwrap two special form types: XmlBeanActionForm and AnyBeanActionForm.
static void warnAboutClassLoaders(Object object, HttpServletRequest request)
           
static void warnAboutClassLoaders(Object object, ServletContext servletContext)
           
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,
                                    HttpServletRequest request,
                                    HttpServletResponse 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,
                                    HttpServletRequest request,
                                    HttpServletResponse 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,
                             HttpServletRequest request,
                             HttpServletResponse response,
                             Object... messageArgs)
                      throws IOException
Write an error to the response.

Throws:
IOException

sendError

public static void sendError(String messageKey,
                             Object[] messageArgs,
                             HttpServletRequest request,
                             HttpServletResponse response,
                             Throwable cause)
                      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.

ensureCurrentPageFlow

public static final PageFlowController ensureCurrentPageFlow(HttpServletRequest request,
                                                             HttpServletResponse response)
Get or create the current PageFlowConroller for the given request. Deduces the ServletContext from the request.

Parameters:
request - the current HttpServletRequest.
response - the current HttpServletResponse
Returns:
the current PageFlowController in the user session, or if there is none, create one appropriate to the given request if possible. Failing that, return null.

getFlowControllerClassName

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

getFlowControllerClassName

public static String getFlowControllerClassName(ModuleConfig mc)

getCurrentActionResolver

public static ActionResolver getCurrentActionResolver(HttpServletRequest request,
                                                      boolean warnAboutClassLoaders)
Get the current ActionResolver (PageFlowController).

Returns:
the current ActionResolver from the user session, or null if there is none.

warnAboutClassLoaders

public static void warnAboutClassLoaders(Object object,
                                         HttpServletRequest request)

warnAboutClassLoaders

public static void warnAboutClassLoaders(Object object,
                                         ServletContext servletContext)

getCurrentPageFlow

public static final PageFlowController getCurrentPageFlow(HttpServletRequest request,
                                                          boolean warnAboutClassLoaders)
Get the current PageFlowController.

Parameters:
request - the current HttpServletRequest.
Returns:
the current PageFlowController from the user session, or null if there is none.

getSingletonPageFlow

public static PageFlowController getSingletonPageFlow(String modulePath,
                                                      HttpServletRequest request,
                                                      boolean warnAboutClassLoaders)
Get the singleton page flow instance associated with the given module (directory) path.

Parameters:
modulePath - the webapp-relative path to the directory containing the singleton page flow.
request - the current HttpServletRequest.
Returns:
the singleton page flow instance associated with the given module, or null if none is found.

isSingleton

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


isNestable

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


getSingletonFlowAttr

public static String getSingletonFlowAttr(String modulePath)

setCurrentPageFlow

public static void setCurrentPageFlow(PageFlowController jpf,
                                      HttpServletRequest request)

deleteCurrentPageFlow

public static void deleteCurrentPageFlow(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)

addValidationError

public static void addValidationError(String propertyName,
                                      ActionError error,
                                      ServletRequest request)

getActionName

public static String getActionName(ActionMapping mapping)

newReloadableInstance

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

getReloadableClass

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

getActionOutputMap

public static Map getActionOutputMap(ServletRequest request,
                                     boolean createIfNotExist)

getPageInputMap

public static Map getPageInputMap(ServletRequest request)

getSharedFlowConfig

public static ModuleConfig getSharedFlowConfig(ModuleConfig flowControllerConfig,
                                               HttpServletRequest request,
                                               ServletContext servletContext)
Get the Struts ModuleConfig associated with the SharedFlowController for the given FlowController module.


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)
                                       throws IOException,
                                              ServletException
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.

Throws:
IOException
ServletException

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.

dumpRequest

public static void dumpRequest(HttpServletRequest request,
                               PrintStream output)
Print parameters and attributes in the given request.

Parameters:
request - the current HttpServletRequest.
output - a PrintStream to which to output request parameters and request/session attributes; if null, System.err is used.

dumpServletContext

public static void dumpServletContext(ServletContext context,
                                      PrintStream output)
Print attributes in the given ServletContext.

Parameters:
context - the current ServletContext.
output - a PrintStream to which to output ServletContext attributes; if null, System.err is used.

setCurrentModule

public static void setCurrentModule(ModuleConfig mc,
                                    ServletRequest request)

createActionForm

public static ActionForm createActionForm(HttpServletRequest request,
                                          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,
                                     HttpServletRequest request)

ensureSharedFlow

public static SharedFlowController ensureSharedFlow(HttpServletRequest request,
                                                    HttpServletResponse response)
Get or create the current SharedFlowController instance.

Parameters:
request - the current HttpServletRequest.
response - the current HttpServletResponse
Returns:
the current applicable SharedFlowController from the user session, or a newly-instantiated one if none was in the session. Failing that, return null.

ensureSharedFlow

public static SharedFlowController ensureSharedFlow(HttpServletRequest request,
                                                    HttpServletResponse response,
                                                    ServletContext servletContext)
Get or create the current SharedFlowController instance.

Parameters:
request - the current HttpServletRequest.
response - the current HttpServletResponse
servletContext - the current ServletContext
Returns:
the current applicable SharedFlowController from the user session, or a newly-instantiated one if none was in the session. Failing that, return null.

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,
                                                          HttpServletRequest request,
                                                          ServletContext servletContext)

getFlowController

public static FlowController getFlowController(Class fcClass,
                                               HttpServletRequest request,
                                               HttpServletResponse response,
                                               ServletContext servletContext)

getSharedFlow

public static SharedFlowController getSharedFlow(FlowController pfc,
                                                 HttpServletRequest request,
                                                 HttpServletResponse response,
                                                 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(HttpServletRequest request)

getMultipartHandlerType

public static PageflowConfig.MultipartHandler.Enum getMultipartHandlerType()

getServletContext

public static ServletContext getServletContext(HttpServletRequest request)