Class 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
    • 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 extending User
        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 interface org.apache.fulcrum.pool.Recyclable
      • dispose

        public void dispose()
        Disposes a run data object.
        Specified by:
        dispose in interface org.apache.fulcrum.pool.Recyclable
      • getParameters

        public org.apache.fulcrum.parser.ParameterParser getParameters()
        Gets the parameters.
        Specified by:
        getParameters in interface RunData
        Returns:
        a parameter parser.
      • getCookies

        public org.apache.fulcrum.parser.CookieParser getCookies()
        Gets the cookies.
        Specified by:
        getCookies in interface RunData
        Returns:
        a cookie parser.
      • getACL

        public <A extends org.apache.fulcrum.security.acl.AccessControlList> A getACL()
        Gets the access control list.
        Specified by:
        getACL in interface RunData
        Type Parameters:
        A - a type extending AccessControlList
        Returns:
        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 key TurbineConstants.ACL_SESSION_KEY. Invalidate session, if session persist.
        Specified by:
        setACL in interface RunData
        Parameters:
        acl - an access control list.
      • hasAction

        public boolean hasAction()
        Whether or not an action has been defined.
        Specified by:
        hasAction in interface RunData
        Returns:
        true if 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.
        Specified by:
        getAction in interface RunData
        Returns:
        a string, "" if null.
      • setAction

        public void setAction​(String action)
        Sets the action for the request.
        Specified by:
        setAction in interface RunData
        Parameters:
        action - a string.
      • 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.
        Specified by:
        getLayout in interface RunData
        Returns:
        a string.
      • setLayout

        public void setLayout​(String layout)
        Set the layout for the request.
        Specified by:
        setLayout in interface RunData
        Parameters:
        layout - 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 interface RunData
        Parameters:
        layout - a layout template.
      • hasScreen

        public boolean hasScreen()
        Whether or not a screen has been defined.
        Specified by:
        hasScreen in interface RunData
        Returns:
        true if a screen has been defined.
      • setScreen

        public void setScreen​(String screen)
        Sets the screen for the request.
        Specified by:
        setScreen in interface RunData
        Parameters:
        screen - 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 interface RunData
        Parameters:
        screen - a screen template.
      • hasMessage

        public boolean hasMessage()
        Whether or not a message has been defined.
        Specified by:
        hasMessage in interface RunData
        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 interface RunData
        Returns:
        a string.
      • setMessage

        public void setMessage​(String msg)
        Sets the message for the request as a string.
        Specified by:
        setMessage in interface RunData
        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 interface RunData
        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 interface RunData
        Returns:
        a string element.
      • setTitle

        public void setTitle​(String title)
        Sets the title of the page.
        Specified by:
        setTitle in interface RunData
        Parameters:
        title - a string.
      • userExists

        public boolean userExists()
        Checks if a user exists in this session.
        Specified by:
        userExists in interface RunData
        Returns:
        true if a user exists in this session.
      • getUser

        public <T extends User> T getUser()
        Gets the user.
        Specified by:
        getUser in interface RunData
        Type Parameters:
        T - a type extending User
        Returns:
        a user.
      • setUser

        public void setUser​(User user)
        Sets the user.
        Specified by:
        setUser in interface RunData
        Parameters:
        user - a user.
      • 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 interface RunData
        Type Parameters:
        T - a type extending User
        Returns:
        a user.
      • isOutSet

        @Deprecated
        public boolean isOutSet()
        Deprecated.
        no replacement planned, response writer will not be cached
        Checks to see if out is set.
        Specified by:
        isOutSet in interface RunData
        Returns:
        true 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 interface RunData
        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 interface RunData
      • 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.
        Specified by:
        getLocale in interface RunData
        Returns:
        the locale.
      • setLocale

        public void setLocale​(Locale locale)
        Sets the locale.
        Specified by:
        setLocale in interface RunData
        Parameters:
        locale - the new locale.
      • 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 interface RunData
        Returns:
        the name of the charset or null.
      • setCharSet

        public void setCharSet​(String charSet)
        Sets the charset.
        Specified by:
        setCharSet in interface RunData
        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 interface RunData
        Returns:
        the charset or null.
      • 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 interface RunData
        Returns:
        the content type or an empty 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 interface RunData
        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 interface RunData
        Parameters:
        ruri - a string.
      • setStatusCode

        public void setStatusCode​(int statusCode)
        Sets the HTTP status code to return.
        Specified by:
        setStatusCode in interface RunData
        Parameters:
        statusCode - the status.
      • 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 interface RunData
        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.
        Specified by:
        populate in interface RunData
      • save

        public void save()
        Saves a user object into the session.
        Specified by:
        save in interface RunData
      • 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 interface RunData
        Parameters:
        name - name of the variable
        value - value of the variable.
      • getParameterParser

        public org.apache.fulcrum.parser.ParameterParser getParameterParser()
        Gets the parameter parser without parsing the parameters.
        Specified by:
        getParameterParser in interface TurbineRunData
        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 interface TurbineRunData
        Returns:
        the cookie parser.
      • setOut

        @Deprecated
        protected void setOut​(PrintWriter out)
        Deprecated.
        no replacement planned, response writer will not be cached
        Sets 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 interface org.apache.fulcrum.pool.Recyclable
        Returns:
        true, if the object is disposed.