cziegeler 2002/11/20 06:23:34
Modified: src/java/org/apache/cocoon/components/source/impl
SitemapSource.java
src/java/org/apache/cocoon/components
CocoonComponentManager.java
lib jars.xml
Added: lib/core commons-collections-2.1.jar
Removed: lib/core commons-collections-1.0.jar
Log:
Removing the intermediate buffering for the cocoon protocol
Revision Changes Path
1.24 +156 -16
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- SitemapSource.java 20 Nov 2002 09:57:21 -0000 1.23
+++ SitemapSource.java 20 Nov 2002 14:23:33 -0000 1.24
@@ -65,16 +65,17 @@
import org.apache.cocoon.Processor;
import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.components.CocoonComponentManager;
+import org.apache.cocoon.components.EnvironmentStack;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
-import org.apache.cocoon.components.sax.XMLDeserializer;
-import org.apache.cocoon.components.sax.XMLSerializer;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
import org.apache.cocoon.xml.AbstractXMLConsumer;
import org.apache.cocoon.xml.ContentHandlerWrapper;
import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
@@ -370,26 +371,18 @@
} else {
consumer = new ContentHandlerWrapper(contentHandler);
}
- // We have to buffer the result in order to get
+ // We have to add an environment changer
// clean environment stack handling.
- XMLSerializer xmls = (XMLSerializer)
this.manager.lookup(XMLSerializer.ROLE);
- Object fragment;
+ EnvironmentStack envStack =
CocoonComponentManager.getCurrentEnvironmentStack();
+ int currentOffset = envStack.getOffset();
try {
CocoonComponentManager.enterEnvironment(this.environment,
this.environment.getObjectModel(),
this.pipelineProcessor);
- this.processingPipeline.process(this.environment, xmls);
- fragment = xmls.getSAXFragment();
+ this.processingPipeline.process(this.environment, new
EnvironmentChanger(consumer, envStack));
} finally {
- this.manager.release(xmls);
CocoonComponentManager.leaveEnvironment();
- }
- XMLDeserializer xmld = (XMLDeserializer)
this.manager.lookup(XMLDeserializer.ROLE);
- try {
- xmld.setConsumer(consumer);
- xmld.deserialize(fragment);
- } finally {
- this.manager.release(xmld);
+ envStack.resetOffset(currentOffset);
}
}
} catch (SAXException e) {
@@ -452,5 +445,152 @@
}
+}
+
+
+/**
+ * This class is an {@link XMLConsumer} that changes the current environment.
+ * When a pipeline calls an internal pipeline, two environments are
+ * established: one for the calling pipeline and one for the internal pipeline.
+ * Now, if SAX events are send from the internal pipeline, they are
+ * received by some component of the calling pipeline, so inbetween we
+ * have to change the environment forth and back.
+ */
+final class EnvironmentChanger
+implements XMLConsumer {
+
+ final XMLConsumer consumer;
+ final EnvironmentStack stack;
+
+ EnvironmentChanger(XMLConsumer consumer, EnvironmentStack es) {
+ this.consumer = consumer;
+ this.stack = es;
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ this.stack.incOffset();
+ this.consumer.setDocumentLocator(locator);
+ this.stack.decOffset();
+ }
+
+ public void startDocument()
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.startDocument();
+ this.stack.decOffset();
+ }
+
+ public void endDocument()
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.endDocument();
+ this.stack.decOffset();
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.startPrefixMapping(prefix, uri);
+ this.stack.decOffset();
+ }
+
+ public void endPrefixMapping(String prefix)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.endPrefixMapping(prefix);
+ this.stack.decOffset();
+ }
+
+ public void startElement(String uri, String loc, String raw, Attributes a)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.startElement(uri, loc, raw, a);
+ this.stack.decOffset();
+ }
+
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.endElement(uri, loc, raw);
+ this.stack.decOffset();
+ }
+
+ public void characters(char c[], int start, int len)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.characters(c, start, len);
+ this.stack.decOffset();
+ }
+
+ public void ignorableWhitespace(char c[], int start, int len)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.ignorableWhitespace(c, start, len);
+ this.stack.decOffset();
+ }
+
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.processingInstruction(target, data);
+ this.stack.decOffset();
+ }
+
+ public void skippedEntity(String name)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.skippedEntity(name);
+ this.stack.decOffset();
+ }
+
+ public void startDTD(String name, String publicId, String systemId)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.startDTD(name, publicId, systemId);
+ this.stack.decOffset();
+ }
+
+ public void endDTD()
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.endDTD();
+ this.stack.decOffset();
+ }
+
+ public void startEntity(String name)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.startEntity(name);
+ this.stack.decOffset();
+ }
+
+ public void endEntity(String name)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.endEntity(name);
+ this.stack.decOffset();
+ }
+
+ public void startCDATA()
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.startCDATA();
+ this.stack.decOffset();
+ }
+
+ public void endCDATA()
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.endCDATA();
+ this.stack.decOffset();
+ }
+
+ public void comment(char ch[], int start, int len)
+ throws SAXException {
+ this.stack.incOffset();
+ this.consumer.comment(ch, start, len);
+ this.stack.decOffset();
+ }
}
1.1 xml-cocoon2/lib/core/commons-collections-2.1.jar
<<Binary file>>
1.40 +29 -20
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.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- CocoonComponentManager.java 20 Nov 2002 10:08:24 -0000 1.39
+++ CocoonComponentManager.java 20 Nov 2002 14:23:34 -0000 1.40
@@ -56,7 +56,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Stack;
import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
import org.apache.avalon.excalibur.component.RoleManager;
import org.apache.avalon.framework.component.Component;
@@ -69,6 +68,7 @@
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.Processor;
import org.apache.cocoon.environment.Environment;
+
import java.net.MalformedURLException;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
@@ -133,9 +133,9 @@
Map objectModel,
Processor processor) {
if (environmentStack.get() == null) {
- environmentStack.set(new Stack());
+ environmentStack.set(new EnvironmentStack());
}
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
stack.push(new Object[] {env, processor});
EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
@@ -148,7 +148,7 @@
* This hook must be called by the sitemap each time a sitemap is left
*/
public static void leaveEnvironment() {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (null != stack && !stack.empty()) {
final Object[] objects = (Object[])stack.pop();
EnvironmentDescription desc =
(EnvironmentDescription)((Environment)objects[0]).getObjectModel().get(PROCESS_KEY);
@@ -186,9 +186,9 @@
* Return the current environment (for the cocoon: protocol)
*/
public static Environment getCurrentEnvironment() {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (null != stack && !stack.empty()) {
- return (Environment) ((Object[])stack.peek())[0];
+ return (Environment) ((Object[])stack.getCurrent())[0];
}
return null;
}
@@ -197,14 +197,21 @@
* Return the current processor (for the cocoon: protocol)
*/
public static Processor getCurrentProcessor() {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if (null != stack && !stack.empty()) {
- return (Processor) ((Object[])stack.peek())[1];
+ return (Processor) ((Object[])stack.getCurrent())[1];
}
return null;
}
/**
+ * Return the current environment stack (for the cocoon: protocol)
+ */
+ public static EnvironmentStack getCurrentEnvironmentStack() {
+ return (EnvironmentStack)environmentStack.get();
+ }
+
+ /**
* Configure the RoleManager
*/
public void setRoleManager( final RoleManager roles ) {
@@ -226,9 +233,9 @@
return this;
}
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.peek();
+ final Object[] objects = (Object[])stack.getCurrent();
final Map objectModel = ((Environment)objects[0]).getObjectModel();
EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
@@ -244,7 +251,7 @@
if (stack == null || stack.empty()) {
throw new ComponentException("ComponentManager has no Environment
Stack.");
}
- final Object[] objects = (Object[]) stack.peek();
+ final Object[] objects = (Object[]) stack.getCurrent();
final Map objectModel = ((Environment)objects[0]).getObjectModel();
EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
@@ -315,9 +322,9 @@
final Component
component,
final ComponentManager
manager)
throws ProcessingException {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.firstElement();
+ final Object[] objects = (Object[])stack.get(0);
final Map objectModel = ((Environment)objects[0]).getObjectModel();
EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
@@ -334,9 +341,9 @@
public static void addComponentForAutomaticRelease(final ComponentManager
manager,
final Component
component)
throws ProcessingException {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.firstElement();
+ final Object[] objects = (Object[])stack.get(0);
final Map objectModel = ((Environment)objects[0]).getObjectModel();
EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
@@ -352,9 +359,9 @@
*/
public static void removeFromAutomaticRelease(final Component component)
throws ProcessingException {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.firstElement();
+ final Object[] objects = (Object[])stack.get(0);
final Map objectModel = ((Environment)objects[0]).getObjectModel();
EnvironmentDescription desc =
(EnvironmentDescription)objectModel.get(PROCESS_KEY);
if ( null != desc ) {
@@ -392,9 +399,9 @@
final Map parameters)
throws MalformedURLException, IOException, SourceException {
if (baseURI == null) {
- final Stack stack = (Stack)environmentStack.get();
+ final EnvironmentStack stack = (EnvironmentStack)environmentStack.get();
if ( null != stack && !stack.empty()) {
- final Object[] objects = (Object[])stack.peek();
+ final Object[] objects = (Object[])stack.getCurrent();
baseURI = ((Environment)objects[0]).getContext().toExternalForm();
}
}
@@ -541,3 +548,5 @@
this.sitemapConfigurations.remove(this.sitemapConfigurations.size()-1);
}
}
+
+
1.50 +1 -1 xml-cocoon2/lib/jars.xml
Index: jars.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/lib/jars.xml,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- jars.xml 20 Nov 2002 12:18:32 -0000 1.49
+++ jars.xml 20 Nov 2002 14:23:34 -0000 1.50
@@ -189,7 +189,7 @@
<title>Jakarta Commons Collections</title>
<description>Common implementations of collection classes.</description>
<used-by>Cocoon</used-by>
- <lib>core/commons-collections-1.0.jar</lib>
+ <lib>core/commons-collections-2.1.jar</lib>
<homepage>http://jakarta.apache.org/commons/collections.html</homepage>
</file>
<file>
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]