org.apache.cocoon.environment
Class AbstractEnvironment

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.environment.AbstractEnvironment
All Implemented Interfaces:
Environment, LogEnabled
Direct Known Subclasses:
AbstractCommandLineEnvironment, BackgroundEnvironment, EnvironmentWrapper, HttpEnvironment, PortletEnvironment

public abstract class AbstractEnvironment
extends AbstractLogEnabled
implements Environment

Base class for any environment

Version:
CVS $Id: AbstractEnvironment.java 226274 2005-07-28 22:45:26Z vgritsenko $
Author:
Björn Lütkemeier, Giacomo Pati, Carsten Ziegeler

Field Summary
protected  String action
          The Action requested
protected  Map objectModel
          The object model
protected  OutputStream outputStream
          The real output stream
protected  String prefix
          The prefix
protected  BufferedOutputStream secureOutputStream
          The secure Output Stream
protected  String uri
          The current uri in progress
protected  String view
          The View requested
 
Constructor Summary
AbstractEnvironment(String uri, String view)
          Constructs the abstract environment
AbstractEnvironment(String uri, String view, String action)
          Constructs the abstract environment
 
Method Summary
 void commitResponse()
          Commit the response
protected static String extractAction(Request req)
          Helper method to extract the action name from the request.
protected static String extractView(Request request)
          Helper method to extract the view name from the request.
 void finishingProcessing()
          Notify that the processing is finished This can be used to cleanup the environment object
 String getAction()
          Get the action to process
 Object getAttribute(String name)
          Returns the object bound with the specified name, or null if no object is bound under the name.
 Enumeration getAttributeNames()
          Returns an Enumeration of String objects containing the names of all the objects bound to this environment.
 Map getObjectModel()
          Get the underlying object model
 OutputStream getOutputStream(int bufferSize)
          Get the output stream where to write the generated resource.
 String getURI()
          Get the URI to process.
 String getURIPrefix()
          Get the prefix of the URI in progress.
 String getView()
          Get the view to process
 boolean isInternalRedirect()
          Is this an internal redirect?
 boolean isResponseModified(long lastModified)
          Check if the response has been modified since the same "resource" was requested.
 void removeAttribute(String name)
          Removes the object bound with the specified name from this environment.
protected  void setAction(String action)
          Allow implementations to set action later than in super() constructor Action can be set only once, and should be set in implementation's constructor.
 void setAttribute(String name, Object value)
          Binds an object to this environment, using the name specified.
 void setResponseIsNotModified()
          Mark the response as not modified.
 void setStatus(int statusCode)
          Set the response status code
 void setURI(String prefix, String value)
          Set the URI and the prefix to process.
protected  void setView(String view)
          Allow implementations to set view later than in super() constructor.
 void startingProcessing()
          Notify that the processing starts.
 boolean tryResetResponse()
          Reset the response if possible.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.environment.Environment
getContentType, isExternal, redirect, setContentLength, setContentType
 

Field Detail

uri

protected String uri
The current uri in progress


prefix

protected String prefix
The prefix


view

protected String view
The View requested


action

protected String action
The Action requested


objectModel

protected Map objectModel
The object model


secureOutputStream

protected BufferedOutputStream secureOutputStream
The secure Output Stream


outputStream

protected OutputStream outputStream
The real output stream

Constructor Detail

AbstractEnvironment

public AbstractEnvironment(String uri,
                           String view)
Constructs the abstract environment


AbstractEnvironment

public AbstractEnvironment(String uri,
                           String view,
                           String action)
Constructs the abstract environment

Method Detail

setView

protected void setView(String view)
Allow implementations to set view later than in super() constructor. View can be set only once, and should be set in implementation's constructor.


setAction

protected void setAction(String action)
Allow implementations to set action later than in super() constructor Action can be set only once, and should be set in implementation's constructor.


extractView

protected static String extractView(Request request)
Helper method to extract the view name from the request.


extractAction

protected static String extractAction(Request req)
Helper method to extract the action name from the request.


getURI

public String getURI()
Description copied from interface: Environment
Get the URI to process. The prefix is stripped off.

