cziegeler 2003/10/29 10:58:06
Modified: src/java/org/apache/cocoon/components/source/impl
SitemapSource.java
src/java/org/apache/cocoon/components
DefaultSitemapConfigurationHolder.java
RequestLifecycleHelper.java
RequestLifestyleComponentHandler.java
ComponentContext.java
src/java/org/apache/cocoon/environment
EnvironmentHelper.java AbstractEnvironment.java
Environment.java EnvironmentStack.java
src/java/org/apache/cocoon/environment/wrapper
EnvironmentWrapper.java
src/java/org/apache/cocoon ProcessorWrapper.java
Processor.java Cocoon.java
src/java/org/apache/cocoon/components/treeprocessor
TreeProcessor.java
src/java/org/apache/cocoon/environment/http
HttpEnvironment.java
src/java/org/apache/cocoon/transformation
TraxTransformer.java
src/java/org/apache/cocoon/environment/commandline
AbstractCommandLineEnvironment.java
Added: src/java/org/apache/cocoon/environment
EnvironmentContext.java EnvironmentInfo.java
Log:
More changes to the environment handling
Revision Changes Path
1.16 +19 -19
cocoon-2.2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
Index: SitemapSource.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- SitemapSource.java 29 Oct 2003 14:45:54 -0000 1.15
+++ SitemapSource.java 29 Oct 2003 18:58:05 -0000 1.16
@@ -65,10 +65,10 @@
import org.apache.cocoon.Constants;
import org.apache.cocoon.Processor;
import org.apache.cocoon.ResourceNotFoundException;
-import org.apache.cocoon.components.CocoonComponentManager;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.EnvironmentHelper;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
@@ -155,7 +155,7 @@
Logger logger)
throws MalformedURLException {
- Environment env = CocoonComponentManager.getCurrentEnvironment();
+ Environment env =
EnvironmentHelper.getCurrentContext().getEnvironment();
if ( env == null ) {
throw new MalformedURLException("The cocoon protocol can not be
used outside an environment.");
}
@@ -191,7 +191,7 @@
} else if (uri.startsWith("/", position)) {
position ++;
prefix = null;
- this.processor = CocoonComponentManager.getCurrentProcessor();
+ this.processor = EnvironmentHelper.getCurrentProcessor();
} else {
throw new MalformedURLException("Malformed cocoon URI: " + uri);
}
@@ -301,14 +301,14 @@
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
this.environment.setOutputStream(os);
- CocoonComponentManager.enterEnvironment(this.environment,
- this.manager,
- this.pipelineProcessor);
+ EnvironmentHelper.enterProcessor(this.pipelineProcessor,
+ this.manager,
+ this.environment);
try {
this.processingPipeline.process(this.environment);
} finally {
- CocoonComponentManager.leaveEnvironment();
+ EnvironmentHelper.leaveProcessor();
}
return new ByteArrayInputStream(os.toByteArray());
@@ -378,17 +378,17 @@
protected void init() {
this.systemIdForCaching = this.systemId;
try {
- this.processKey =
CocoonComponentManager.startProcessing(this.environment);
+ this.processKey =
EnvironmentHelper.startProcessing(this.environment);
this.processingPipeline =
this.processor.buildPipeline(this.environment);
- this.pipelineProcessor =
CocoonComponentManager.getLastProcessor(this.environment);
+ this.pipelineProcessor =
EnvironmentHelper.getLastProcessor(this.environment);
this.environment.changeToLastContext();
String redirectURL = this.environment.getRedirectURL();
if (redirectURL == null) {
- CocoonComponentManager.enterEnvironment(this.environment,
- this.manager,
-
this.pipelineProcessor);
+ EnvironmentHelper.enterProcessor(this.pipelineProcessor,
+ this.manager,
+ this.environment);
try {
this.processingPipeline.prepareInternal(this.environment);
this.sourceValidity =
this.processingPipeline.getValidityForEventPipeline();
@@ -407,7 +407,7 @@
this.systemIdForCaching = this.systemId;
}
} finally {
- CocoonComponentManager.leaveEnvironment();
+ EnvironmentHelper.leaveProcessor();
}
} else {
if (redirectURL.indexOf(":") == -1) {
@@ -456,14 +456,14 @@
}
// We have to add an environment changer
// for clean environment stack handling.
- CocoonComponentManager.enterEnvironment(this.environment,
- this.manager,
-
this.pipelineProcessor);
+ EnvironmentHelper.enterProcessor(this.pipelineProcessor,
+ this.manager,
+ this.environment);
try {
this.processingPipeline.process(this.environment,
-
CocoonComponentManager.createEnvironmentAwareConsumer(consumer));
+
EnvironmentHelper.createEnvironmentAwareConsumer(consumer));
} finally {
- CocoonComponentManager.leaveEnvironment();
+ EnvironmentHelper.leaveProcessor();
}
}
} catch (SAXException e) {
@@ -483,7 +483,7 @@
private void reset() {
if (this.processingPipeline != null)
this.processingPipeline.release();
if (this.processKey != null) {
- CocoonComponentManager.endProcessing(this.environment,
this.processKey);
+ EnvironmentHelper.endProcessing(this.environment,
this.processKey);
this.processKey = null;
}
this.processingPipeline = null;
1.7 +4 -2
cocoon-2.2/src/java/org/apache/cocoon/components/DefaultSitemapConfigurationHolder.java
Index: DefaultSitemapConfigurationHolder.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/DefaultSitemapConfigurationHolder.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultSitemapConfigurationHolder.java 22 Oct 2003 15:37:50 -0000
1.6
+++ DefaultSitemapConfigurationHolder.java 29 Oct 2003 18:58:05 -0000
1.7
@@ -53,6 +53,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.cocoon.environment.EnvironmentHelper;
+
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
@@ -75,7 +77,7 @@
* @see SitemapConfigurationHolder#getConfiguration()
*/
public ChainedConfiguration getConfiguration() {
- Map confs =
RequestLifecycleHelper.getCurrentProcessor().getComponentConfigurations();
+ Map confs =
EnvironmentHelper.getCurrentProcessor().getComponentConfigurations();
return (ChainedConfiguration) (confs == null ? null :
confs.get(this.role));
}
1.5 +27 -213
cocoon-2.2/src/java/org/apache/cocoon/components/RequestLifecycleHelper.java
Index: RequestLifecycleHelper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/RequestLifecycleHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RequestLifecycleHelper.java 24 Oct 2003 07:29:56 -0000 1.4
+++ RequestLifecycleHelper.java 29 Oct 2003 18:58:05 -0000 1.5
@@ -49,15 +49,18 @@
*/
package org.apache.cocoon.components;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.Processor;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.xml.XMLConsumer;
-
-import java.util.*;
+import org.apache.cocoon.environment.EnvironmentContext;
+import org.apache.cocoon.environment.EnvironmentHelper;
/**
* RequestLifecycleHelper Encapsulates all the static processing that is
needed
@@ -66,183 +69,29 @@
* @author <a href="bloritsch.at.apache.org">Berin Loritsch</a>
* @version CVS $ Revision: 1.1 $
*/
-class RequestLifecycleHelper
-{
- /** The key used to store the current process environment */
- static final String PROCESS_KEY = RequestLifecycleHelper.class.getName();
- /** The environment information */
- private static InheritableThreadLocal environmentStack = new
CloningInheritableThreadLocal();
-
- static EnvironmentStack getTopEnvironmentStack()
- {
- return (EnvironmentStack)environmentStack.get();
- }
-
- /**
- * 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!
- */
- static void enterEnvironment(Environment env,
- ComponentHandler manager,
- Processor processor) {
- if ( null == env || null == manager || null == processor) {
- throw new
IllegalArgumentException("CocoonComponentManager.enterEnvironment: all
parameters must be set: " + env + " - " + manager + " - " + processor);
- }
-
- EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
- if (stack == null) {
- stack = new EnvironmentStack();
- environmentStack.set(stack);
- }
- stack.push(new Object[] {env, processor, manager, new
Integer(stack.getOffset())});
- stack.setOffset(stack.size()-1);
-
- env.setAttribute("CocoonComponentManager.processor", processor);
- }
-
- /**
- * This hook must be called by the sitemap each time a sitemap is left.
- * It's the counterpart to [EMAIL PROTECTED]
#enterEnvironment(Environment, ComponentHandler, Processor)}.
- */
- static void leaveEnvironment() {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- final Object[] objs = (Object[])stack.pop();
- stack.setOffset(((Integer)objs[3]).intValue());
- if ( stack.isEmpty() ) {
- final Environment env = (Environment)objs[0];
- final Map globalComponents =
(Map)env.getAttribute(GlobalRequestLifecycleComponent.class.getName());
- if ( globalComponents != null) {
+class RequestLifecycleHelper {
- final Iterator iter = globalComponents.values().iterator();
- while ( iter.hasNext() ) {
- final Object[] o = (Object[])iter.next();
- final Object c = o[0];
- ((RequestLifestyleComponentHandler)o[1]).release( c );
- }
- }
-
env.removeAttribute(GlobalRequestLifecycleComponent.class.getName());
+ static final String KEY = RequestLifecycleHelper.class.getName();
+
+ static EnvironmentDescription getEnvironmentDescription() {
+ final EnvironmentContext context =
EnvironmentHelper.getCurrentContext();
+ EnvironmentDescription desc = (EnvironmentDescription)
context.getAttribute(KEY);
+ if ( desc == null ) {
+ desc = new EnvironmentDescription(context.getEnvironment());
+ context.addAttribute(KEY, desc);
}
- }
-
- static void checkEnvironment(Logger logger)
- throws Exception {
- // TODO (CZ): This is only for testing - remove it later on
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- if (stack != null && !stack.isEmpty() ) {
- logger.error("ENVIRONMENT STACK HAS NOT BEEN CLEANED PROPERLY");
- throw new ProcessingException("Environment stack has not been
cleaned up properly. "
- +"Please report this (if possible
together with a test case) "
- +"to the Cocoon developers.");
- }
- }
-
- /**
- * Create an environment aware xml consumer for the cocoon
- * protocol
- */
- static XMLConsumer createEnvironmentAwareConsumer(XMLConsumer consumer) {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- final Object[] objs = (Object[])stack.getCurrent();
- return stack.getEnvironmentAwareConsumerWrapper(consumer,
((Integer)objs[3]).intValue());
- }
-
- /**
- * This hook has to be called before a request is processed.
- * The hook is called by the Cocoon component and by the
- * cocoon protocol implementation.
- * This method should never raise an exception, except when
- * the environment is not set.
- *
- * @return A unique key within this thread.
- */
- static Object startProcessing(Environment env) {
- if ( null == env) {
- throw new
RuntimeException("CocoonComponentManager.startProcessing: environment must be
set.");
- }
- final EnvironmentDescription desc = new EnvironmentDescription(env);
- env.getObjectModel().put(PROCESS_KEY, desc);
- env.startingProcessing();
return desc;
}
-
- /**
- * This hook has to be called before a request is processed.
- * The hook is called by the Cocoon component and by the
- * cocoon protocol implementation.
- * @param key A unique key within this thread return by
- * [EMAIL PROTECTED] #startProcessing(Environment)}.
- */
- static void endProcessing(Environment env, Object key) {
- env.finishingProcessing();
- final EnvironmentDescription desc = (EnvironmentDescription)key;
- desc.release();
- env.getObjectModel().remove(PROCESS_KEY);
- }
-
- /**
- * Return the current environment (for the cocoon: protocol)
- */
- static Environment getCurrentEnvironment() {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- if (null != stack && !stack.empty()) {
- return (Environment) ((Object[])stack.getCurrent())[0];
- }
- return null;
- }
-
- /**
- * Return the current processor (for the cocoon: protocol)
- */
- static Processor getCurrentProcessor() {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- if (null != stack && !stack.empty()) {
- return (Processor) ((Object[])stack.getCurrent())[1];
- }
- return null;
- }
-
- /**
- * Return the processor that is actually processing the request
- */
- static Processor getLastProcessor(Environment env) {
- return
(Processor)env.getAttribute("CocoonComponentManager.processor");
- }
-
- /**
- * 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.
- */
- static public ServiceManager getSitemapComponentManager() {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
-
- if ( null != stack && !stack.empty()) {
- Object[] o = (Object[])stack.peek();
- return (ServiceManager)o[2];
- }
-
- // if we don't have an environment yet, just return null
- return null;
- }
-
+
/**
* Add an automatically released component
*/
static void addComponentForAutomaticRelease(final ComponentHandler
manager,
final Object
component)
throws ProcessingException {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.get(0);
- final Map objectModel =
((Environment)objects[0]).getObjectModel();
- EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
- if ( null != desc ) {
- desc.addToAutoRelease(manager, component);
- }
- } else {
- throw new ProcessingException("Unable to add component for
automatic release: no environment available.");
+ EnvironmentDescription desc = getEnvironmentDescription();
+ if ( null != desc ) {
+ desc.addToAutoRelease(manager, component);
}
}
@@ -251,50 +100,15 @@
*/
public static void removeFromAutomaticRelease(final Object component)
throws ProcessingException {
- final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.get(0);
- final Map objectModel =
((Environment)objects[0]).getObjectModel();
- EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
- if ( null != desc ) {
- desc.removeFromAutoRelease(component);
- }
- } else {
- throw new ProcessingException("Unable to remove component from
automatic release: no environment available.");
- }
- }
-}
-
-final class CloningInheritableThreadLocal
- extends InheritableThreadLocal
-{
-
- /**
- * Computes the child's initial value for this InheritableThreadLocal
- * as a function of the parent's value at the time the child Thread is
- * created. This method is called from within the parent thread before
- * the child is started.
- * <p>
- * This method merely returns its input argument, and should be
overridden
- * if a different behavior is desired.
- *
- * @param parentValue the parent thread's value
- * @return the child thread's initial value
- */
- protected Object childValue( Object parentValue )
- {
- if ( null != parentValue )
- {
- return ( (EnvironmentStack) parentValue ).clone();
- }
- else
- {
- return null;
+ EnvironmentDescription desc = getEnvironmentDescription();
+ if ( null != desc ) {
+ desc.removeFromAutoRelease(component);
}
}
}
final class EnvironmentDescription
+implements Disposable
{
Environment environment;
Map objectModel;
@@ -326,7 +140,7 @@
* All RequestLifecycleComponents and autoreleaseComponents are
* released.
*/
- void release()
+ public void dispose()
{
if ( this.requestLifecycleComponents != null )
{
1.3 +30 -50
cocoon-2.2/src/java/org/apache/cocoon/components/RequestLifestyleComponentHandler.java
Index: RequestLifestyleComponentHandler.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/RequestLifestyleComponentHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestLifestyleComponentHandler.java 22 Oct 2003 15:37:50 -0000
1.2
+++ RequestLifestyleComponentHandler.java 29 Oct 2003 18:58:05 -0000
1.3
@@ -55,11 +55,9 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.environment.Environment;
import org.apache.excalibur.mpool.Pool;
import org.apache.excalibur.mpool.PoolManager;
-import java.util.Map;
/**
* RequestLifestyleComponentHandler does XYZ
@@ -124,16 +122,10 @@
* @exception Exception if an error occurs
*/
protected Object doGet()
- throws Exception
- {
- final EnvironmentStack stack =
RequestLifecycleHelper.getTopEnvironmentStack();
- if ( null != stack && !stack.empty() )
- {
- final Object[] objects = (Object[]) stack.getCurrent();
- final Map objectModel = ( (Environment) objects[0]
).getObjectModel();
- EnvironmentDescription desc = (EnvironmentDescription)
objectModel.get( RequestLifecycleHelper.PROCESS_KEY );
- if ( null != desc )
- {
+ throws Exception {
+ EnvironmentDescription desc =
RequestLifecycleHelper.getEnvironmentDescription();
+ if ( null != desc ) {
+ if ( null != desc ) {
Object component = desc.getRequestLifecycleComponent( m_role
);
if ( null != component )
{
@@ -150,61 +142,49 @@
final Object component = m_pool.acquire();
if ( null != component && component instanceof
RequestLifecycleComponent )
{
- if ( stack == null || stack.empty() )
+ if ( desc == null )
{
throw new ServiceException( m_role, "ComponentManager has no
Environment Stack." );
}
- final Object[] objects = (Object[]) stack.getCurrent();
- final Map objectModel = ( (Environment) objects[0]
).getObjectModel();
- EnvironmentDescription desc = (EnvironmentDescription)
objectModel.get( RequestLifecycleHelper.PROCESS_KEY );
- if ( null != desc )
- {
- // first test if the parent CM has already initialized this
component
- if ( !desc.containsRequestLifecycleComponent( m_role ) )
+ // first test if the parent CM has already initialized this
component
+ if ( !desc.containsRequestLifecycleComponent( m_role ) )
+ {
+ try
+ { // FIXME - we need a source resolver here!
+ ( (RequestLifecycleComponent) component ).setup(
+ null,
+ desc.objectModel );
+ }
+ catch ( Exception local )
{
- try
- {
- ( (RequestLifecycleComponent) component ).setup(
-
(org.apache.cocoon.environment.SourceResolver) objects[0],
- objectModel );
- }
- catch ( Exception local )
- {
- throw new ServiceException( m_role, "Exception
during setup of RequestLifecycleComponent.", local );
- }
- desc.addRequestLifecycleComponent( m_role, component,
this );
+ throw new ServiceException( m_role, "Exception during
setup of RequestLifecycleComponent.", local );
}
+ desc.addRequestLifecycleComponent( m_role, component, this );
}
}
if ( null != component && component instanceof
GlobalRequestLifecycleComponent )
{
- if ( stack == null || stack.empty() )
+ if ( desc == null )
{
throw new ServiceException( m_role, "ComponentManager has no
Environment Stack." );
}
- final Object[] objects = (Object[]) stack.getCurrent();
- final Map objectModel = ( (Environment) objects[0]
).getObjectModel();
- EnvironmentDescription desc = (EnvironmentDescription)
objectModel.get( RequestLifecycleHelper.PROCESS_KEY );
- if ( null != desc )
- {
- // first test if the parent CM has already initialized this
component
- if ( !desc.containsGlobalRequestLifecycleComponent( m_role )
)
+ // first test if the parent CM has already initialized this
component
+ if ( !desc.containsGlobalRequestLifecycleComponent( m_role ) )
+ {
+ try
+ { // FIXME - we need a source resolver here!
+ ( (GlobalRequestLifecycleComponent) component ).setup(
+ null,
+ desc.objectModel );
+ }
+ catch ( Exception local )
{
- try
- {
- ( (GlobalRequestLifecycleComponent) component
).setup(
-
(org.apache.cocoon.environment.SourceResolver) objects[0],
- objectModel );
- }
- catch ( Exception local )
- {
- throw new ServiceException( m_role, "Exception
during setup of RequestLifecycleComponent.", local );
- }
- desc.addGlobalRequestLifecycleComponent( m_role,
component, this );
+ throw new ServiceException( m_role, "Exception during
setup of RequestLifecycleComponent.", local );
}
+ desc.addGlobalRequestLifecycleComponent( m_role, component,
this );
}
}
1.6 +4 -3
cocoon-2.2/src/java/org/apache/cocoon/components/ComponentContext.java
Index: ComponentContext.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/ComponentContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ComponentContext.java 22 Oct 2003 15:37:50 -0000 1.5
+++ ComponentContext.java 29 Oct 2003 18:58:05 -0000 1.6
@@ -53,6 +53,7 @@
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.cocoon.environment.EnvironmentHelper;
import java.util.Map;
@@ -116,12 +117,12 @@
public Object get( final Object key )
throws ContextException {
if ( key.equals(ContextHelper.CONTEXT_OBJECT_MODEL)) {
- return
RequestLifecycleHelper.getCurrentEnvironment().getObjectModel();
+ return
EnvironmentHelper.getCurrentContext().getEnvironment().getObjectModel();
}
if ( key instanceof String ) {
String stringKey = (String)key;
if ( stringKey.startsWith(OBJECT_MODEL_KEY_PREFIX) ) {
- final Map objectModel =
RequestLifecycleHelper.getCurrentEnvironment().getObjectModel();
+ final Map objectModel =
EnvironmentHelper.getCurrentContext().getEnvironment().getObjectModel();
String objectKey =
stringKey.substring(OBJECT_MODEL_KEY_PREFIX.length());
Object o = objectModel.get( objectKey );
1.6 +94 -9
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java
Index: EnvironmentHelper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentHelper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EnvironmentHelper.java 27 Oct 2003 07:57:26 -0000 1.5
+++ EnvironmentHelper.java 29 Oct 2003 18:58:06 -0000 1.6
@@ -56,6 +56,7 @@
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
@@ -72,11 +73,14 @@
* @version CVS $Id$
* @since 2.2
*/
-
public class EnvironmentHelper
extends AbstractLogEnabled
implements SourceResolver, Serviceable, Disposable {
+ /** The key used to store the current environment context
+ * in the object model */
+ static final String PROCESS_KEY = EnvironmentHelper.class.getName();
+
/** The real source resolver */
protected org.apache.excalibur.source.SourceResolver resolver;
@@ -122,7 +126,7 @@
this.rootContext = this.context;
}
} catch (IOException ioe) {
- throw new ServiceException("Unable to resolve environment
context. ", ioe);
+ throw new ServiceException("EnvironmentHelper", "Unable to
resolve environment context. ", ioe);
} finally {
this.resolver.release(source);
}
@@ -168,10 +172,24 @@
return this.resolveURI(location, null, null);
}
+ /**
+ * Return the current context URI
+ */
+ public String getContext() {
+ return this.context;
+ }
+
+ /**
+ * Return the prefix
+ */
+ public String getPrefix() {
+ return this.prefix;
+ }
+
public void changeContext(Environment env)
throws ProcessingException {
- String uris = env.getURI();
if ( this.prefix != null ) {
+ String uris = env.getURIPrefix() + '/' + env.getURI();
if (!uris.startsWith(this.prefix)) {
String message = "The current URI (" + uris +
") doesn't start with given prefix (" +
prefix + ")";
@@ -182,7 +200,7 @@
// of uris - the prefix always ends with a slash!
final int l = this.prefix.length();
uris = uris.substring(l);
- env.setURI(uris);
+ env.setURI(this.prefix, uris);
}
}
@@ -263,7 +281,9 @@
* This method should never raise an exception, except when the
* parameters are not set!
*/
- public static void enterProcessor(Processor processor) {
+ public static void enterProcessor(Processor processor,
+ ServiceManager manager,
+ Environment env) {
if ( null == processor) {
throw new IllegalArgumentException("Processor is not set.");
}
@@ -273,8 +293,10 @@
stack = new EnvironmentStack();
environmentStack.set(stack);
}
- stack.push(new EnvironmentInfo(processor, stack.getOffset()));
+ stack.pushInfo(new EnvironmentInfo(processor, stack.getOffset(),
manager, env));
stack.setOffset(stack.size()-1);
+ // FIXME - Put it somewhere else
+ env.setAttribute("EnvironmentHelper.processor", processor);
}
/**
@@ -287,25 +309,88 @@
stack.setOffset(info.oldStackCount);
}
+ public static void checkEnvironment(Logger logger)
+ throws Exception {
+ // TODO (CZ): This is only for testing - remove it later on
+ final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
+ if (stack != null && !stack.isEmpty() ) {
+ logger.error("ENVIRONMENT STACK HAS NOT BEEN CLEANED PROPERLY");
+ throw new ProcessingException("Environment stack has not been
cleaned up properly. "
+ +"Please report this (if possible
together with a test case) "
+ +"to the Cocoon developers.");
+ }
+ }
+
+ /**
+ * This hook has to be called before a request is processed.
+ * The hook is called by the Cocoon component and by the
+ * cocoon protocol implementation.
+ * This method should never raise an exception, except when
+ * the environment is not set.
+ *
+ * @return A unique key within this thread.
+ */
+ public static Object startProcessing(Environment env) {
+ if ( null == env) {
+ throw new RuntimeException("EnvironmentHelper.startProcessing:
environment must be set.");
+ }
+ final EnvironmentContext desc = new EnvironmentContext(env);
+ env.getObjectModel().put(PROCESS_KEY, desc);
+ env.startingProcessing();
+ return desc;
+ }
+
+ /**
+ * Return the environment context
+ */
+ public static EnvironmentContext getCurrentContext() {
+ final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
+ final EnvironmentInfo info = stack.getCurrentInfo();
+ final Map objectModel = info.environment.getObjectModel();
+ return (EnvironmentContext)objectModel.get(PROCESS_KEY);
+ }
+
+ /**
+ * This hook has to be called before a request is processed.
+ * The hook is called by the Cocoon component and by the
+ * cocoon protocol implementation.
+ * @param key A unique key within this thread return by
+ * [EMAIL PROTECTED] #startProcessing(Environment)}.
+ */
+ public static void endProcessing(Environment env, Object key) {
+ env.finishingProcessing();
+ final EnvironmentContext desc = (EnvironmentContext)key;
+ desc.dispose();
+ env.getObjectModel().remove(PROCESS_KEY);
+ }
+
/**
* Return the current processor
*/
public static Processor getCurrentProcessor() {
final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
if ( stack != null && !stack.isEmpty()) {
- final EnvironmentInfo info = stack.getCurrent();
+ final EnvironmentInfo info = stack.getCurrentInfo();
return info.processor;
}
return null;
}
/**
+ * Return the processor that is actually processing the request
+ */
+ public static Processor getLastProcessor(Environment env) {
+ // FIXME - Put it somewhere else
+ return (Processor)env.getAttribute("EnvironmentHelper.processor");
+ }
+
+ /**
* Create an environment aware xml consumer for the cocoon
* protocol
*/
public static XMLConsumer createEnvironmentAwareConsumer(XMLConsumer
consumer) {
final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- final EnvironmentInfo info = stack.getCurrent();
+ final EnvironmentInfo info = stack.getCurrentInfo();
return stack.getEnvironmentAwareConsumerWrapper(consumer,
info.oldStackCount);
}
}
1.21 +15 -233
cocoon-2.2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
Index: AbstractEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- AbstractEnvironment.java 27 Oct 2003 07:57:26 -0000 1.20
+++ AbstractEnvironment.java 29 Oct 2003 18:58:06 -0000 1.21
@@ -50,20 +50,13 @@
*/
package org.apache.cocoon.environment;
-import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
-import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.components.CocoonComponentManager;
-import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.util.BufferedOutputStream;
import org.apache.commons.collections.iterators.IteratorEnumeration;
@@ -82,34 +75,18 @@
/** The current uri in progress */
protected String uris;
- /** The current prefix to strip off from the request uri - TODO (CZ)
Remove this*/
- protected StringBuffer prefix = new StringBuffer();
-
+ /** The prefix */
+ protected String prefix;
+
/** The View requested */
protected String view;
/** The Action requested */
protected String action;
- /** The Context path - TODO (CZ) Remove this*/
- protected String context;
-
- /** The context path stored temporarily between constructor and
initComponents
- * - TODO (CZ) Remove this*/
- private String tempInitContext;
-
- /** The root context path - TODO (CZ) Remove this*/
- protected String rootContext;
-
- /** The servlet object model */
+ /** The object model */
protected HashMap objectModel;
- /** The real source resolver - TODO (CZ) Remove this*/
- protected org.apache.excalibur.source.SourceResolver sourceResolver;
-
- /** The service manager - TODO (CZ) Remove this */
- protected ServiceManager manager;
-
/** The attributes */
private Map attributes = new HashMap();
@@ -119,33 +96,19 @@
/** The real output stream */
protected OutputStream outputStream;
- /** Do we have our components ? - TODO (CZ) Remove this */
- protected boolean initializedComponents = false;
-
/**
* Constructs the abstract environment
*/
- public AbstractEnvironment(String uri, String view, File file)
- throws MalformedURLException {
- this(uri, view, file, null);
+ public AbstractEnvironment(String uri, String view) {
+ this(uri, view, null);
}
/**
* Constructs the abstract environment
*/
- public AbstractEnvironment(String uri, String view, File file, String
action)
- throws MalformedURLException {
- this(uri, view, file.toURL().toExternalForm(), action);
- }
-
- /**
- * Constructs the abstract environment
- */
- public AbstractEnvironment(String uri, String view, String context,
String action)
- throws MalformedURLException {
+ public AbstractEnvironment(String uri, String view, String action) {
this.uris = uri;
this.view = view;
- this.tempInitContext = context;
this.action = action;
this.objectModel = new HashMap();
}
@@ -160,155 +123,18 @@
}
/* (non-Javadoc)
- * @see
org.apache.cocoon.environment.Environment#setURI(java.lang.String)
- */
- public void setURI(String value) {
- this.uris = value;
- }
-
- /**
- * Get the Root Context
- * TODO (CZ) Remove this method
- */
- public String getRootContext() {
- if ( !this.initializedComponents) {
- this.initComponents();
- }
- return this.rootContext;
- }
-
- /**
- * Get the current Context
- * TODO (CZ) Remove this method
- */
- public String getContext() {
- if ( !this.initializedComponents) {
- this.initComponents();
- }
- return this.context;
- }
-
- /**
- * Get the prefix of the URI in progress
- * TODO (CZ) Remove this method
+ * @see org.apache.cocoon.environment.Environment#getURIPrefix()
*/
public String getURIPrefix() {
- return this.prefix.toString();
- }
-
- /**
- * Set the prefix of the URI in progress
- * TODO (CZ) Remove this method
- */
- protected void setURIPrefix(String prefix) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Set the URI Prefix (OLD=" + getURIPrefix() +
", NEW=" + prefix + ")");
- }
- this.prefix = new StringBuffer(prefix);
- }
-
- /**
- * Set the context.
- * TODO (CZ) Remove this method
- */
- protected void setContext(String context) {
- this.context = context;
+ return this.prefix;
}
- /**
- * Set the context. This is similar to changeContext()
- * except that it is absolute.
- * TODO (CZ) Remove this method
- */
- public void setContext(String prefix, String uri, String context) {
- this.setContext(context);
- this.setURIPrefix(prefix == null ? "" : prefix);
- this.uris = uri;
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Reset context to " + this.context);
- }
- }
-
- /**
- * Adds an prefix to the overall stripped off prefix from the request uri
- * TODO (CZ) Remove this method
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Environment#setURI(java.lang.String)
*/
- public void changeContext(String prefix, String newContext)
- throws IOException {
- if ( !this.initializedComponents) {
- this.initComponents();
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Changing Cocoon context");
- getLogger().debug(" from context(" + this.context + ") and
prefix(" + this.prefix + ")");
- getLogger().debug(" to context(" + newContext + ") and prefix("
+ prefix + ")");
- getLogger().debug(" at URI " + this.uris);
- }
- int l = prefix.length();
- if (l >= 1) {
- if (!this.uris.startsWith(prefix)) {
- String message = "The current URI (" + this.uris +
- ") doesn't start with given prefix (" +
prefix + ")";
- getLogger().error(message);
- throw new RuntimeException(message);
- }
- this.prefix.append(prefix);
- this.uris = this.uris.substring(l);
-
- // check for a slash at the beginning to avoid problems with
subsitemaps
- if (this.uris.startsWith("/")) {
- this.uris = this.uris.substring(1);
- this.prefix.append('/');
- }
- }
-
- if (SourceUtil.getScheme(this.context).equals("zip")) {
- // if the resource is zipped into a war file (e.g. Weblogic temp
deployment)
- // FIXME (VG): Is this still required? Better to unify both
cases.
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Base context is zip: " + this.context);
- }
-
- org.apache.excalibur.source.Source source = null;
- try {
- source = this.sourceResolver.resolveURI(this.context +
newContext);
- this.context = source.getURI();
- } finally {
- this.sourceResolver.release(source);
- }
- } else {
- String sContext;
- // if we got a absolute context or one with a protocol resolve it
- if (newContext.charAt(0) == '/') {
- // context starts with the '/' - absolute file URL
- sContext = "file:" + newContext;
- } else if (newContext.indexOf(':') > 1) {
- // context have ':' - absolute URL
- sContext = newContext;
- } else {
- // context is relative to old one
- sContext = this.context + '/' + newContext;
- }
-
- // Cut the file name part from context (if present)
- int i = sContext.lastIndexOf('/');
- if (i != -1 && i + 1 < sContext.length()) {
- sContext = sContext.substring(0, i + 1);
- }
-
- org.apache.excalibur.source.Source source = null;
- try {
- source = this.sourceResolver.resolveURI(sContext);
- this.context = source.getURI();
- } finally {
- this.sourceResolver.release(source);
- }
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("New context is " + this.context);
- }
+ public void setURI(String prefix, String value) {
+ this.prefix = prefix;
+ this.uris = value;
}
/**
@@ -320,8 +146,6 @@
redirect(sessionmode, newURL);
}
- // Request methods
-
/**
* Returns the request view
*/
@@ -336,16 +160,12 @@
return this.action;
}
- // Response methods
-
/**
* Set a status code
*/
public void setStatus(int statusCode) {
}
- // Object model method
-
/**
* Returns a Map containing environment specific objects
*/
@@ -439,37 +259,6 @@
}
/**
- * Initialize the components for the environment
- * This gets the source resolver and the xmlizer component
- * TODO (CZ) Remove this method
- */
- protected void initComponents() {
- this.initializedComponents = true;
- try {
- this.manager =
CocoonComponentManager.getSitemapComponentManager();
- this.sourceResolver =
(org.apache.excalibur.source.SourceResolver)this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
- if (this.tempInitContext != null) {
- org.apache.excalibur.source.Source source = null;
- try {
- source =
this.sourceResolver.resolveURI(this.tempInitContext);
- this.context = source.getURI();
-
- if (this.rootContext == null) // hack for
EnvironmentWrapper
- this.rootContext = this.context;
- } finally {
- this.sourceResolver.release(source);
- }
- this.tempInitContext = null;
- }
- } catch (ServiceException ce) {
- // this should never happen!
- throw new CascadingRuntimeException("Unable to lookup
component.", ce);
- } catch (IOException ie) {
- throw new CascadingRuntimeException("Unable to resolve URI:
"+this.tempInitContext, ie);
- }
- }
-
- /**
* Notify that the processing starts.
*/
public void startingProcessing() {
@@ -481,12 +270,5 @@
* This can be used to cleanup the environment object
*/
public void finishingProcessing() {
- // TODO (CZ) Remove this
- if ( null != this.manager ) {
- this.manager.release( this.sourceResolver );
- this.manager = null;
- this.sourceResolver = null;
- }
- this.initializedComponents = false;
}
}
1.9 +6 -27
cocoon-2.2/src/java/org/apache/cocoon/environment/Environment.java
Index: Environment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/Environment.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Environment.java 27 Oct 2003 07:57:26 -0000 1.8
+++ Environment.java 29 Oct 2003 18:58:06 -0000 1.9
@@ -71,25 +71,15 @@
String getURI();
/**
- * Set the URI to process.
- */
- void setURI(String value);
-
- /**
- * Get the prefix of the URI in progress - TODO(CZ) - Remove this
+ * Get the URI prefix
*/
String getURIPrefix();
-
- /**
- * Get the Root Context - TODO(CZ) - Remove this
- */
- String getRootContext();
-
+
/**
- * Get current context - TODO(CZ) - Remove this
+ * Set the URI and the prefix to process.
*/
- String getContext();
-
+ void setURI(String prefix, String value);
+
/**
* Get the view to process
*/
@@ -99,17 +89,6 @@
* Get the action to process
*/
String getAction();
-
- /**
- * Set the context. This is similar to changeContext()
- * except that it is absolute. - TODO(CZ) - Remove this
- */
- void setContext(String prefix, String uri, String context);
-
- /**
- * Change the context from uriprefix to context - TODO(CZ) - Remove this
- */
- void changeContext(String uriprefix, String context) throws Exception;
/**
* Redirect to the given URL
1.3 +14 -14
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentStack.java
Index: EnvironmentStack.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentStack.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EnvironmentStack.java 24 Oct 2003 12:49:40 -0000 1.2
+++ EnvironmentStack.java 29 Oct 2003 18:58:06 -0000 1.3
@@ -50,7 +50,6 @@
*/
package org.apache.cocoon.environment;
-import org.apache.cocoon.Processor;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.commons.collections.ArrayStack;
import org.xml.sax.Attributes;
@@ -71,10 +70,22 @@
int offset;
- EnvironmentInfo getCurrent() {
+ EnvironmentInfo getCurrentInfo() {
return (EnvironmentInfo)this.get(offset);
}
+ void pushInfo(EnvironmentInfo info) {
+ this.push(info);
+ }
+
+ EnvironmentInfo popInfo() {
+ return (EnvironmentInfo)this.pop();
+ }
+
+ EnvironmentInfo peekInfo() {
+ return (EnvironmentInfo)this.peek();
+ }
+
int getOffset() {
return this.offset;
}
@@ -92,17 +103,6 @@
XMLConsumer getEnvironmentAwareConsumerWrapper(XMLConsumer consumer,
int oldOffset) {
return new EnvironmentChanger(consumer, this, oldOffset,
this.offset);
- }
-}
-
-final class EnvironmentInfo {
-
- public final Processor processor;
- public final int oldStackCount;
-
- public EnvironmentInfo(Processor processor, int oldStackCount) {
- this.processor = processor;
- this.oldStackCount = oldStackCount;
}
}
1.1
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentContext.java
Index: EnvironmentContext.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.environment;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.container.ContainerUtil;
/**
* Experimental code for cleaning up the environment handling
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id: EnvironmentContext.java,v 1.1 2003/10/29 18:58:06
cziegeler Exp $
* @since 2.2
*/
public class EnvironmentContext
implements Disposable {
protected Environment environment;
protected Map attributes;
public EnvironmentContext(Environment environment) {
this.attributes = new HashMap();
this.environment = environment;
}
public Environment getEnvironment() {
return this.environment;
}
public void addAttribute(String key, Object value) {
this.attributes.put(key, value);
}
public Object getAttribute(String key) {
return this.attributes.get(key);
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
final Iterator iter = this.attributes.values().iterator();
while ( iter.hasNext() ) {
final Object o = iter.next();
ContainerUtil.dispose(o);
}
this.attributes.clear();
}
}
1.1
cocoon-2.2/src/java/org/apache/cocoon/environment/EnvironmentInfo.java
Index: EnvironmentInfo.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.environment;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.Processor;
/**
* Experimental code for cleaning up the environment handling
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id: EnvironmentInfo.java,v 1.1 2003/10/29 18:58:06 cziegeler
Exp $
* @since 2.2
*/
public class EnvironmentInfo {
public final Processor processor;
public final int oldStackCount;
//public final ServiceManager manager;
public final Environment environment;
public EnvironmentInfo(Processor processor,
int oldStackCount,
ServiceManager manager,
Environment environment) {
this.processor = processor;
this.oldStackCount = oldStackCount;
// this.manager = manager;
this.environment = environment;
}
}
1.13 +19 -50
cocoon-2.2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
Index: EnvironmentWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- EnvironmentWrapper.java 19 Oct 2003 16:21:28 -0000 1.12
+++ EnvironmentWrapper.java 29 Oct 2003 18:58:06 -0000 1.13
@@ -92,14 +92,11 @@
/** The request object */
protected Request request;
- /** The last context */
- protected String lastContext;
-
- /** The last prefix */
- protected String lastPrefix;
-
/** The last uri */
protected String lastURI;
+
+ /** The last prefix */
+ protected String lastPrefix;
/** The stream to output to */
protected OutputStream outputStream;
@@ -155,7 +152,7 @@
boolean rawMode,
String view)
throws MalformedURLException {
- super(env.getURI(), view, env.getContext(), env.getAction());
+ super(env.getURI(), view, env.getAction());
init(env, requestURI, queryString, logger, manager, rawMode, view);
}
@@ -166,16 +163,12 @@
ServiceManager manager,
boolean rawMode,
String view)
- throws MalformedURLException {
-// super(env.getURI(), view, env.getContext(), env.getAction());
- this.rootContext = env.getRootContext();
+ throws MalformedURLException {
this.enableLogging(logger);
this.environment = env;
this.view = view;
- this.prefix = new StringBuffer(env.getURIPrefix());
-
// create new object model and replace the request object
Map oldObjectModel = env.getObjectModel();
if (oldObjectModel instanceof HashMap) {
@@ -198,7 +191,7 @@
}
public EnvironmentWrapper(Environment env, ServiceManager manager,
String uri, Logger logger) throws MalformedURLException {
- super(env.getURI(), env.getView(), env.getContext(),
env.getAction());
+ super(env.getURI(), env.getView(), env.getAction());
// FIXME(SW): code stolen from SitemapSource. Factorize somewhere...
boolean rawMode = false;
@@ -277,7 +270,7 @@
// this.protocol + "://" + requestURI + "?" + queryString;
this.init(env, requestURI, queryString, logger, manager, rawMode,
view);
- this.setURI(prefix, uri);
+ this.setURI((prefix == null ? env.getURIPrefix() : ""), uri);
}
@@ -402,44 +395,12 @@
}
/**
- * Set a new URI for processing. If the prefix is null the
- * new URI is inside the current context.
- * If the prefix is not null the context is changed to the root
- * context and the prefix is set.
- */
- public void setURI(String prefix, String uris) {
- if(getLogger().isDebugEnabled()) {
- getLogger().debug("Setting uri (prefix=" + prefix + ", uris=" +
uris + ")");
- }
- if ( !this.initializedComponents) {
- this.initComponents();
- }
- if (prefix != null) {
- setContext(getRootContext());
- setURIPrefix(prefix);
- }
- this.uris = uris;
- this.lastURI = uris;
- this.lastContext = this.context;
- this.lastPrefix = this.prefix.toString();
- }
-
- public void changeContext(String prefix, String context)
- throws IOException {
- super.changeContext(prefix, context);
- this.lastContext = this.context;
- this.lastPrefix = this.prefix.toString();
- this.lastURI = this.uris;
- }
-
- /**
* Change the current context to the last one set by changeContext()
* and return last processor
*/
public void changeToLastContext() {
- this.setContext(this.lastContext);
- this.setURIPrefix(this.lastPrefix);
this.uris = this.lastURI;
+ this.prefix = this.lastPrefix;
}
/**
@@ -451,8 +412,7 @@
* @return an <code>Object</code>, the value of the attribute or
* null if no such attribute was found.
*/
- public Object getAttribute(String name)
- {
+ public Object getAttribute(String name) {
Object value = super.getAttribute(name);
if (value == null)
value = this.environment.getAttribute(name);
@@ -476,6 +436,15 @@
*/
public boolean isExternal() {
return false;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Environment#setURI(java.lang.String)
+ */
+ public void setURI(String prefix, String value) {
+ super.setURI(prefix, value);
+ this.lastURI = this.uris;
+ this.lastPrefix = this.prefix;
}
}
1.6 +8 -1
cocoon-2.2/src/java/org/apache/cocoon/ProcessorWrapper.java
Index: ProcessorWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/ProcessorWrapper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ProcessorWrapper.java 19 Oct 2003 16:06:32 -0000 1.5
+++ ProcessorWrapper.java 29 Oct 2003 18:58:06 -0000 1.6
@@ -119,4 +119,11 @@
return this.processor.getSourceResolver();
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.Processor#getContext()
+ */
+ public String getContext() {
+ return this.processor.getContext();
+ }
+
}
1.8 +8 -1 cocoon-2.2/src/java/org/apache/cocoon/Processor.java
Index: Processor.java
===================================================================
RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/Processor.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Processor.java 19 Oct 2003 16:06:32 -0000 1.7
+++ Processor.java 29 Oct 2003 18:58:06 -0000 1.8
@@ -108,4 +108,11 @@
* @since 2.2
*/
SourceResolver getSourceResolver();
+
+ /**
+ * Get the context URI for this processor
+ * EXPERIMENTAL
+ * @since 2.2
+ */
+ String getContext();
}
1.27 +12 -9 cocoon-2.2/src/java/org/apache/cocoon/Cocoon.java
Index: Cocoon.java
===================================================================
RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- Cocoon.java 24 Oct 2003 13:00:16 -0000 1.26
+++ Cocoon.java 29 Oct 2003 18:58:06 -0000 1.27
@@ -146,7 +146,7 @@
ContainerUtil.enableLogging(this.environmentHelper, getLogger());
ContainerUtil.service(this.environmentHelper,
this.serviceManager);
} catch (ContextException e) {
- throw new ServiceException("Unable to get context root url from
context.", e);
+ throw new ServiceException("Cocoon", "Unable to get context root
url from context.", e);
}
}
@@ -369,11 +369,8 @@
throw new IllegalStateException("You cannot process a Disposed
Cocoon engine.");
}
-/* Object key = CocoonComponentManager.startProcessing(environment);
- CocoonComponentManager.enterEnvironment(environment,
- this.serviceManager,
- this); */
- EnvironmentHelper.enterProcessor(this);
+// Object key = CocoonComponentManager.startProcessing(environment);
+ EnvironmentHelper.enterProcessor(this, this.serviceManager,
environment);
try {
boolean result;
if (getLogger().isDebugEnabled()) {
@@ -399,14 +396,13 @@
throw any;
} finally {
EnvironmentHelper.leaveProcessor();
-// CocoonComponentManager.leaveEnvironment();
// CocoonComponentManager.endProcessing(environment, key);
if (getLogger().isDebugEnabled()) {
--activeRequestCount;
}
// TODO (CZ): This is only for testing - remove it later on
-// CocoonComponentManager.checkEnvironment(getLogger());
+ EnvironmentHelper.checkEnvironment(getLogger());
}
}
@@ -509,6 +505,13 @@
*/
public org.apache.cocoon.environment.SourceResolver getSourceResolver() {
return this.environmentHelper;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.Processor#getContext()
+ */
+ public String getContext() {
+ return this.environmentHelper.getContext();
}
}
1.20 +4 -6
cocoon-2.2/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java
Index: TreeProcessor.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- TreeProcessor.java 20 Oct 2003 08:15:27 -0000 1.19
+++ TreeProcessor.java 29 Oct 2003 18:58:06 -0000 1.20
@@ -161,8 +161,8 @@
/** The different sitemap component configurations */
protected Map sitemapComponentConfigurations;
- /** The component manager for the sitemap */
- protected ComponentManager sitemapComponentManager;
+ /** The service manager for the sitemap */
+ protected ServiceManager sitemapComponentManager;
/** The source resolver */
protected SourceResolver resolver;
@@ -364,8 +364,7 @@
}
// and now process
- //CocoonComponentManager.enterEnvironment(environment,
this.sitemapComponentManager, this);
- EnvironmentHelper.enterProcessor(this);
+ EnvironmentHelper.enterProcessor(this, this.sitemapComponentManager,
environment);
try {
boolean success = this.rootNode.invoke(environment, context);
@@ -388,7 +387,6 @@
} finally {
EnvironmentHelper.leaveProcessor();
- CocoonComponentManager.leaveEnvironment();
}
}
1.13 +6 -6
cocoon-2.2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java
Index: HttpEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/http/HttpEnvironment.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HttpEnvironment.java 27 Sep 2003 12:59:51 -0000 1.12
+++ HttpEnvironment.java 29 Oct 2003 18:58:06 -0000 1.13
@@ -74,16 +74,16 @@
public static final String HTTP_SERVLET_CONTEXT= "httpservletcontext";
/** The HttpRequest */
- private HttpRequest request = null;
+ private HttpRequest request;
/** The HttpResponse */
- private HttpResponse response = null;
+ private HttpResponse response;
/** The HttpContext */
- private HttpContext webcontext = null;
+ private HttpContext webcontext;
/** Cache content type as there is no getContentType() in reponse object
*/
- private String contentType = null;
+ private String contentType;
/** Did we redirect ? */
private boolean hasRedirected = false;
@@ -101,7 +101,7 @@
String containerEncoding,
String defaultFormEncoding)
throws MalformedURLException, IOException {
- super(uri, req.getParameter(Constants.VIEW_PARAM), root,
extractAction(req));
+ super(uri, req.getParameter(Constants.VIEW_PARAM),
extractAction(req));
this.request = new HttpRequest(req, this);
this.request.setCharacterEncoding(defaultFormEncoding);
1.10 +2 -2
cocoon-2.2/src/java/org/apache/cocoon/transformation/TraxTransformer.java
Index: TraxTransformer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/transformation/TraxTransformer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TraxTransformer.java 28 Oct 2003 20:04:58 -0000 1.9
+++ TraxTransformer.java 29 Oct 2003 18:58:06 -0000 1.10
@@ -568,7 +568,7 @@
this.transformerHandler = null;
this.transformerValidity = null;
this.exceptionDuringSetConsumer = null;
- super.recycle();
+ super.reset();
}
/**
1.6 +2 -5
cocoon-2.2/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
Index: AbstractCommandLineEnvironment.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractCommandLineEnvironment.java 15 Oct 2003 19:25:48 -0000
1.5
+++ AbstractCommandLineEnvironment.java 29 Oct 2003 18:58:06 -0000
1.6
@@ -89,7 +89,7 @@
OutputStream stream,
Logger log)
throws MalformedURLException {
- super(uri, view, context);
+ super(uri, view);
this.enableLogging(log);
this.outputStream = stream;
this.statusCode = 0;
@@ -101,9 +101,6 @@
public void redirect(boolean sessionmode, String newURL)
throws IOException {
- if ( !this.initializedComponents) {
- this.initComponents();
- }
this.hasRedirected = true;
if (sessionmode) {