org.apache.cocoon.environment.wrapper
Class MutableEnvironmentFacade

java.lang.Object
  extended by org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade
All Implemented Interfaces:
Environment, SourceResolver

public class MutableEnvironmentFacade
extends Object
implements Environment

Enviroment facade, whose delegate object can be changed. This class is required to handle internal redirects in sitemap sources ("cocoon:"). This is because SitemapSource keeps the environment in which the internal request should be processed. But internal redirects create a new processing environment and there's no way to change the one held by the SitemapSource. So the processing of internal redirects actually changes the delegate of this class, transparently for the SitemapSource.

Version:
$Id: MutableEnvironmentFacade.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Sylvain Wallez
See Also:
SitemapSource

Field Summary
 
Fields inherited from interface org.apache.excalibur.source.SourceResolver
METHOD, ROLE, URI_ENCODING, URI_PARAMETERS
 
Constructor Summary
MutableEnvironmentFacade(EnvironmentWrapper env)
           
 
Method Summary
 void changeContext(String uriprefix, String context)
          Change the context from uriprefix to context
 void commitResponse()
          Commit the response
 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.
 String getContentType()
          Get the content type of the resource
 String getContext()
          Get current context
 EnvironmentWrapper getDelegate()
           
 Map getObjectModel()
          Get the underlying object model
 OutputStream getOutputStream()
          Deprecated. Use getOutputStream(int) instead.
 OutputStream getOutputStream(int bufferSize)
          Get the output stream where to write the generated resource.
 String getRedirectURL()
           
 String getRootContext()
          Get the Root Context
 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 isExternal()
          Is this environment external ?
 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 redirect(boolean sessionmode, String url)
          Redirect the client to the given URL
 void release(Source arg0)
           
 void removeAttribute(String name)
          Removes the object bound with the specified name from this environment.
 void reset()
           
 Source resolve(String systemID)
          Resolve the source.
 Source resolveURI(String arg0)
           
 Source resolveURI(String arg0, String arg1, Map arg2)
           
 void setAttribute(String name, Object value)
          Binds an object to this environment, using the name specified.
 void setContentLength(int length)
          Set the length of the generated content
 void setContentType(String mimeType)
          Set the content type of the generated resource
 void setContext(String prefix, String uri, String context)
          Set the context.
 void setDelegate(EnvironmentWrapper env)
           
 void setOutputStream(OutputStream os)
           
 void setResponseIsNotModified()
          Mark the response as not modified.
 void setStatus(int statusCode)
          Set the response status code
 void setURI(String prefix, String uri)
           
 void startingProcessing()
          Notify that the processing starts.
 boolean tryResetResponse()
          Reset the response if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MutableEnvironmentFacade

public MutableEnvironmentFacade(EnvironmentWrapper env)
Method Detail

getDelegate

public EnvironmentWrapper getDelegate()

setDelegate

public void setDelegate(EnvironmentWrapper env)

setURI

public void setURI(String prefix,
                   String uri)

setOutputStream

public void setOutputStream(OutputStream os)

getRedirectURL

public String getRedirectURL()

reset

public void reset()

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

getRootContext

public String getRootContext()
Description copied from interface: Environment
Get the Root Context

Specified by:
getRootContext in interface Environment

getContext

public String getContext()
Description copied from interface: Environment
Get current context

Specified by:
getContext 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

setContext

public void setContext(String prefix,
                       String uri,
                       String context)
Description copied from interface: Environment
Set the context. This is similar to changeContext() except that it is absolute.

Specified by:
setContext in interface Environment

changeContext

public void changeContext(String uriprefix,
                          String context)
                   throws Exception
Description copied from interface: Environment
Change the context from uriprefix to context

Specified by:
changeContext in interface Environment
Throws:
Exception

redirect

public void redirect(boolean sessionmode,
                     String url)
              throws IOException
Description copied from interface: Environment
Redirect the client to the given URL

Specified by:
redirect in interface Environment
Throws:
IOException

setContentType

public void setContentType(String mimeType)
Description copied from interface: Environment
Set the content type of the generated resource

Specified by:
setContentType in interface Environment

getContentType

public String getContentType()
Description copied from interface: Environment
Get the content type of the resource

Specified by:
getContentType in interface Environment

setContentLength

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

Specified by:
setContentLength 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

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Deprecated. Use getOutputStream(int) instead.

Description copied from interface: Environment
Get the output stream where to write the generated resource.

Specified by:
getOutputStream in interface Environment
Throws:
IOException
See Also:
Environment.getOutputStream()

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. This method replaces Environment.getOutputStream().

Specified by:
getOutputStream in interface Environment
Throws:
IOException

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

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

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

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.

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

isExternal

public boolean isExternal()
Description copied from interface: Environment
Is this environment external ? An external environment is one that is created in response to an external request (http, commandline, etc.). Environments created by the "cocoon:" protocol aren't external.

Specified by:
isExternal in interface Environment
Returns:
true if this environment is external

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

resolve

public Source resolve(String systemID)
               throws ProcessingException,
                      SAXException,
                      IOException
Description copied from interface: SourceResolver
Resolve the source.

Parameters:
systemID - This is either a system identifier (java.net.URL or a local file.
Throws:
ProcessingException
SAXException
IOException

resolveURI

public Source resolveURI(String arg0)
                  throws MalformedURLException,
                         IOException
Specified by:
resolveURI in interface SourceResolver
Throws:
MalformedURLException
IOException

resolveURI

public Source resolveURI(String arg0,
                         String arg1,
                         Map arg2)
                  throws MalformedURLException,
                         IOException
Specified by:
resolveURI in interface SourceResolver
Throws:
MalformedURLException
IOException

release

public void release(Source arg0)
Specified by:
release in interface SourceResolver


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.