cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adrian Petru Dimulescu" <adrian.dimule...@free.fr>
Subject SxwGenerator: ZipInputStream gets closed
Date Tue, 13 May 2003 12:46:14 GMT
Hello, 

I am trying to write an SxwGenerator (for OpenOffice writer). I am using
the CVS cocoon 2.1 as of may 10th.

The idea is that all xml content in the sxw zip file is grouped under an
<office:document> 
element.

I use a ZipInputStream to look into the zip archive, locate an ".xml"
entry and parse it.
Unfortunately, it looks like the parser (or something else?) closes the
ZipInputStream after it
has finished its parsing.

Which is not cool, as I have to parse several Zip entries (content,
style, etc.), not only the first entry.

As I don't need the StartDocument and EndDocument for each XML entry, i
filter them out using a little class at the
end of the code listing: StartEndEventFilter.

The exception I get is: org.apache.cocoon.ProcessingException: Failed to
execute pipeline.: java.io.IOException: Stream closed
The whole exception backtrace is at the end of this message.

Here is my Java file, thank you for your ideas!

/*
 * Created on 12 mai 2003
 *
 */
package org.apache.cocoon.generation;

import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.avalon.framework.component.ComponentException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.xml.ContentHandlerWrapper;
import org.apache.excalibur.xml.sax.SAXParser;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

/**
 * Generates Sax events using an OpenOffice Writer .sxw file as source.
 * <br/>
 * It uses &lt;office:document> as root and pastes in all XML content
that can
 * be found inside the .sxw zip archive.
 * 
 * @author Adrian Petru Dimulescu
 */
public class SxwGenerator extends FileGenerator {

	/* (non-Javadoc)
	 * @see org.apache.cocoon.generation.Generator#generate()
	 */
	public void generate()
		throws IOException, SAXException, ProcessingException 
	{
		this.xmlConsumer.startDocument();
		this.xmlConsumer.startElement(
			"http://openoffice.org/2000/office",
			"document",
			"office:document",
			new AttributesImpl());

		try {
			ZipInputStream zin =
				new
ZipInputStream(this.inputSource.getInputStream());
			ZipEntry entry;
			StartEndEventFilter startEndFilter = new
StartEndEventFilter(this.xmlConsumer);
			SAXParser parser;
			parser = (SAXParser)
this.manager.lookup(SAXParser.ROLE);
		
			while ((entry = zin.getNextEntry()) != null) {
				if (entry.getName().endsWith(".xml")) {
					InputSource iSrc = new
InputSource(zin);
					parser.parse(iSrc,
startEndFilter);
				}
			}
		} catch (ComponentException e) {
			getLogger().error("Could not get parser", e);
			throw new ProcessingException(
				"Exception in "
					+ this.getClass().getName()
					+ ".generate()",
				e);
		} finally {
			this.xmlConsumer.endElement(
				"http://openoffice.org/2000/office",
				"document",
				"office:document");
			this.xmlConsumer.endDocument();
		}
	}

}

/**
 *
 * Filter out StartDocument and EndDocument events. 
 * @author Adrian Petru Dimulescu
 *
 */
class StartEndEventFilter extends ContentHandlerWrapper {
	StartEndEventFilter(ContentHandler document) {
		super(document);
	}
	
	
	/* (non-Javadoc)
	 * @see org.xml.sax.ContentHandler#endDocument()
	 */
	public void endDocument() throws SAXException {
		// Filter out endDocument()
	}

	/* (non-Javadoc)
	 * @see org.xml.sax.ContentHandler#startDocument()
	 */
	public void startDocument() throws SAXException {
		// Filter out startDocument()
	}

}



Here is the backtrace:


Original Exception: java.io.IOException: Stream closed

	at
java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:43)

	at
java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:67)

	at
org.apache.cocoon.generation.SxwGenerator.generate(SxwGenerator.java:51)

	at
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipe
line.processXMLPipeline(AbstractCachingProcessingPipeline.java:292)

	at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process
(AbstractProcessingPipeline.java:489)

	at
org.apache.cocoon.components.treeprocessor.sitemap.SerializeNode.invoke(
SerializeNode.java:150)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:84)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i
nvoke(PreparableMatchNode.java:164)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:108)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P
ipelineNode.java:162)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:108)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(
PipelinesNode.java:162)

	at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:325)

	at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:307)

	at
org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(Moun
tNode.java:133)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:84)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i
nvoke(PreparableMatchNode.java:164)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:108)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P
ipelineNode.java:162)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:108)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(
PipelinesNode.java:162)

	at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:325)

	at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:307)

	at
org.apache.cocoon.components.treeprocessor.sitemap.MountNode.invoke(Moun
tNode.java:133)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:84)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PreparableMatchNode.i
nvoke(PreparableMatchNode.java:164)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:108)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(P
ipelineNode.java:162)

	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.
invokeNodes(AbstractParentProcessingNode.java:108)

	at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(
PipelinesNode.java:162)

	at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:325)

	at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreePro
cessor.java:307)

	at org.apache.cocoon.Cocoon.process(Cocoon.java:640)

	at
org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1139)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

	at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)

	at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationH
andler.java:280)

	at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)

	at org.mortbay.http.HttpContext.handle(HttpContext.java:1717)

	at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationCon
text.java:549)

	at org.mortbay.http.HttpContext.handle(HttpContext.java:1667)

	at org.mortbay.http.HttpServer.service(HttpServer.java:863)

	at
org.mortbay.http.HttpConnection.service(HttpConnection.java:773)

	at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:937)

	at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:790)

	at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201
)

	at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)

	at
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)



Mime
View raw message