Class UtilAbstractAction

  • All Implemented Interfaces:
    org.bedework.util.logging.Logged, HttpAppLogger
    Direct Known Subclasses:
    UtilRenderAction

    public abstract class UtilAbstractAction
    extends org.apache.struts.action.Action
    implements HttpAppLogger, org.bedework.util.logging.Logged
    Abstract implementation of Action which sets up frequently required fields then calls an abstract method to do the work.

    If the abstract action method returns null or throws an exception the struts action method will forward to "error".

    An invalid form of request parameter (for those recognized by the abstract action) will cause a forward to "badRequest"..

    Otherwise we forward to the result from the abstract action.

    This action also checks for a number of request parameters, mostly related to presentation of data but some related to debugging.

    Debugging actions:

    • debug=yes|no Set the debugging mode
    • seralize=anything Try to serialize all session attributes and log the result. Only when debugging on.

    The following are related to presentation of data. They are often useful when debugging xslt but can be used to force content types.

    • browserType=! Reset to normal dynamic behaviour, that is browser type reset every request.
    • browserType=string Set the browser type for one request
    • browserTypeSticky=! Reset to normal dynamic behaviour, that is reset browser type every request.
    • browserTypeSticky=string Set the browser type permanently - browser type set until next explicit setting.

    Set the 'skinName' - maybe change the look and feel or e.g. provide printer friendly output:

    • skinName=! Reset to normal dynamic behaviour, that is reset every request.
    • skinName=string Set the skin name for one request
    • skinNameSticky=! Reset to normal dynamic behaviour, that is reset every request.
    • skinNameSticky=string Set the skin name permanently

    Allow user to set the content type explicitly. Used mainly for debugging. The incoming request may contain the following:

    • contentType=! Reset to normal dynamic behaviour, that is reset every request.
    • contentType=string Set the Content type
    • contentTypeSticky=! Reset to normal dynamic behaviour, that is reset every request.
    • contentTypeSticky=string Set the Content type permanently

    Allow user to indicate if we should refresh the xslt once, every time or only when something changes. Used mainly for debugging. The incoming request may contain the following:

    • refreshXslt=! Reset to normal dynamic behaviour, that is reset every request.
    • refreshXslt=yes One shot refresh
    • refreshxslt=always Refresh every request.

    Some misc actions:

    • forwardto=name Just does a forward to that name. Used to provide a null action with arbitrary forward configured in struts-config.xml
    • noxslt=anything Suppress XSLT transform for one request. Used for debugging - provides the raw xml.

    A combination of the above can allow us to dump the output in a file,
    contentType=text/text&noxslt=yes

    • Field Detail

      • requestLogout

        protected String requestLogout
      • isPortlet

        protected boolean isPortlet
    • Constructor Detail

      • UtilAbstractAction

        public UtilAbstractAction()
    • Method Detail

      • performAction

        public abstract String performAction​(Request request,
                                             org.apache.struts.util.MessageResources messages)
                                      throws Throwable
        This is the routine which does the work.
        Parameters:
        request - Provide http request/response and form
        messages - Resources
        Returns:
        String forward name
        Throws:
        Throwable
      • execute

        public org.apache.struts.action.ActionForward execute​(org.apache.struts.action.ActionMapping mapping,
                                                              org.apache.struts.action.ActionForm frm,
                                                              javax.servlet.http.HttpServletRequest request,
                                                              javax.servlet.http.HttpServletResponse response)
                                                       throws IOException,
                                                              javax.servlet.ServletException
        Overrides:
        execute in class org.apache.struts.action.Action
        Throws:
        IOException
        javax.servlet.ServletException
      • traceConfig

        protected void traceConfig​(Request req)
      • getContentName

        public String getContentName​(Request req)
                              throws Throwable
        Override this to get the contentName from different sources
        Parameters:
        req -
        Returns:
        String name of content
        Throws:
        Throwable
      • getId

        public abstract String getId()
        Set the global id to some name for logging
        Returns:
        String id
      • clearMessages

        public boolean clearMessages()
        In a portlet environment a render action should override this to return false to preserve messages.
        Returns:
        boolean true to clear messages
      • getErrorObjAttrName

        public String getErrorObjAttrName()
        Override to return the name of the error object session attribute.
        Returns:
        String request attribute name. Null to suppress.
      • getMessageObjAttrName

        public String getMessageObjAttrName()
        Override to return the name of the messages object session attribute.
        Returns:
        String request attribute name. Null to suppress.
      • getErrorObjErrProp

        public String getErrorObjErrProp()
        Override to return a different name for the error exception property. This must return non-null if getErrorObjAttrName returns a value.
        Returns:
        error exception property name
      • getPresentationAttrName

        public String getPresentationAttrName()
        Overide this to set the value or turn off presentation support by returning null or the value "NONE".
        Returns:
        presentation attr name
      • getMessages

        public org.apache.struts.util.MessageResources getMessages()
        Returns:
        message resources
      • getMessage

        public String getMessage​(String name)
        Parameters:
        name -
        Returns:
        message identified by name
      • logOutCleanup

        protected boolean logOutCleanup​(javax.servlet.http.HttpServletRequest request,
                                        UtilActionForm form)
        Clean up - we're about to logout
        Parameters:
        request - HttpServletRequest
        form -
        Returns:
        boolean true for OK to log out. False - not allowed - ignore it.
      • checkLogOut

        protected String checkLogOut​(javax.servlet.http.HttpServletRequest request,
                                     UtilActionForm form)
                              throws Throwable
        Check for logout request.
        Parameters:
        request - HttpServletRequest
        form -
        Returns:
        null for continue, forwardLoggedOut to end session.
        Throws:
        Throwable
      • setRefreshInterval

        public void setRefreshInterval​(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response,
                                       int refreshInterval,
                                       String refreshAction,
                                       UtilActionForm form)
        Check request for refresh interval
        Parameters:
        request -
        response -
        refreshInterval -
        refreshAction -
        form -
      • setAppVar

        public boolean setAppVar​(String name,
                                 String val,
                                 HashMap<String,​String> appVars)
        Called to set an application variable to a value
        Parameters:
        name - name of variable
        val - new value of variable - null means remove.
        appVars -
        Returns:
        boolean True if ok - false for too many vars
      • checkConfirmationId

        protected String checkConfirmationId​(javax.servlet.http.HttpServletRequest request,
                                             UtilActionForm form)
                                      throws Throwable
        Check for a confirmation id. This is a random string embedded in some requests to confirm that the incoming request came from a page we generated. Not all pages will have such an id but if we do it must match. We expect the request parameter to be of the form
        confirmationid=id

        .

        Parameters:
        request - Needed to locate session
        form -
        Returns:
        String forward to here on error. null for OK.
        Throws:
        Throwable
      • requireConfirmationId

        protected String requireConfirmationId​(javax.servlet.http.HttpServletRequest request,
                                               UtilActionForm form)
                                        throws Throwable
        Require a confirmation id. This is a random string embedded in some requests to confirm that the incoming request came from a page we generated. Not all pages will have such an id but if we do it must match. We expect the request parameter to be of the form
        confirmationid=id

        .

        Parameters:
        request - Needed to locate session
        form -
        Returns:
        String forward to here on error. null for OK.
        Throws:
        Throwable
      • initPresentationState

        protected void initPresentationState​(Request request,
                                             PresentationState ps)
        Parameters:
        request -
      • getReqRes

        public String getReqRes​(String resName)
                         throws Throwable
        Return the value of a required named resource.
        Parameters:
        resName - Name of the property
        Returns:
        String Resource value or null
        Throws:
        Throwable
      • isPortletRequest

        public boolean isPortletRequest​(javax.servlet.http.HttpServletRequest req)
        Parameters:
        req -
        Returns:
        boolean true for portlet
      • getReqPar

        protected String getReqPar​(javax.servlet.http.HttpServletRequest req,
                                   String name)
                            throws Throwable
        Get a request parameter stripped of white space. Return null for zero length.
        Parameters:
        req -
        name - name of parameter
        Returns:
        String value
        Throws:
        Throwable
      • getReqPars

        protected Collection<String> getReqPars​(javax.servlet.http.HttpServletRequest req,
                                                String name)
                                         throws Throwable
        Get a multi-valued request parameter stripped of white space. Return null for zero length.
        Parameters:
        req -
        name - name of parameter
        Returns:
        Collection or null
        Throws:
        Throwable
      • dumpRequest

        public void dumpRequest​(javax.servlet.http.HttpServletRequest req)
        Parameters:
        req -
      • getLogger

        public org.bedework.util.logging.BwLogger getLogger()
        Specified by:
        getLogger in interface org.bedework.util.logging.Logged