org.apache.cocoon.environment
Class AbstractEnvironment

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

public abstract class AbstractEnvironment
extends AbstractLogEnabled
implements Environment

Base class for any environment

Version:
$Id: AbstractEnvironment.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Björn Lütkemeier, Giacomo Pati, Carsten Ziegeler

Field Summary
protected  String action
          The Action requested
protected static Method avalonToCocoonSourceWrapper
          The AvalonToCocoonSourceWrapper (this is for the deprecated support)
protected  String context
          The Context path
protected  boolean initializedComponents
          Do we have our components ?
protected  ComponentManager manager
          The component manager
protected  HashMap objectModel
          The servlet object model
protected  OutputStream outputStream
          The real output stream
protected  StringBuffer prefix
          The current prefix to strip off from the request uri
protected  String rootContext
          The root context path
protected  BufferedOutputStream secureOutputStream
          The secure Output Stream
protected  SourceResolver sourceResolver
          The real source resolver
protected  String uris
          The current uri in progress
protected  String view
          The View requested
 
Fields inherited from interface org.apache.excalibur.source.SourceResolver
METHOD, ROLE, URI_ENCODING, URI_PARAMETERS
 
Constructor Summary
AbstractEnvironment(String uri, String view, File file)
          Constructs the abstract environment
AbstractEnvironment(String uri, String view, File file, String action)
          Constructs the abstract environment
AbstractEnvironment(String uri, String view, String context, String action)
          Constructs the abstract environment
 
Method Summary
 void changeContext(String newPrefix, String newContext)
          Adds an prefix to the overall stripped off prefix from the request uri
 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()
          Returns the request action
 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 getContext()
          Get the current Context
 Map getObjectModel()
          Returns a Map containing environment specific objects
 OutputStream getOutputStream()
          Deprecated. Use getOutputStream(int) instead.
 OutputStream getOutputStream(int bufferSize)
          Get the output stream where to write the generated resource.
 String getRootContext()
          Get the Root Context
 String getURI()
          Returns the uri in progress.
 String getURIPrefix()
          Get the prefix of the URI in progress
 String getView()
          Returns the request view
 void globalRedirect(boolean sessionmode, String newURL)
           
protected  boolean hasAttribute(String name)
           
protected  void initComponents()
          Initialize the components for the environment This gets the source resolver and the xmlizer component
 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 release(Source source)
          Releases a resolved resource
 void removeAttribute(String name)
          Removes the object bound with the specified name from this environment.
 Source resolve(String systemId)
          Deprecated. Use the resolveURI methods instead
 Source resolveURI(String location)
          Get a Source object.
 Source resolveURI(String location, String baseURI, Map parameters)
          Get a Source object.
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.
protected  void setContext(String context)
          Set the context.
 void setContext(String prefix, String uri, String context)
          Set the context.
 void setResponseIsNotModified()
          Mark the response as not modified.
 void setStatus(int statusCode)
          Set a status code
protected  void setURIPrefix(String prefix)
          Set the prefix of the URI in progress
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

uris

protected String uris
The current uri in progress


prefix

protected StringBuffer prefix
The current prefix to strip off from the request uri


view

protected String view
The View requested


action

protected String action
The Action requested


context

protected String context
The Context path


rootContext

protected String rootContext
The root context path


objectModel

protected HashMap objectModel
The servlet object model


sourceResolver

protected SourceResolver sourceResolver
The real source resolver


manager

protected ComponentManager manager
The component manager


secureOutputStream

protected BufferedOutputStream secureOutputStream
The secure Output Stream


outputStream

protected OutputStream outputStream
The real output stream


avalonToCocoonSourceWrapper

protected static Method avalonToCocoonSourceWrapper
The AvalonToCocoonSourceWrapper (this is for the deprecated support)


initializedComponents

protected boolean initializedComponents
Do we have our components ?

Constructor Detail

AbstractEnvironment

public AbstractEnvironment(String uri,
                           String view,
                           File file)
                    throws MalformedURLException
Constructs the abstract environment

Throws:
MalformedURLException

AbstractEnvironment

public AbstractEnvironment(String uri,
                           String view,
                           File file,
                           String action)
                    throws MalformedURLException
Constructs the abstract environment

Throws:
MalformedURLException

AbstractEnvironment

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

Throws:
MalformedURLException
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()
Returns the uri in progress. The prefix is stripped off

Specified by:
getURI in interface Environment

getRootContext

public String getRootContext()
Get the Root Context

Specified by:
getRootContext in interface Environment

getContext

public String getContext()
Get the current Context

Specified by:
getContext in interface Environment

getURIPrefix

public String getURIPrefix()
Get the prefix of the URI in progress

Specified by:
getURIPrefix in interface Environment

setURIPrefix

protected void setURIPrefix(String prefix)
Set the prefix of the URI in progress


setContext

protected void setContext(String context)
Set the context.


setContext

public void setContext(String prefix,
                       String uri,
                       String context)
Set the context. This is similar to changeContext() except that it is absolute.

Specified by:
setContext in interface Environment

changeContext

public void changeContext(String newPrefix,
                          String newContext)
                   throws IOException
Adds an prefix to the overall stripped off prefix from the request uri

Specified by:
changeContext in interface Environment
Throws:
IOException

globalRedirect

public void globalRedirect(boolean sessionmode,
                           String newURL)
                    throws IOException
Throws:
IOException

getView

public String getView()
Returns the request view

Specified by:
getView in interface Environment

getAction

public String getAction()
Returns the request action

Specified by:
getAction in interface Environment

setStatus

public void setStatus(int statusCode)
Set a status code

Specified by:
setStatus in interface Environment

getObjectModel

public Map getObjectModel()
Returns a Map containing environment specific objects

Specified by:
getObjectModel in interface Environment

resolve

public Source resolve(String systemId)
               throws ProcessingException,
                      SAXException,
                      IOException
Deprecated. Use the resolveURI methods instead

Resolve an entity.

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

isResponseModified

public boolean isResponseModified(long lastModified)
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()
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

hasAttribute

protected boolean hasAttribute(String 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.

getOutputStream

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

Get the output stream where to write the generated resource.

Specified by:
getOutputStream in interface Environment
Throws:
IOException

getOutputStream

public OutputStream getOutputStream(int bufferSize)
                             throws IOException
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 getOutputStream().

Specified by:
getOutputStream in interface Environment
Throws:
IOException

tryResetResponse

public boolean tryResetResponse()
                         throws IOException
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.

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

commitResponse

public void commitResponse()
                    throws IOException
Commit the response

Specified by:
commitResponse in interface Environment
Throws:
IOException

resolveURI

public Source resolveURI(String location)
                  throws MalformedURLException,
                         IOException,
                         SourceException
Get a Source object.

Specified by:
resolveURI in interface SourceResolver
Throws:
MalformedURLException
IOException
SourceException

resolveURI

public Source resolveURI(String location,
                         String baseURI,
                         Map parameters)
                  throws MalformedURLException,
                         IOException,
                         SourceException
Get a Source object.

Specified by:
resolveURI in interface SourceResolver
Throws:
MalformedURLException
IOException
SourceException

release

public void release(Source source)
Releases a resolved resource

Specified by:
release in interface SourceResolver

initComponents

protected void initComponents()
Initialize the components for the environment This gets the source resolver and the xmlizer component


startingProcessing

public void startingProcessing()
Notify that the processing starts.

Specified by:
startingProcessing in interface Environment

finishingProcessing

public void finishingProcessing()
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-2010 The Apache Software Foundation. All Rights Reserved.