sylvain 02/02/01 07:14:54 Modified: . changes.xml src/java/org/apache/cocoon/components/source SitemapSource.java src/java/org/apache/cocoon/environment/wrapper EnvironmentWrapper.java Log: Calling getInputStream() on a "cocoon:" source now returns the same output as an external call instead of always using an XML serializer. This also allows to get internally data produced by a Reader. Revision Changes Path 1.93 +6 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.92 retrieving revision 1.93 diff -u -r1.92 -r1.93 --- changes.xml 1 Feb 2002 14:53:46 -0000 1.92 +++ changes.xml 1 Feb 2002 15:14:54 -0000 1.93 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.92 2002/02/01 14:53:46 vgritsenko Exp $ + $Id: changes.xml,v 1.93 2002/02/01 15:14:54 sylvain Exp $ --> <changes title="History of Changes"> @@ -31,6 +31,11 @@ </devs> <release version="@version@" date="@date@"> + <action dev="SW" type="update"> + Calling getInputStream() on a "cocoon:" source now returns the same output + as an external call instead of always using an XML serializer. + This also allows to get internally data produced by a Reader. + </action> <action dev="VG" type="fix"> Fixed memory leaks in XScript engine. Fixed global and session scope variables: now they are shared between XScript pages as it should be. 1.4 +14 -15 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SitemapSource.java 31 Jan 2002 16:44:23 -0000 1.3 +++ SitemapSource.java 1 Feb 2002 15:14:54 -0000 1.4 @@ -39,13 +39,14 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.Map; /** * Description of a source which is defined by a pipeline. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Revision: 1.3 $ $Date: 2002/01/31 16:44:23 $ + * @version CVS $Revision: 1.4 $ $Date: 2002/02/01 15:14:54 $ */ public final class SitemapSource @@ -170,7 +171,8 @@ * Return an <code>InputStream</code> object to read from the source. */ public InputStream getInputStream() - throws ProcessingException, IOException { + throws ProcessingException, IOException { + if (this.needsRefresh) { this.refresh(); } @@ -178,27 +180,24 @@ if (this.exception != null) { throw this.exception; } - ComponentSelector serializerSelector = null; - Serializer serializer = null; + + if (this.redirectSource != null) { + return this.redirectSource.getInputStream(); + } + try { - - serializerSelector = (ComponentSelector) this.manager.lookup(Serializer.ROLE + "Selector"); - serializer = (Serializer)serializerSelector.select("xml"); ByteArrayOutputStream os = new ByteArrayOutputStream(); - serializer.setOutputStream(os); - - this.toSAX(serializer); - + this.environment.setOutputStream(os); + this.pipeline.process(this.environment); return new ByteArrayInputStream(os.toByteArray()); - } catch (ComponentException cme) { - throw new ProcessingException("could not lookup pipeline components", cme); + } catch (ProcessingException e) { throw e; } catch (Exception e) { throw new ProcessingException("Exception during processing of " + this.systemId, e); } finally { - if (serializer != null) serializerSelector.release(serializer); - if (serializerSelector != null) this.manager.release(serializerSelector); + // Unhide wrapped environment output stream + this.environment.setOutputStream(null); reset(); } } 1.4 +15 -2 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- EnvironmentWrapper.java 22 Jan 2002 00:17:13 -0000 1.3 +++ EnvironmentWrapper.java 1 Feb 2002 15:14:54 -0000 1.4 @@ -30,7 +30,7 @@ * contains a <code>RequestWrapper</code> object. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version $Id: EnvironmentWrapper.java,v 1.3 2002/01/22 00:17:13 vgritsenko Exp $ + * @version $Id: EnvironmentWrapper.java,v 1.4 2002/02/01 15:14:54 sylvain Exp $ */ public final class EnvironmentWrapper extends AbstractEnvironment @@ -50,10 +50,15 @@ /** The last context */ private URL lastContext; + /** The last prefix */ private String lastPrefix; + /** The last uri */ private String lastURI; + + /** The stream to output to */ + private OutputStream outputStream; /** * Constructs an EnvironmentWrapper object from a Request @@ -121,7 +126,15 @@ */ public OutputStream getOutputStream() throws IOException { - return this.environment.getOutputStream(); + return (this.outputStream == null) ? this.environment.getOutputStream() : this.outputStream; + } + + /** + * Set the output stream for this environment. It hides the one of the + * wrapped environment. + */ + public void setOutputStream(OutputStream stream) { + this.outputStream = stream; } /**
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]