org.apache.cocoon.environment.internal
Class EnvironmentHelper

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.environment.internal.EnvironmentHelper
All Implemented Interfaces:
Component, Disposable, LogEnabled, Serviceable, SourceResolver, SourceResolver
Direct Known Subclasses:
BlockEnvironmentHelper

public class EnvironmentHelper
extends AbstractLogEnabled
implements SourceResolver, Serviceable, Disposable

Helper class for maintaining the environment stack. This is an internal class, and it might change in an incompatible way over time. For developing your own components/applications based on Cocoon, you shouldn't really need it.

Since:
2.2
Version:
$Id: EnvironmentHelper.java 312659 2005-10-10 14:11:48Z cziegeler $
Author:
Carsten Ziegeler

Nested Class Summary
static class EnvironmentHelper.AbstractCocoonRunnable
          A runnable wrapper that inherits the environment stack of the thread it is created in.
 
Field Summary
protected  String context
          The Context path
protected static ThreadLocal environmentStack
          The environment information
protected  String lastPrefix
          The last prefix, which is stripped off from the request uri
protected  ServiceManager manager
          The service manager
protected  String prefix
          The complete prefix
protected  SourceResolver resolver
          The real source resolver
 
Fields inherited from interface org.apache.excalibur.source.SourceResolver
METHOD, ROLE, URI_ENCODING, URI_PARAMETERS
 
Constructor Summary
EnvironmentHelper(EnvironmentHelper parent)
          Constructor
EnvironmentHelper(URL context)
          Constructor
 
Method Summary
 void changeContext(Environment env)
          Change the context of the environment.
 void changeContext(Source newSource, String newPrefix)
          Adds an prefix to the overall stripped off prefix from the request uri
static void checkEnvironment(int depth, Logger logger)
          INTERNAL METHOD.
static XMLConsumer createEnvironmentAwareConsumer(XMLConsumer consumer)
          Create an environment aware xml consumer for the cocoon protocol
static XMLConsumer createPopEnvironmentConsumer(XMLConsumer consumer)
          Create an environment aware xml consumer that pop and save the current environment before calling the consumer.
static XMLConsumer createPushEnvironmentConsumer(XMLConsumer consumer, Environment environment)
          Create an environment aware xml consumer that push an environment before calling the consumer.
 void dispose()
           
static void enterEnvironment(Environment env)
          This method is used for entering a new environment.
static void enterProcessor(Processor processor, ServiceManager manager, Environment env)
          This hook must be called by the sitemap each time a sitemap is entered.
 String getContext()
          Return the current context URI
static Environment getCurrentEnvironment()
          Return the environment
static Processor getCurrentProcessor()
          Return the current processor
 String getPrefix()
          Return the prefix
static ServiceManager getSitemapServiceManager()
          Get the current sitemap component manager.
static Environment leaveEnvironment()
          This method is used for leaving the current environment.
static void leaveProcessor()
          This hook must be called by the sitemap each time a sitemap is left.
static int markEnvironment()
          INTERNAL METHOD.
 void release(Source source)
           
 Source resolveURI(String location)
           
 Source resolveURI(String location, String baseURI, Map parameters)
           
 void service(ServiceManager manager)
           
 
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

environmentStack

protected static final ThreadLocal environmentStack
The environment information


resolver

protected SourceResolver resolver
The real source resolver


manager

protected ServiceManager manager
The service manager


prefix

protected String prefix
The complete prefix


context

protected String context
The Context path


lastPrefix

protected String lastPrefix
The last prefix, which is stripped off from the request uri

Constructor Detail

EnvironmentHelper

public EnvironmentHelper(URL context)
Constructor


EnvironmentHelper

public EnvironmentHelper(EnvironmentHelper parent)
Constructor

Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException
See Also:
Serviceable.service(org.apache.avalon.framework.service.ServiceManager)

dispose

public void dispose()
Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

release

public void release(Source source)
Specified by:
release in interface SourceResolver
See Also:
SourceResolver.release(org.apache.excalibur.source.Source)

resolveURI

public Source resolveURI(String location,
                         String baseURI,
                         Map parameters)
                  throws MalformedURLException,
                         IOException
Specified by:
resolveURI in interface SourceResolver
Throws:
MalformedURLException
IOException
See Also:
SourceResolver.resolveURI(java.lang.String, java.lang.String, java.util.Map)

resolveURI

public Source resolveURI(String location)
                  throws MalformedURLException,
                         IOException
Specified by:
resolveURI in interface SourceResolver
Throws:
MalformedURLException
IOException
See Also:
SourceResolver.resolveURI(java.lang.String)

getContext

public String getContext()
Return the current context URI


getPrefix

public String getPrefix()
Return the prefix


changeContext

public void changeContext(Environment env)
                   throws ProcessingException
Change the context of the environment.

Parameters:
env - The environment to change
Throws:
ProcessingException

changeContext

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

Throws:
IOException

enterProcessor

public static void enterProcessor(Processor processor,
                                  ServiceManager manager,
                                  Environment env)
                           throws ProcessingException
This hook must be called by the sitemap each time a sitemap is entered.

This method should never raise an exception, except when the parameters are not set!

Throws:
ProcessingException - if processor is null

leaveProcessor

public static void leaveProcessor()
This hook must be called by the sitemap each time a sitemap is left.

It's the counterpart to the enterProcessor(Processor, ServiceManager, Environment) method.


enterEnvironment

public static void enterEnvironment(Environment env)
                             throws ProcessingException
This method is used for entering a new environment.

Throws:
ProcessingException - if there is no current processing environment

leaveEnvironment

public static Environment leaveEnvironment()
This method is used for leaving the current environment.

It's the counterpart to the enterEnvironment(Environment) method.


markEnvironment

public static int markEnvironment()
INTERNAL METHOD. Do not use, can be removed without warning or deprecation cycle.


checkEnvironment

public static void checkEnvironment(int depth,
                                    Logger logger)
                             throws Exception
INTERNAL METHOD. Do not use, can be removed without warning or deprecation cycle.

Throws:
Exception

getCurrentEnvironment

public static Environment getCurrentEnvironment()
Return the environment


getCurrentProcessor

public static Processor getCurrentProcessor()
Return the current processor


getSitemapServiceManager

public static ServiceManager getSitemapServiceManager()
Get the current sitemap component manager. This method return the current sitemap component manager. This is the manager that holds all the components of the currently processed (sub)sitemap.


createEnvironmentAwareConsumer

public static XMLConsumer createEnvironmentAwareConsumer(XMLConsumer consumer)
Create an environment aware xml consumer for the cocoon protocol


createPushEnvironmentConsumer

public static XMLConsumer createPushEnvironmentConsumer(XMLConsumer consumer,
                                                        Environment environment)
Create an environment aware xml consumer that push an environment before calling the consumer.


createPopEnvironmentConsumer

public static XMLConsumer createPopEnvironmentConsumer(XMLConsumer consumer)
Create an environment aware xml consumer that pop and save the current environment before calling the consumer.



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