Specified by:
getURI in interface Environment

getURIPrefix

public String getURIPrefix()
Description copied from interface: Environment
Get the prefix of the URI in progress.

Specified by:
getURIPrefix in interface Environment

setURI

public void setURI(String prefix,
                   String value)
Description copied from interface: Environment
Set the URI and the prefix to process.

Specified by:
setURI in interface Environment

getView

public String getView()
Description copied from interface: Environment
Get the view to process

Specified by:
getView in interface Environment

getAction

public String getAction()
Description copied from interface: Environment
Get the action to process

Specified by:
getAction in interface Environment

setStatus

public void setStatus(int statusCode)
Description copied from interface: Environment
Set the response status code

Specified by:
setStatus in interface Environment

getObjectModel

public Map getObjectModel()
Description copied from interface: Environment
Get the underlying object model

Specified by:
getObjectModel in interface Environment

isResponseModified

public boolean isResponseModified(long lastModified)
Description copied from interface: Environment
Check if the response has been modified since the same "resource" was requested. The caller has to test if it is really the same "resource" which is requested.

Specified by:
isResponseModified in interface Environment
Returns:
true if the response is modified or if the environment is not able to test it

setResponseIsNotModified

public void setResponseIsNotModified()
Description copied from interface: Environment
Mark the response as not modified.

Specified by:
setResponseIsNotModified in interface Environment

getAttribute

public Object getAttribute(String name)
Description copied from interface: Environment
Returns the object bound with the specified name, or null if no object is bound under the name.

Specified by:
getAttribute in interface Environment
Parameters:
name - a string specifying the name of the object
Returns:
the object with the specified name

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: Environment
Binds an object to this environment, using the name specified. This allows the pipeline assembly engine to store for its own use objects that souldn't be exposed to other components (generators, selectors, etc) and therefore cannot be put in the object model.

If an object of the same name is already bound, the object is replaced.

Specified by:
setAttribute in interface Environment
Parameters:
name - the name to which the object is bound
value - the object to be bound

removeAttribute

public void removeAttribute(String name)
Description copied from interface: Environment
Removes the object bound with the specified name from this environment. If the environment does not have an object bound with the specified name, this method does nothing.

Specified by:
removeAttribute in interface Environment
Parameters:
name - the name of the object to remove

getAttributeNames

public Enumeration getAttributeNames()
Description copied from interface: Environment
Returns an Enumeration of String objects containing the names of all the objects bound to this environment.

Specified by:
getAttributeNames in interface Environment
Returns:
an Enumeration of Strings.

getOutputStream

public OutputStream getOutputStream(int bufferSize)
                             throws IOException
Description copied from interface: Environment
Get the output stream where to write the generated resource. The returned stream is buffered by the environment. If the buffer size is -1 then the complete output is buffered. If the buffer size is 0, no buffering takes place.

Specified by:
getOutputStream in interface Environment
Throws:
IOException

tryResetResponse

public boolean tryResetResponse()
                         throws IOException
Description copied from interface: Environment
Reset the response if possible. This allows error handlers to have a higher chance to produce clean output if the pipeline that raised the error has already output some data. If a buffered output stream is used, resetting is always successful.

Specified by:
tryResetResponse in interface Environment
Returns:
true if the response was successfully reset
Throws:
IOException

commitResponse

public void commitResponse()
                    throws IOException
Description copied from interface: Environment
Commit the response

Specified by:
commitResponse in interface Environment
Throws:
IOException

startingProcessing

public void startingProcessing()
Description copied from interface: Environment
Notify that the processing starts.

Specified by:
startingProcessing in interface Environment

finishingProcessing

public void finishingProcessing()
Description copied from interface: Environment
Notify that the processing is finished This can be used to cleanup the environment object

Specified by:
finishingProcessing in interface Environment

isInternalRedirect

public boolean isInternalRedirect()
Description copied from interface: Environment
Is this an internal redirect? An environment is on internal redirect if it is an internal request (via the cocoon: protocol) and used for a redirect.

Specified by:
isInternalRedirect in interface Environment


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.