Class DefaultTurbineRunData
- java.lang.Object
-
- org.apache.turbine.pipeline.DefaultPipelineData
-
- org.apache.turbine.services.rundata.DefaultTurbineRunData
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.fulcrum.pool.Recyclable
,PipelineData
,TurbineRunData
,RunData
public class DefaultTurbineRunData extends DefaultPipelineData implements TurbineRunData
DefaultTurbineRunData is the default implementation of the TurbineRunData interface, which is distributed by the Turbine RunData service, if another implementation is not defined in the default or specified RunData configuration. TurbineRunData is an extension to RunData, which is an interface to run-time information that is passed within Turbine. This provides the threading mechanism for the entire system because multiple requests can potentially come in at the same time. Thus, there is only one RunData instance for each request that is being serviced.DefaultTurbineRunData implements the Recyclable interface making it possible to pool its instances for recycling.
- Version:
- $Id$
- Author:
- Ilkka Priha, Jon S. Stevens, Bernie Hoeneisen, Daniel Rall, Henning P. Schmiedehausen, Quinton McCombs
-
-
Constructor Summary
Constructors Constructor Description DefaultTurbineRunData()
Constructs a run data object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addMessage(String msg)
Adds the string to message.void
declareDirectResponse()
Declares that output will be direct to the response stream, even though getOut() may never be called.void
dispose()
Disposes a run data object.<A extends org.apache.fulcrum.security.acl.AccessControlList>
AgetACL()
Gets the access control list.String
getAction()
Gets the action.Charset
getCharset()
Gets the charset.String
getCharSet()
Gets the charset.String
getContentType()
Gets the HTTP content type to return.String
getContextPath()
Gets the cached context path.org.apache.fulcrum.parser.CookieParser
getCookieParser()
Gets the cookie parser without parsing the cookies.org.apache.fulcrum.parser.CookieParser
getCookies()
Gets the cookies.Map<String,Object>
getDebugVariables()
Gets a Map of debug variables.Map<String,Context>
getJNDIContexts()
Gets JNDI Contexts.String
getLayout()
If the Layout has not been defined by the screen then set the layout to be "DefaultLayout".String
getLayoutTemplate()
Convenience method for a template info that returns the layout template being used.Locale
getLocale()
Gets the locale.String
getMessage()
Gets the results of an action or another message to be displayed as a string.String
getMessageAsHTML()
Gets the results of an action or another message to be displayed as a string (never null).FormMessages
getMessages()
Gets a FormMessages object where all the messages to the user should be stored.PrintWriter
getOut()
Gets the print writer.org.apache.fulcrum.parser.ParameterParser
getParameterParser()
Gets the parameter parser without parsing the parameters.org.apache.fulcrum.parser.ParameterParser
getParameters()
Gets the parameters.String
getRedirectURI()
Gets the redirect URI.String
getRemoteAddr()
Gets the IP address of the client that sent the request.String
getRemoteHost()
Gets the qualified name of the client that sent the request.HttpServletRequest
getRequest()
Gets the servlet request.HttpServletResponse
getResponse()
Gets the servlet response.String
getScreen()
Gets the screen to execute.String
getScreenTemplate()
Convenience method for a template info that returns the name of the template being used.String
getScriptName()
Gets the cached script name.ServerData
getServerData()
Gets the server data ofy the request.String
getServerName()
Gets the cached server name.int
getServerPort()
Gets the cached server port.String
getServerScheme()
Gets the cached server scheme.ServletConfig
getServletConfig()
Gets the servlet configuration used during servlet init.ServletContext
getServletContext()
Gets the servlet context used during servlet init.HttpSession
getSession()
Gets the servlet session information.String
getStackTrace()
Gets the stack trace if set.Throwable
getStackTraceException()
Gets the stack trace exception if set.int
getStatusCode()
Gets the HTTP status code to return.SystemError[]
getSystemErrors()
Gets an array of system errors.String
getTemplateEncoding()
Gets the character encoding to use for reading template files.TemplateInfo
getTemplateInfo()
Gets the template info.String
getTitle()
Gets the title of the page.<T extends User>
TgetUser()
Gets the user.String
getUserAgent()
Get the user agent for the request.<T extends User>
TgetUserFromSession()
Attempts to get the user from the session.static <T extends User>
TgetUserFromSession(HttpSession session)
Attempts to get the User object from the session.boolean
hasAction()
Whether or not an action has been defined.boolean
hasMessage()
Whether or not a message has been defined.boolean
hasScreen()
Whether or not a screen has been defined.boolean
isDisposed()
Checks whether the object is disposed.boolean
isOutSet()
Deprecated.no replacement planned, response writer will not be cachedvoid
populate()
Pulls a user object from the session and increments the access counter and sets the last access date for the object.void
recycle()
Recycles the object by removing its disposed flag.boolean
removeUserFromSession()
Allows one to invalidate the user in the default session.static boolean
removeUserFromSession(HttpSession session)
Allows one to invalidate the user in a session.void
save()
Saves a user object into the session.void
setACL(org.apache.fulcrum.security.acl.AccessControlList acl)
Sets the access control list.void
setAction(String action)
Sets the action for the request.void
setCharset(Charset charSet)
Sets the charset.void
setCharSet(String charSet)
Sets the charset.void
setContentType(String contentType)
Sets the HTTP content type to return.protected void
setContextPath(String contextPath)
Sets the cached context path that is stored in the server data.void
setDebugVariable(String name, Object value)
Sets a name/value pair in an internal Map that is accessible from the Error screen.void
setJNDIContexts(Map<String,Context> contexts)
Sets JNDI Contexts.void
setLayout(String layout)
Set the layout for the request.void
setLayoutTemplate(String layout)
Modifies the layout template for the screen.void
setLocale(Locale locale)
Sets the locale.void
setMessage(String msg)
Sets the message for the request as a string.void
setMessages(FormMessages msgs)
Sets the FormMessages object for the request.protected void
setOut(PrintWriter out)
Deprecated.no replacement planned, response writer will not be cachedvoid
setRedirectURI(String ruri)
Sets the redirect uri.void
setScreen(String screen)
Sets the screen for the request.void
setScreenTemplate(String screen)
Sets the screen template for the request.protected void
setScriptName(String scriptName)
Sets the cached script name that is stored in the server data.protected void
setServerName(String serverName)
Sets the cached server same that is stored in the server data.protected void
setServerPort(int port)
Sets the cached server port that is stored in the server data.protected void
setServerScheme(String serverScheme)
Sets the cached server scheme that is stored in the server data.void
setStackTrace(String trace, Throwable exp)
Sets the stack trace.void
setStatusCode(int statusCode)
Sets the HTTP status code to return.void
setSystemError(SystemError err)
Adds a critical system error.void
setTemplateEncoding(String encoding)
Sets the character encoding to use for reading template files.void
setTitle(String title)
Sets the title of the page.void
setUser(User user)
Sets the user.void
unsetMessage()
Unsets the message for the request.boolean
userExists()
Checks if a user exists in this session.-
Methods inherited from class org.apache.turbine.pipeline.DefaultPipelineData
close, get, get, put
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.AutoCloseable
close
-
Methods inherited from interface org.apache.turbine.pipeline.PipelineData
get, get, getRunData, put
-
-
-
-
Constructor Detail
-
DefaultTurbineRunData
public DefaultTurbineRunData()
Constructs a run data object.
-
-
Method Detail
-
getUserFromSession
public static <T extends User> T getUserFromSession(HttpSession session)
Attempts to get the User object from the session. If it does not exist, it returns null.- Type Parameters:
T
- a type extendingUser
- Parameters:
session
- An HttpSession.- Returns:
- A User.
-
removeUserFromSession
public static boolean removeUserFromSession(HttpSession session)
Allows one to invalidate the user in a session.- Parameters:
session
- An HttpSession.- Returns:
- True if user was invalidated.
-
recycle
public void recycle()
Recycles the object by removing its disposed flag.- Specified by:
recycle
in interfaceorg.apache.fulcrum.pool.Recyclable
-
dispose
public void dispose()
Disposes a run data object.- Specified by:
dispose
in interfaceorg.apache.fulcrum.pool.Recyclable
-
getParameters
public org.apache.fulcrum.parser.ParameterParser getParameters()
Gets the parameters.- Specified by:
getParameters
in interfaceRunData
- Returns:
- a parameter parser.
-
getCookies
public org.apache.fulcrum.parser.CookieParser getCookies()
Gets the cookies.- Specified by:
getCookies
in interfaceRunData
- Returns:
- a cookie parser.
-
getRequest
public HttpServletRequest getRequest()
Gets the servlet request.- Specified by:
getRequest
in interfaceRunData
- Returns:
- the request.
-
getResponse
public HttpServletResponse getResponse()
Gets the servlet response.- Specified by:
getResponse
in interfaceRunData
- Returns:
- the response.
-
getSession
public HttpSession getSession()
Gets the servlet session information.- Specified by:
getSession
in interfaceRunData
- Returns:
- the session.
-
getServletConfig
public ServletConfig getServletConfig()
Gets the servlet configuration used during servlet init.- Specified by:
getServletConfig
in interfaceRunData
- Returns:
- the configuration.
-
getServletContext
public ServletContext getServletContext()
Gets the servlet context used during servlet init.- Specified by:
getServletContext
in interfaceRunData
- Returns:
- the context.
-
getACL
public <A extends org.apache.fulcrum.security.acl.AccessControlList> A getACL()
Gets the access control list.
-
setACL
public void setACL(org.apache.fulcrum.security.acl.AccessControlList acl)
Sets the access control list. To delete ACL from session use keyTurbineConstants.ACL_SESSION_KEY
. Invalidate session, if session persist.
-
hasAction
public boolean hasAction()
Whether or not an action has been defined.
-
getAction
public String getAction()
Gets the action. It returns an empty string if null so that it is easy to do conditionals on it based on the equalsIgnoreCase() method.
-
getLayout
public String getLayout()
If the Layout has not been defined by the screen then set the layout to be "DefaultLayout". The screen object can also override this method to provide intelligent determination of the Layout to execute. You can also define that logic here as well if you want it to apply on a global scale. For example, if you wanted to allow someone to define layout "preferences" where they could dynamically change the layout for the entire site.
-
getLayoutTemplate
public String getLayoutTemplate()
Convenience method for a template info that returns the layout template being used.- Specified by:
getLayoutTemplate
in interfaceRunData
- Returns:
- a string.
-
setLayoutTemplate
public void setLayoutTemplate(String layout)
Modifies the layout template for the screen. This convenience method allows for a layout to be modified from within a template. For example; $data.setLayoutTemplate("NewLayout.vm")- Specified by:
setLayoutTemplate
in interfaceRunData
- Parameters:
layout
- a layout template.
-
hasScreen
public boolean hasScreen()
Whether or not a screen has been defined.
-
getScreenTemplate
public String getScreenTemplate()
Convenience method for a template info that returns the name of the template being used.- Specified by:
getScreenTemplate
in interfaceRunData
- Returns:
- a string.
-
setScreenTemplate
public void setScreenTemplate(String screen)
Sets the screen template for the request. For example; $data.setScreenTemplate("NewScreen.vm")- Specified by:
setScreenTemplate
in interfaceRunData
- Parameters:
screen
- a screen template.
-
getTemplateEncoding
public String getTemplateEncoding()
Gets the character encoding to use for reading template files.- Specified by:
getTemplateEncoding
in interfaceRunData
- Returns:
- the template encoding or null if not specified.
-
setTemplateEncoding
public void setTemplateEncoding(String encoding)
Sets the character encoding to use for reading template files.- Specified by:
setTemplateEncoding
in interfaceRunData
- Parameters:
encoding
- the template encoding.
-
getTemplateInfo
public TemplateInfo getTemplateInfo()
Gets the template info. Creates a new one if needed.- Specified by:
getTemplateInfo
in interfaceRunData
- Returns:
- a template info.
-
hasMessage
public boolean hasMessage()
Whether or not a message has been defined.- Specified by:
hasMessage
in interfaceRunData
- Returns:
- true if a message has been defined.
-
getMessage
public String getMessage()
Gets the results of an action or another message to be displayed as a string.- Specified by:
getMessage
in interfaceRunData
- Returns:
- a string.
-
setMessage
public void setMessage(String msg)
Sets the message for the request as a string.- Specified by:
setMessage
in interfaceRunData
- Parameters:
msg
- a string.
-
addMessage
public void addMessage(String msg)
Adds the string to message. If message has prior messages from other actions or screens, this method can be used to chain them.- Specified by:
addMessage
in interfaceRunData
- Parameters:
msg
- a string.
-
getMessageAsHTML
public String getMessageAsHTML()
Gets the results of an action or another message to be displayed as a string (never null).- Specified by:
getMessageAsHTML
in interfaceRunData
- Returns:
- a string element.
-
unsetMessage
public void unsetMessage()
Unsets the message for the request.- Specified by:
unsetMessage
in interfaceRunData
-
getMessages
public FormMessages getMessages()
Gets a FormMessages object where all the messages to the user should be stored.- Specified by:
getMessages
in interfaceRunData
- Returns:
- a FormMessages.
-
setMessages
public void setMessages(FormMessages msgs)
Sets the FormMessages object for the request.- Specified by:
setMessages
in interfaceRunData
- Parameters:
msgs
- A FormMessages.
-
userExists
public boolean userExists()
Checks if a user exists in this session.- Specified by:
userExists
in interfaceRunData
- Returns:
- true if a user exists in this session.
-
getUserFromSession
public <T extends User> T getUserFromSession()
Attempts to get the user from the session. If it does not exist, it returns null.- Specified by:
getUserFromSession
in interfaceRunData
- Type Parameters:
T
- a type extendingUser
- Returns:
- a user.
-
removeUserFromSession
public boolean removeUserFromSession()
Allows one to invalidate the user in the default session.- Specified by:
removeUserFromSession
in interfaceRunData
- Returns:
- true if user was invalidated.
-
isOutSet
@Deprecated public boolean isOutSet()
Deprecated.no replacement planned, response writer will not be cachedChecks to see if out is set.
-
getOut
public PrintWriter getOut() throws IOException
Gets the print writer. First time calling this will set the print writer via the response.- Specified by:
getOut
in interfaceRunData
- Returns:
- a print writer.
- Throws:
IOException
- on failure getting the PrintWriter
-
declareDirectResponse
public void declareDirectResponse()
Declares that output will be direct to the response stream, even though getOut() may never be called. Useful for response mechanisms that may call res.getWriter() themselves (such as JSP.)- Specified by:
declareDirectResponse
in interfaceRunData
-
getLocale
public Locale getLocale()
Gets the locale. If it has not already been defined with setLocale(), then properties named "locale.default.lang" and "locale.default.country" are checked from the Resource Service and the corresponding locale is returned. If these properties are undefined, JVM's default locale is returned.
-
getCharSet
public String getCharSet()
Gets the charset. If it has not already been defined with setCharSet(), then a property named "locale.default.charset" is checked from the Resource Service and returned. If this property is undefined, the default charset of the locale is returned. If the locale is undefined, null is returned.- Specified by:
getCharSet
in interfaceRunData
- Returns:
- the name of the charset or null.
-
setCharSet
public void setCharSet(String charSet)
Sets the charset.- Specified by:
setCharSet
in interfaceRunData
- Parameters:
charSet
- the name of the new charset.
-
getCharset
public Charset getCharset()
Gets the charset. If it has not already been defined with setCharSet(), then a property named "locale.default.charset" is checked from the Resource Service and returned. If this property is undefined, the default charset of the locale is returned. If the locale is undefined, null is returned.- Specified by:
getCharset
in interfaceRunData
- Returns:
- the charset or null.
-
setCharset
public void setCharset(Charset charSet)
Sets the charset.- Specified by:
setCharset
in interfaceRunData
- Parameters:
charSet
- the new charset.
-
getContentType
public String getContentType()
Gets the HTTP content type to return. If a charset has been specified, it is included in the content type. If the charset has not been specified and the main type of the content type is "text", the default charset is included. If the default charset is undefined, but the default locale is defined and it is not the US locale, a locale specific charset is included.- Specified by:
getContentType
in interfaceRunData
- Returns:
- the content type or an empty string.
-
setContentType
public void setContentType(String contentType)
Sets the HTTP content type to return.- Specified by:
setContentType
in interfaceRunData
- Parameters:
contentType
- a string.
-
getRedirectURI
public String getRedirectURI()
Gets the redirect URI. If this is set, also make sure to set the status code to 302.- Specified by:
getRedirectURI
in interfaceRunData
- Returns:
- a string, "" if null.
-
setRedirectURI
public void setRedirectURI(String ruri)
Sets the redirect uri. If this is set, also make sure to set the status code to 302.- Specified by:
setRedirectURI
in interfaceRunData
- Parameters:
ruri
- a string.
-
getStatusCode
public int getStatusCode()
Gets the HTTP status code to return.- Specified by:
getStatusCode
in interfaceRunData
- Returns:
- the status.
-
setStatusCode
public void setStatusCode(int statusCode)
Sets the HTTP status code to return.- Specified by:
setStatusCode
in interfaceRunData
- Parameters:
statusCode
- the status.
-
getSystemErrors
public SystemError[] getSystemErrors()
Gets an array of system errors.- Specified by:
getSystemErrors
in interfaceRunData
- Returns:
- a SystemError[].
-
setSystemError
public void setSystemError(SystemError err)
Adds a critical system error.- Specified by:
setSystemError
in interfaceRunData
- Parameters:
err
- a system error.
-
getJNDIContexts
public Map<String,Context> getJNDIContexts()
Gets JNDI Contexts.- Specified by:
getJNDIContexts
in interfaceRunData
- Returns:
- a hashmap.
-
setJNDIContexts
public void setJNDIContexts(Map<String,Context> contexts)
Sets JNDI Contexts.- Specified by:
setJNDIContexts
in interfaceRunData
- Parameters:
contexts
- a hashmap.
-
getServerScheme
public String getServerScheme()
Gets the cached server scheme.- Specified by:
getServerScheme
in interfaceRunData
- Returns:
- a string.
-
getServerName
public String getServerName()
Gets the cached server name.- Specified by:
getServerName
in interfaceRunData
- Returns:
- a string.
-
getServerPort
public int getServerPort()
Gets the cached server port.- Specified by:
getServerPort
in interfaceRunData
- Returns:
- an int.
-
getContextPath
public String getContextPath()
Gets the cached context path.- Specified by:
getContextPath
in interfaceRunData
- Returns:
- a string.
-
getScriptName
public String getScriptName()
Gets the cached script name.- Specified by:
getScriptName
in interfaceRunData
- Returns:
- a string.
-
getServerData
public ServerData getServerData()
Gets the server data ofy the request.- Specified by:
getServerData
in interfaceRunData
- Returns:
- server data.
-
getRemoteAddr
public String getRemoteAddr()
Gets the IP address of the client that sent the request.- Specified by:
getRemoteAddr
in interfaceRunData
- Returns:
- a string.
-
getRemoteHost
public String getRemoteHost()
Gets the qualified name of the client that sent the request.- Specified by:
getRemoteHost
in interfaceRunData
- Returns:
- a string.
-
getUserAgent
public String getUserAgent()
Get the user agent for the request. The semantics here are muddled because RunData caches the value after the first invocation. This is different e.g. from getCharSet().- Specified by:
getUserAgent
in interfaceRunData
- Returns:
- a string.
-
populate
public void populate()
Pulls a user object from the session and increments the access counter and sets the last access date for the object.
-
save
public void save()
Saves a user object into the session.
-
getStackTrace
public String getStackTrace()
Gets the stack trace if set.- Specified by:
getStackTrace
in interfaceRunData
- Returns:
- the stack trace.
-
getStackTraceException
public Throwable getStackTraceException()
Gets the stack trace exception if set.- Specified by:
getStackTraceException
in interfaceRunData
- Returns:
- the stack exception.
-
setStackTrace
public void setStackTrace(String trace, Throwable exp)
Sets the stack trace.- Specified by:
setStackTrace
in interfaceRunData
- Parameters:
trace
- the stack trace.exp
- the exception.
-
setDebugVariable
public void setDebugVariable(String name, Object value)
Sets a name/value pair in an internal Map that is accessible from the Error screen. This is a good way to get debugging information when an exception is thrown.- Specified by:
setDebugVariable
in interfaceRunData
- Parameters:
name
- name of the variablevalue
- value of the variable.
-
getDebugVariables
public Map<String,Object> getDebugVariables()
Gets a Map of debug variables.- Specified by:
getDebugVariables
in interfaceRunData
- Returns:
- a Map of debug variables.
-
getParameterParser
public org.apache.fulcrum.parser.ParameterParser getParameterParser()
Gets the parameter parser without parsing the parameters.- Specified by:
getParameterParser
in interfaceTurbineRunData
- Returns:
- the parameter parser. TODO Does this method make sense? Pulling the parameter out of the run data object before setting a request (which happens only in getParameters() leads to the Parameter parser having no object and thus the default or even an undefined encoding instead of the actual request character encoding).
-
getCookieParser
public org.apache.fulcrum.parser.CookieParser getCookieParser()
Gets the cookie parser without parsing the cookies.- Specified by:
getCookieParser
in interfaceTurbineRunData
- Returns:
- the cookie parser.
-
setOut
@Deprecated protected void setOut(PrintWriter out)
Deprecated.no replacement planned, response writer will not be cachedSets the print writer.- Parameters:
out
- a print writer.
-
setServerScheme
protected void setServerScheme(String serverScheme)
Sets the cached server scheme that is stored in the server data.- Parameters:
serverScheme
- a string.
-
setServerName
protected void setServerName(String serverName)
Sets the cached server same that is stored in the server data.- Parameters:
serverName
- a string.
-
setServerPort
protected void setServerPort(int port)
Sets the cached server port that is stored in the server data.- Parameters:
port
- an int.
-
setContextPath
protected void setContextPath(String contextPath)
Sets the cached context path that is stored in the server data.- Parameters:
contextPath
- a string.
-
setScriptName
protected void setScriptName(String scriptName)
Sets the cached script name that is stored in the server data.- Parameters:
scriptName
- a string.
-
isDisposed
public boolean isDisposed()
Checks whether the object is disposed.- Specified by:
isDisposed
in interfaceorg.apache.fulcrum.pool.Recyclable
- Returns:
- true, if the object is disposed.
-
-