You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by bu...@apache.org on 2004/10/19 09:38:47 UTC
DO NOT REPLY [Bug 31767] New: -
SXWGenerator (for OpenOffice.org writer documents)
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=31767>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=31767
SXWGenerator (for OpenOffice.org writer documents)
Summary: SXWGenerator (for OpenOffice.org writer documents)
Product: Cocoon 2
Version: Current CVS 2.2
Platform: Other
URL: http://http://wiki.apache.org/cocoon/XfolioOpenOfficeGen
eration
OS/Version: Other
Status: NEW
Severity: Normal
Priority: Other
Component: core
AssignedTo: dev@cocoon.apache.org
ReportedBy: frederic.glorieux@xfolio.org
Forrest and Lenya are using OpenOffice.org Writer text documents as sources, in
2 different ways. The issue is explained here
<http://wiki.apache.org/cocoon/XfolioOpenOfficeGeneration>
A default generator in Cocoon may be a good idea. The code below worked in a
cocoon app on hundreds of sxw docs. Last source available here
<http://cvs.berlios.de/cgi-bin/viewcvs.cgi/xfolio/webapp/WEB-INF/classes/org/apache/cocoon/generation/SXWGenerator.java>
package org.apache.cocoon.generation;
import java.io.IOException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class SXWGenerator extends FileGenerator implements
CacheableProcessingComponent {
/**
* Generate XML data.
*
* if catalog resolution is not properly set, you may have the exception
* java.io.FileNotFoundException:...\{yourFile}.sxw\office.dtd
* (The system cannot find the path specified)
*/
public void generate() throws IOException, SAXException, ProcessingException {
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Source " + super.source + " resolved to " +
this.inputSource.getURI());
}
this.contentHandler.startDocument();
// prefixMapping is perhaps not useful in this case
// this.contentHandler.startPrefixMapping("office",
"http://openoffice.org/2000/office");
//...
super.contentHandler.startElement("http://openoffice.org/2000/office",
"document", "office" + ':' + "document", new AttributesImpl());
// from org.apache.cocoon.transformation.XIncludeTransformer
SourceUtil.toSAX(super.resolver.resolveURI("zip://meta.xml@" +
this.inputSource.getURI()),
new IncludeXMLConsumer(this.contentHandler));
// useful to get size of page from which calculate relative width of
an image
SourceUtil.toSAX(super.resolver.resolveURI("zip://styles.xml@" +
this.inputSource.getURI()),
new IncludeXMLConsumer(this.contentHandler));
SourceUtil.toSAX(super.resolver.resolveURI("zip://content.xml@" +
this.inputSource.getURI()),
new IncludeXMLConsumer(this.contentHandler));
super.contentHandler.endElement("http://openoffice.org/2000/office",
"document", "office" + ':' + "document");
this.contentHandler.endDocument();
} catch (SAXException e) {
SourceUtil.handleSAXException(this.inputSource.getURI(), e);
}
}
}
Apache Cocoon is free to commit this code, licence issues have been solved from
our side, except we would be glad to make appear somewhere the mention of
author, company, and project
Frédéric Glorieux (AJLSM <http://ajlsm.com/> for Strabon <http://strabon.org>)
In hope this helps.