Class UtilAbstractAction
- java.lang.Object
-
- org.apache.struts.action.Action
-
- org.bedework.util.struts.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.bedework.util.servlet.HttpAppLogger
HttpAppLogger.LogEntry
-
-
Field Summary
Fields Modifier and Type Field Description StringforwardLoggedOutForward to here for logged outprotected booleanisPortletprotected StringrequestLogout
-
Constructor Summary
Constructors Constructor Description UtilAbstractAction()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StringcheckConfirmationId(javax.servlet.http.HttpServletRequest request, UtilActionForm form)Check for a confirmation id.protected StringcheckLogOut(javax.servlet.http.HttpServletRequest request, UtilActionForm form)Check for logout request.booleanclearMessages()In a portlet environment a render action should override this to return false to preserve messages.voiddoPresentation(Request request)voiddumpRequest(javax.servlet.http.HttpServletRequest req)org.apache.struts.action.ActionForwardexecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm frm, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)HashMap<String,String>getAppVars(Request request)StringgetContentName(Request req)Override this to get the contentName from different sourcesStringgetErrorObjAttrName()Override to return the name of the error object session attribute.StringgetErrorObjErrProp()Override to return a different name for the error exception property.abstract StringgetId()Set the global id to some name for loggingorg.bedework.util.logging.BwLoggergetLogger()StringgetLogPrefix(javax.servlet.http.HttpServletRequest request)StringgetMessage(String name)StringgetMessageObjAttrName()Override to return the name of the messages object session attribute.org.apache.struts.util.MessageResourcesgetMessages()StringgetPresentationAttrName()Overide this to set the value or turn off presentation support by returning null or the value "NONE".PresentationStategetPresentationState(Request request)protected StringgetReqPar(javax.servlet.http.HttpServletRequest req, String name)Get a request parameter stripped of white space.protected Collection<String>getReqPars(javax.servlet.http.HttpServletRequest req, String name)Get a multi-valued request parameter stripped of white space.StringgetReqRes(String resName)Return the value of a required named resource.protected voidinitPresentationState(Request request, PresentationState ps)booleanisPortletRequest(javax.servlet.http.HttpServletRequest req)protected booleanlogOutCleanup(javax.servlet.http.HttpServletRequest request, UtilActionForm form)Clean up - we're about to logoutabstract StringperformAction(Request request, org.apache.struts.util.MessageResources messages)This is the routine which does the work.protected StringrequireConfirmationId(javax.servlet.http.HttpServletRequest request, UtilActionForm form)Require a confirmation id.booleansetAppVar(String name, String val, HashMap<String,String> appVars)Called to set an application variable to a valuevoidsetRefreshInterval(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int refreshInterval, String refreshAction, UtilActionForm form)Check request for refresh intervalprotected voidtraceConfig(Request req)-
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bedework.util.servlet.HttpAppLogger
emitLogEntry, getLogEntry, getSessionId, logInfo, logRequest, logRequestOut, logSessionCounts
-
Methods inherited from interface org.bedework.util.logging.Logged
audit, debug, debug, enableAuditLogger, enableErrorLogger, enableMetricsLogger, error, error, error, info, isAuditLoggerEnabled, isErrorLoggerEnabled, isMetricsDebugEnabled, isMetricsLoggerEnabled, metrics, setLoggerClass, setLoggerClass, trace, trace, warn
-
-
-
-
Field Detail
-
requestLogout
protected String requestLogout
-
forwardLoggedOut
public final String forwardLoggedOut
Forward to here for logged out- See Also:
- Constant Field Values
-
isPortlet
protected boolean isPortlet
-
-
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 formmessages- 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:
executein classorg.apache.struts.action.Action- Throws:
IOExceptionjavax.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
-
getLogPrefix
public String getLogPrefix(javax.servlet.http.HttpServletRequest request)
- Specified by:
getLogPrefixin interfaceHttpAppLogger
-
logOutCleanup
protected boolean logOutCleanup(javax.servlet.http.HttpServletRequest request, UtilActionForm form)Clean up - we're about to logout- Parameters:
request- HttpServletRequestform-- 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- HttpServletRequestform-- 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-
-
getAppVars
public HashMap<String,String> getAppVars(Request request)
- Parameters:
request-- Returns:
- app vars
-
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 variableval- 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 sessionform-- 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 sessionform-- Returns:
- String forward to here on error. null for OK.
- Throws:
Throwable
-
doPresentation
public void doPresentation(Request request) throws Throwable
- Parameters:
request-- Throws:
Throwable
-
getPresentationState
public PresentationState getPresentationState(Request request) throws Throwable
- Parameters:
request-- Returns:
- PresentationState
- 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:
getLoggerin interfaceorg.bedework.util.logging.Logged
-
-