cziegeler 01/11/09 04:21:10 Modified: src/org/apache/cocoon/sitemap ContentAggregator.java Log: Fixed (hopefully) namespace, prefix and strip-root handling in CA Revision Changes Path 1.20 +56 -46 xml-cocoon2/src/org/apache/cocoon/sitemap/ContentAggregator.java Index: ContentAggregator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/ContentAggregator.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ContentAggregator.java 2001/10/11 07:28:23 1.19 +++ ContentAggregator.java 2001/11/09 12:21:10 1.20 @@ -8,9 +8,7 @@ package org.apache.cocoon.sitemap; -import org.apache.avalon.framework.component.ComponentException; -import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.Composable; +import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.AggregatedCacheValidity; @@ -35,9 +33,11 @@ /** * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: ContentAggregator.java,v 1.19 2001/10/11 07:28:23 cziegeler Exp $ + * @version CVS $Id: ContentAggregator.java,v 1.20 2001/11/09 12:21:10 cziegeler Exp $ */ -public class ContentAggregator extends ContentHandlerWrapper implements Generator, Cacheable, Composable { +public class ContentAggregator +extends ContentHandlerWrapper +implements Generator, Cacheable, Recyclable { /** the root element of the aggregated content */ protected String rootElement; @@ -63,30 +63,15 @@ /** The source URI associated with the request or <b>null</b>. */ protected String source; - /** The <code>ComponentManager</code> */ - protected ComponentManager manager; - /** Stacks namespaces during processing */ private ArrayList currentNS = new ArrayList(); + /** Stacks prefixes during processing */ + private ArrayList currentPrefix = new ArrayList(); + /** Indicates the position in the stack of the root element of the aggregated content */ private int rootElementIndex; - /** - * Pass the <code>ComponentManager</code> to the <code>Composable</code>. - * The <code>Composable</code> implementation should use the specified - * <code>ComponentManager</code> to acquire the components it needs for - * execution. - * - * @param manager The <code>ComponentManager</code> which this - * <code>Composable</code> uses. - */ - public void compose(ComponentManager manager) throws ComponentException { - if (this.manager == null) { - this.manager = manager; - } - } - /** This object holds the part parts :) */ private class Part { public String uri; @@ -101,6 +86,7 @@ this.element = element; this.namespace = namespace; this.prefix = prefix; + if (this.prefix == null) this.prefix = ""; if (stripRoot.equals("yes") || stripRoot.equals("true")) { this.stripRootElement = true; } else { @@ -119,12 +105,12 @@ try { for (int i = 0; i < this.parts.size(); i++) { Part part = (Part)this.parts.get(i); - this.rootElementIndex = (part.stripRootElement ? 0 : -1); + this.rootElementIndex = (part.stripRootElement ? -1 : 0); String ns = part.namespace; String prefix = part.prefix; - if (ns == null || ns.equals("")) { + if (ns.equals("")) { ns = this.getNS(); - prefix = ""; + prefix = this.getPrefix(); } if (!part.element.equals("")) { this.startElem(ns, prefix, part.element); @@ -199,6 +185,7 @@ this.rootElement = element; this.rootElementNS = namespace; this.rootElementNSPrefix = prefix; + if (prefix == null) this.rootElementNSPrefix = ""; getLogger().debug("ContentAggregator: root element='" + element + "' ns='" + namespace + "' prefix='" + prefix + "'"); } @@ -235,6 +222,7 @@ ((Part)i.next()).source.recycle(); this.parts.clear(); this.currentNS.clear(); + this.currentPrefix.clear(); } /** @@ -255,8 +243,9 @@ } } - private String pushNS(String ns) { - currentNS.add(ns); + private String pushNS(String ns, String prefix) { + this.currentNS.add(ns); + this.currentPrefix.add(prefix); return ns; } @@ -264,6 +253,7 @@ int last = currentNS.size() - 1; String ns = (String)currentNS.get(last); currentNS.remove(last); + currentPrefix.remove(last); return ns; } @@ -272,18 +262,26 @@ return (String)currentNS.get(last); } + private String getPrefix() { + int last = currentPrefix.size() - 1; + return (String)currentPrefix.get(last); + } + private void startElem(String namespaceURI, String prefix, String name) throws SAXException { - this.pushNS(namespaceURI); + this.pushNS(namespaceURI, prefix); AttributesImpl attrs = new AttributesImpl(); if (!namespaceURI.equals("")) { this.contentHandler.startPrefixMapping(prefix, namespaceURI); + this.contentHandler.startElement(namespaceURI, name, prefix+':'+name, attrs); + } else { + this.contentHandler.startElement(namespaceURI, name, name, attrs); } - this.contentHandler.startElement(namespaceURI, name, name, attrs); } private void endElem(String prefix, String name) throws SAXException { - String ns = this.popNS(); - this.contentHandler.endElement(ns, name, name); + final String ns = this.popNS(); + final String qname = prefix.equals("") ? name : prefix+':'+name; + this.contentHandler.endElement(ns, name, qname); if (ns != null && !ns.equals("")) { this.contentHandler.endPrefixMapping(prefix); } @@ -298,26 +296,38 @@ public void endDocument() throws SAXException { } - public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) + throws SAXException { + this.rootElementIndex++; + if (this.rootElementIndex == 0) { + getLogger().debug("ContentAggregator: skipping root element start event."); + return; + } String ns = namespaceURI; if (ns == null || ns.equals("")) { - ns = (String)this.getNS(); - } - this.pushNS(ns); - if (rootElementIndex != 0) { - this.contentHandler.startElement(ns, localName, qName, atts); - } else { - rootElementIndex = currentNS.size(); - getLogger().debug("ContentAggregator: skipping root element start event " + rootElementIndex); + ns = this.getNS(); + final String prefix = this.getPrefix(); + if (!prefix.equals("")) { + qName = prefix + ':' + qName; + } } + this.contentHandler.startElement(ns, localName, qName, atts); } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { - if (rootElementIndex != currentNS.size()) { - this.contentHandler.endElement((String)this.popNS(), localName, qName); - } else { - this.popNS(); - getLogger().debug("ContentAggregator: ignoring root element end event " + rootElementIndex); + this.rootElementIndex--; + if (this.rootElementIndex == -1) { + getLogger().debug("ContentAggregator: ignoring root element end event."); + return; + } + String ns = namespaceURI; + if (ns == null || ns.equals("")) { + ns = this.getNS(); + final String prefix = this.getPrefix(); + if (!prefix.equals("")) { + qName = prefix + ':' + qName; + } } + this.contentHandler.endElement(ns, localName, qName); } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]