You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/08/08 04:10:40 UTC
cvs commit: xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper EnvironmentWrapper.java
vgritsenko 2002/08/07 19:10:40
Modified: src/java/org/apache/cocoon/components
CocoonComponentManager.java
src/java/org/apache/cocoon/components/source
CocoonSourceFactory.java SitemapSource.java
src/java/org/apache/cocoon/components/source/impl
CocoonSourceFactory.java SitemapSource.java
SourceFactoryWrapper.java
src/java/org/apache/cocoon/environment
AbstractEnvironment.java
src/java/org/apache/cocoon/environment/wrapper
EnvironmentWrapper.java
Log:
Port recent changes from 203 branch
Revision Changes Path
1.27 +18 -9 xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java
Index: CocoonComponentManager.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- CocoonComponentManager.java 4 Jun 2002 09:27:20 -0000 1.26
+++ CocoonComponentManager.java 8 Aug 2002 02:10:39 -0000 1.27
@@ -73,8 +73,6 @@
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.SourceResolver;
-import org.xml.sax.SAXException;
-
/**
* Cocoon Component Manager.
* This manager extends the <code>ExcaliburComponentManager</code>
@@ -134,7 +132,7 @@
environmentStack.set(new Stack());
}
final Stack stack = (Stack)environmentStack.get();
- if ( !stack.empty() ) {
+ if (!stack.empty()) {
final Object[] objects = (Object[])stack.peek();
if ( objects[1] == objectModel ) {
stack.push(new Object[] {env, objectModel, objects[2], TWO, processor, processor.getComponentConfigurations()});
@@ -149,7 +147,7 @@
*/
public static void leaveEnvironment() {
final Stack stack = (Stack)environmentStack.get();
- if ( null != stack && !stack.empty()) {
+ if (null != stack && !stack.empty()) {
final Object[] objects = (Object[])stack.pop();
if (objects[3] == ONE) {
final Map components = (Map)objects[2];
@@ -179,12 +177,23 @@
}
/**
- * Return the current stack state (for the cocoon: protocol
+ * Return the current environment (for the cocoon: protocol)
+ */
+ public static Environment getCurrentEnvironment() {
+ final Stack stack = (Stack)environmentStack.get();
+ if (null != stack && !stack.empty()) {
+ return (Environment) ((Object[])stack.peek())[0];
+ }
+ return null;
+ }
+
+ /**
+ * Return the current processor (for the cocoon: protocol)
*/
- public static Object[] getCurrentEnvironment() {
+ public static Processor getCurrentProcessor() {
final Stack stack = (Stack)environmentStack.get();
- if ( null != stack && !stack.empty()) {
- return (Object[])stack.peek();
+ if (null != stack && !stack.empty()) {
+ return (Processor) ((Object[])stack.peek())[4];
}
return null;
}
1.6 +2 -9 xml-cocoon2/src/java/org/apache/cocoon/components/source/CocoonSourceFactory.java
Index: CocoonSourceFactory.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/CocoonSourceFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CocoonSourceFactory.java 31 Jul 2002 13:13:25 -0000 1.5
+++ CocoonSourceFactory.java 8 Aug 2002 02:10:39 -0000 1.6
@@ -69,20 +69,15 @@
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id$
*/
-
public final class CocoonSourceFactory
extends AbstractLogEnabled
implements SourceFactory {
- /** The processor */
- private Processor processor;
-
/** The component manager */
private ComponentManager manager;
public CocoonSourceFactory(Processor processor,
ComponentManager manager) {
- this.processor = processor;
this.manager = manager;
}
@@ -93,9 +88,7 @@
throws ProcessingException, IOException, MalformedURLException {
if (environment == null)
throw new ProcessingException("CocoonSourceFactory: environment is required.");
- return new SitemapSource(environment,
- this.manager,
- this.processor,
+ return new SitemapSource(this.manager,
location,
this.getLogger());
}
1.22 +10 -18 xml-cocoon2/src/java/org/apache/cocoon/components/source/SitemapSource.java
Index: SitemapSource.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/SitemapSource.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- SitemapSource.java 31 Jul 2002 13:13:25 -0000 1.21
+++ SitemapSource.java 8 Aug 2002 02:10:39 -0000 1.22
@@ -52,27 +52,20 @@
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.source.SourceException;
-import org.apache.cocoon.Constants;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.Processor;
-import org.apache.cocoon.caching.PipelineCacheKey;
import org.apache.cocoon.components.CocoonComponentManager;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.ModifiableSource;
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.Source;
import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
-import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.xml.AbstractXMLConsumer;
import org.apache.cocoon.xml.ContentHandlerWrapper;
import org.apache.cocoon.xml.XMLConsumer;
-import org.apache.cocoon.xml.XMLProducer;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -82,8 +75,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Map;
+import java.net.MalformedURLException;
/**
* Description of a source which is defined by a pipeline.
@@ -92,7 +84,6 @@
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id$
*/
-
public final class SitemapSource
extends AbstractXMLConsumer
implements ModifiableSource {
@@ -136,13 +127,16 @@
/**
* Construct a new object
*/
- public SitemapSource(Environment env,
- ComponentManager manager,
- Processor sitemap,
+ public SitemapSource(ComponentManager manager,
String uri,
Logger logger)
throws IOException, ProcessingException {
+ Environment env = CocoonComponentManager.getCurrentEnvironment();
+ if ( env == null ) {
+ throw new MalformedURLException("The cocoon protocol can not be used outside an environment.");
+ }
+
this.manager = manager;
this.enableLogging(logger);
boolean rawMode = false;
@@ -160,18 +154,16 @@
// does the uri point to this sitemap or to the root sitemap?
if (uri.startsWith("//", position)) {
position += 2;
- Processor processor = null;
try {
- processor = (Processor)this.manager.lookup(Processor.ROLE);
+ this.processor = (Processor)this.manager.lookup(Processor.ROLE);
} catch (ComponentException e) {
throw new ProcessingException("Cannot get Processor instance", e);
}
this.prefix = ""; // start at the root
- this.processor = processor;
} else if (uri.startsWith("/", position)) {
position ++;
this.prefix = null;
- this.processor = sitemap;
+ this.processor = CocoonComponentManager.getCurrentProcessor();
} else {
throw new ProcessingException("Malformed cocoon URI.");
}
1.3 +5 -16 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonSourceFactory.java
Index: CocoonSourceFactory.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/CocoonSourceFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CocoonSourceFactory.java 31 Jul 2002 13:13:25 -0000 1.2
+++ CocoonSourceFactory.java 8 Aug 2002 02:10:40 -0000 1.3
@@ -62,10 +62,6 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceFactory;
-import org.apache.cocoon.Processor;
-import org.apache.cocoon.components.CocoonComponentManager;
-import org.apache.cocoon.environment.Environment;
-
/**
* This class implements the cocoon: protocol.
* It cannot be configured like the other source factories
@@ -74,7 +70,6 @@
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id$
*/
-
public final class CocoonSourceFactory
extends AbstractLogEnabled
implements SourceFactory, ThreadSafe, Composable
@@ -96,20 +91,14 @@
public Source getSource( String location, Map parameters )
throws MalformedURLException, IOException
{
- if( this.getLogger().isDebugEnabled() )
+ if( getLogger().isDebugEnabled() )
{
- this.getLogger().debug( "Creating source object for " + location );
+ getLogger().debug( "Creating source object for " + location );
}
- Object[] currentEnv = CocoonComponentManager.getCurrentEnvironment();
- if ( currentEnv == null ) {
- throw new MalformedURLException("The cocoon protocol can not be used outside an environment.");
- }
- return new SitemapSource( (Environment)currentEnv[0],
- this.manager,
- (Processor)currentEnv[4],
+ return new SitemapSource( this.manager,
location,
parameters,
- this.getLogger() );
+ getLogger());
}
}
1.17 +9 -18 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
Index: SitemapSource.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SitemapSource.java 31 Jul 2002 13:13:25 -0000 1.16
+++ SitemapSource.java 8 Aug 2002 02:10:40 -0000 1.17
@@ -61,24 +61,16 @@
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.cocoon.Constants;
-import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.Processor;
import org.apache.cocoon.ResourceNotFoundException;
-import org.apache.cocoon.caching.PipelineCacheKey;
import org.apache.cocoon.components.CocoonComponentManager;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.environment.ModifiableSource;
-import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
-import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.xml.AbstractXMLConsumer;
import org.apache.cocoon.xml.ContentHandlerWrapper;
import org.apache.cocoon.xml.XMLConsumer;
-import org.apache.cocoon.xml.XMLProducer;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -88,7 +80,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.Map;
@@ -99,7 +90,6 @@
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Id$
*/
-
public final class SitemapSource
extends AbstractXMLConsumer
implements Source, XMLizable, Recyclable {
@@ -146,14 +136,17 @@
/**
* Construct a new object
*/
- public SitemapSource(Environment env,
- ComponentManager manager,
- Processor sitemap,
+ public SitemapSource(ComponentManager manager,
String uri,
Map parameters,
Logger logger)
throws MalformedURLException {
+ Environment env = CocoonComponentManager.getCurrentEnvironment();
+ if ( env == null ) {
+ throw new MalformedURLException("The cocoon protocol can not be used outside an environment.");
+ }
+
this.manager = manager;
this.enableLogging(logger);
boolean rawMode = false;
@@ -171,18 +164,16 @@
// does the uri point to this sitemap or to the root sitemap?
if (uri.startsWith("//", position)) {
position += 2;
- Processor processor = null;
try {
- processor = (Processor)this.manager.lookup(Processor.ROLE);
+ this.processor = (Processor)this.manager.lookup(Processor.ROLE);
} catch (ComponentException e) {
throw new MalformedURLException("Cannot get Processor instance");
}
this.prefix = ""; // start at the root
- this.processor = processor;
} else if (uri.startsWith("/", position)) {
position ++;
this.prefix = null;
- this.processor = sitemap;
+ this.processor = CocoonComponentManager.getCurrentProcessor();
} else {
throw new MalformedURLException("Malformed cocoon URI.");
}
1.3 +6 -7 xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SourceFactoryWrapper.java
Index: SourceFactoryWrapper.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/impl/SourceFactoryWrapper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SourceFactoryWrapper.java 31 Jul 2002 13:13:25 -0000 1.2
+++ SourceFactoryWrapper.java 8 Aug 2002 02:10:40 -0000 1.3
@@ -162,18 +162,17 @@
public Source getSource( String location, Map parameters )
throws MalformedURLException, IOException
{
- if( this.getLogger().isDebugEnabled() )
+ if( getLogger().isDebugEnabled() )
{
- this.getLogger().debug( "Creating source object for " + location );
+ getLogger().debug( "Creating source object for " + location );
}
- Object[] currentEnv = CocoonComponentManager.getCurrentEnvironment();
+ final Environment currentEnv = CocoonComponentManager.getCurrentEnvironment();
org.apache.cocoon.environment.Source source;
try {
- source = this.sourceFactory.getSource((currentEnv == null ? null : (Environment)currentEnv[0]),
- location);
+ source = this.sourceFactory.getSource(currentEnv, location);
} catch (ProcessingException pe) {
- this.getLogger().error("ProcessingException", pe);
+ getLogger().error("ProcessingException", pe);
throw new IOException("ProcessingException: " + pe.getMessage());
}
return new CocoonToAvalonSource( source );
1.26 +3 -3 xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java
Index: AbstractEnvironment.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/AbstractEnvironment.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- AbstractEnvironment.java 31 Jul 2002 13:13:27 -0000 1.25
+++ AbstractEnvironment.java 8 Aug 2002 02:10:40 -0000 1.26
@@ -117,7 +117,7 @@
protected ComponentManager manager = null;
/**
- * The treeprocessor sets up new managers per sitemap. Get the
+ * The sitemap processor sets up new managers per sitemap. Get the
* "current" one for this environment.
*/
public ComponentManager getComponentManager(){
@@ -125,7 +125,7 @@
}
/**
- * The treeprocessor sets up new managers per sitemap. Set the
+ * The sitemap processor sets up new managers per sitemap. Set the
* "current" one for this environment.
*/
public void setComponentManager(ComponentManager manager){
1.20 +12 -9 xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java
Index: EnvironmentWrapper.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- EnvironmentWrapper.java 31 Jul 2002 13:13:29 -0000 1.19
+++ EnvironmentWrapper.java 8 Aug 2002 02:10:40 -0000 1.20
@@ -191,12 +191,11 @@
*/
public void globalRedirect(boolean sessionmode, String newURL)
throws IOException {
- if (environment instanceof EnvironmentWrapper) {
- ((EnvironmentWrapper)environment).globalRedirect(sessionmode, newURL);
- }
- else {
- environment.redirect(sessionmode,newURL);
- }
+ if (environment instanceof EnvironmentWrapper) {
+ ((EnvironmentWrapper)environment).globalRedirect(sessionmode, newURL);
+ } else {
+ environment.redirect(sessionmode,newURL);
+ }
}
/**
@@ -205,8 +204,12 @@
*/
public void setComponentManager(ComponentManager manager) {
super.setComponentManager( manager );
- this.processor = (Processor)CocoonComponentManager.getCurrentEnvironment()[4];
+ // HACK: As processing enters sitemap, capture current processor.
+ // If pipeline is successfully assembled, this will contain proper processor.
+ // Used by cocoon protocol.
+ this.processor = CocoonComponentManager.getCurrentProcessor();
}
+
/**
* Get the output stream
*/
@@ -298,7 +301,7 @@
/**
* Change the current context to the last one set by changeContext()
- * and return the processor
+ * and return last processor
*/
public Processor changeToLastContext() {
this.setContext(this.lastContext);
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org