org.apache.cocoon.environment.wrapper
Class EnvironmentWrapper

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

public class EnvironmentWrapper
extends AbstractEnvironment

This is a wrapper class for the Environment object. It has the same properties except that the object model contains a RequestWrapper object.

Version:
CVS $Id: EnvironmentWrapper.java 165284 2005-04-29 09:24:28Z cziegeler $
Author:
Björn Lütkemeier, Carsten Ziegeler

Field Summary
protected  String contentType
           
protected  Environment environment
          The wrapped environment
protected  boolean internalRedirect
           
protected  OutputStream outputStream
          The stream to output to
protected  String redirectURL
          The redirect url
protected  Request request
          The request object
 
Fields inherited from class org.apache.cocoon.environment.AbstractEnvironment
action, objectModel, prefix, secureOutputStream, uri, view
 
Constructor Summary
EnvironmentWrapper(Environment env, SitemapSourceInfo info, Logger logger)
          Construct a new environment.
EnvironmentWrapper(Environment env, SitemapSourceInfo info, Logger logger, boolean wrapResponse)
          Construct a new environment.
 
Method Summary
 void commitResponse()
          Commit the response
 Object getAttribute(String name)
          Lookup an attribute in this instance, and if not found search it in the wrapped environment.
 String getContentType()
          Get the ContentType
 OutputStream getOutputStream(int bufferSize)
          Get the output stream where to write the generated resource.
 String getRedirectURL()
          if a redirect should happen this returns the url, otherwise null is returned
 boolean isExternal()
          Always return false.
 boolean isInternalRedirect()
          Is this an internal redirect?
 void redirect(String newURL, boolean global, boolean permanent)
          Redirect to the given URL
 void removeAttribute(String name)
          Remove attribute from the current instance, as well as from the wrapped environment.
 void reset()
           
 void setContentLength(int length)
          Set the length of the generated content
 void setContentType(String contentType)
          Set the ContentType
 void setInternalRedirect(boolean flag)
           
 void setOutputStream(OutputStream stream)
          Set the output stream for this environment.
 void setStatus(int statusCode)
          Set the StatusCode
 boolean tryResetResponse()
          Reset the response if possible.
 
Methods inherited from class org.apache.cocoon.environment.AbstractEnvironment
extractAction, extractView, finishingProcessing, getAction, getAttributeNames, getObjectModel, getURI, getURIPrefix, getView, isResponseModified, setAction, setAttribute, setResponseIsNotModified, setURI, setView, startingProcessing
 
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
 

Field Detail

environment

protected final Environment environment
The wrapped environment


redirectURL

protected String redirectURL
The redirect url


request

protected final Request request
The request object


outputStream

protected OutputStream outputStream
The stream to output to


contentType

protected String contentType

internalRedirect

protected boolean internalRedirect
Constructor Detail

EnvironmentWrapper

public EnvironmentWrapper(Environment env,
                          SitemapSourceInfo info,
                          Logger logger)
Construct a new environment.

Parameters:
env - The origial Environment
info - A description of the uri for the new environment
logger - The logger to be used by this environment

EnvironmentWrapper

public EnvironmentWrapper(Environment env,
                          SitemapSourceInfo info,
                          Logger logger,
                          boolean wrapResponse)
Construct a new environment.

Parameters:
env - The origial Environment
info - A description of the uri for the new environment
logger - The logger to be used by this environment
wrapResponse - Whether or not to wrap the Response object
Method Detail

redirect

public void redirect(String newURL,
                     boolean global,
                     boolean permanent)
              throws IOException
Description copied from interface: Environment
Redirect to the given URL

Throws:
IOException

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
Overrides:
getOutputStream in class AbstractEnvironment
Throws:
IOException

setOutputStream

public void setOutputStream(OutputStream stream)
Set the output stream for this environment. It hides the one of the wrapped environment.


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
Overrides:
tryResetResponse in class AbstractEnvironment
Throws:
IOException

commitResponse

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

Specified by:
commitResponse in interface Environment
Overrides:
commitResponse in class AbstractEnvironment
Throws:
IOException

getRedirectURL

public String getRedirectURL()
if a redirect should happen this returns the url, otherwise null is returned


reset

public void reset()

setStatus

public void setStatus(int statusCode)
Set the StatusCode

Specified by:
setStatus in interface Environment
Overrides:
setStatus in class AbstractEnvironment

setContentLength

public void setContentLength(int length)
Description copied from interface: Environment
Set the length of the generated content


setContentType

public void setContentType(String contentType)
Set the ContentType


getContentType

public String getContentType()
Get the ContentType


getAttribute

public Object getAttribute(String name)
Lookup an attribute in this instance, and if not found search it in the wrapped environment.

Specified by:
getAttribute in interface Environment
Overrides:
getAttribute in class AbstractEnvironment
Parameters:
name - a String, the name of the attribute to look for
Returns:
an Object, the value of the attribute or null if no such attribute was found.

removeAttribute

public void removeAttribute(String name)
Remove attribute from the current instance, as well as from the wrapped environment.

Specified by:
removeAttribute in interface Environment
Overrides:
removeAttribute in class AbstractEnvironment
Parameters:
name - a String value

isExternal

public boolean isExternal()
Always return false.

Returns:
true if this environment is external

setInternalRedirect

public void setInternalRedirect(boolean flag)

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
Overrides:
isInternalRedirect in class AbstractEnvironment


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