cziegeler 2003/03/05 05:47:32
Modified: src/java/org/apache/cocoon/transformation CIncludeTransformer.java Log: Fixing parallel processing bug Revision Changes Path 1.29 +56 -13 xml-cocoon2/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java Index: CIncludeTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/CIncludeTransformer.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- CIncludeTransformer.java 5 Mar 2003 11:17:58 -0000 1.28 +++ CIncludeTransformer.java 5 Mar 2003 13:47:32 -0000 1.29 @@ -65,6 +65,7 @@ import org.apache.cocoon.transformation.helpers.IncludeCacheManager; import org.apache.cocoon.transformation.helpers.IncludeCacheManagerSession; import org.apache.cocoon.xml.IncludeXMLConsumer; +import org.apache.cocoon.xml.XMLConsumer; import org.apache.cocoon.xml.XMLUtils; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; @@ -338,17 +339,13 @@ null, this.cacheManager != null); if (this.compiling) { - this.srcAttributes.addAttribute("", "src", "src", "CDATA", src); + this.srcAttributes.addAttribute("", CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE, CINCLUDE_SRC_ELEMENT, "CDATA", src); super.startTransformingElement(uri, CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT, raw+"p", this.srcAttributes); this.srcAttributes.clear(); } - } else if (name.equals(CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) { - // this is a placeholder - final String src = attr.getValue("",CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE); - this.cacheManager.stream(src, this.cachingSession, this.filter); } else { super.startTransformingElement(uri, name, raw, attr); } @@ -464,8 +461,6 @@ raw+"p"); } // do nothing else - } else if (name.equals(CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) { - // this is the placeholder element: do nothing } else { super.endTransformingElement(uri, name, raw); } @@ -550,7 +545,11 @@ if ( null != this.configurationParameters ) { mimeType = this.configurationParameters.getParameter("mime-type", mimeType); } - this.resolver.toSAX(source, mimeType, this.filter); + if ( this.compiling ) { + this.resolver.toSAX(source, mimeType, new IncludeXMLConsumer(this.contentHandler, this.lexicalHandler)); + } else { + this.resolver.toSAX(source, mimeType, this.filter); + } } @@ -592,7 +591,6 @@ this.addRecorder(recorder); - this.sendStartPrefixMapping(); } catch (ComponentException ce) { throw new SAXException("Unable to lookup xml serializer for compiling xml.", ce); } @@ -611,8 +609,6 @@ this.getLogger().debug("BEGIN endCompiledXMLRecording"); } - this.sendEndPrefixMapping(); - XMLSerializer recorder = (XMLSerializer)this.removeRecorder(); Object text = (byte[])recorder.getSAXFragment(); @@ -626,7 +622,7 @@ * @see org.xml.sax.ContentHandler#startDocument() */ public void startDocument() throws SAXException { - this.filter = new IncludeXMLConsumer(this.xmlConsumer); + this.filter = new MyFilter(this.xmlConsumer, this); super.startDocument(); } @@ -675,4 +671,51 @@ return null; } +} + +final class MyFilter extends IncludeXMLConsumer { + + private CIncludeTransformer transformer; + + /** + * This filter class post-processes the parallel fetching + * @param consumer + */ + public MyFilter(XMLConsumer consumer, CIncludeTransformer transformer) { + super(consumer); + this.transformer = transformer; + } + + + public void endElement(String uri, String local, String qName) + throws SAXException { + if (uri != null + && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI) + && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) { + // this is the placeholder element: do nothing + } else { + super.endElement(uri, local, qName); + } + } + + public void startElement(String uri, + String local, + String qName, + Attributes attr) + throws SAXException { + if (uri != null + && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI) + && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) { + // this is a placeholder + try { + final String src = attr.getValue("",CIncludeTransformer.CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE); + this.transformer.cacheManager.stream(src, this.transformer.cachingSession, this); + } catch (IOException ioe) { + throw new SAXException("IOException", ioe); + } + } else { + super.startElement(uri, local, qName, attr); + } + } + }