giacomo 01/04/24 13:21:27
Modified: src/org/apache/cocoon/sitemap Tag: xml-cocoon2
ContentAggregator.java
src/org/apache/cocoon/components/language/markup/sitemap/java
Tag: xml-cocoon2 sitemap.xsl
Log:
Added an optional strip-root attribute to the map:part element of the
map:aggregate element to indicate that the aggregator should strip off
the root element of the aggregated content. The values can be "yes" or "true"
to strip off and anything else to not.
Also made the element attribute of the map:part element optional.
Revision Changes Path
No revision
No revision
1.1.2.7 +58 -34
xml-cocoon/src/org/apache/cocoon/sitemap/Attic/ContentAggregator.java
Index: ContentAggregator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/sitemap/Attic/ContentAggregator.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- ContentAggregator.java 2001/04/24 20:18:27 1.1.2.6
+++ ContentAggregator.java 2001/04/24 20:21:26 1.1.2.7
@@ -41,7 +41,7 @@
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Id: ContentAggregator.java,v 1.1.2.6 2001/04/24 20:18:27
dims Exp $
+ * @version CVS $Id: ContentAggregator.java,v 1.1.2.7 2001/04/24 20:21:26
giacomo Exp $
*/
public class ContentAggregator extends ContentHandlerWrapper
@@ -55,15 +55,9 @@
/** the namespace of the root element */
protected String rootElementNS;
- /** the elements of the parts */
- protected ArrayList partElements = new ArrayList();
+ /** the parts */
+ protected ArrayList parts = new ArrayList();
- /** the namespaces of the parts */
- protected ArrayList partNSs = new ArrayList();
-
- /** the URIs of the parts */
- protected ArrayList partURIs = new ArrayList();
-
/** The current <code>Environment</code>. */
protected Environment environment;
@@ -97,6 +91,9 @@
/** Stacks namespaces during processing */
private ArrayList currentNS = 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>composer</code>.
* The <code>Composable</code> implementation should use the specified
@@ -112,6 +109,24 @@
}
}
+ /** This object holds the part parts :) */
+ private class Part {
+ public String uri;
+ public String element;
+ public String namespace;
+ boolean stripRootElement;
+ public Part (String uri, String element, String namespace, String
stripRoot) {
+ this.uri = uri;
+ this.element = element;
+ this.namespace = namespace;
+ if (stripRoot.equals("yes") || stripRoot.equals("true")) {
+ this.stripRootElement = true;
+ } else {
+ this.stripRootElement = false;
+ }
+ }
+ }
+
/**
* generates the content
*/
@@ -122,23 +137,29 @@
this.startElem(this.rootElementNS, this.rootElement);
try {
for (int i = 0; i < this.partEventPipelines.size(); i++) {
- String ns = (String)this.partNSs.get(i);
+ Part part = (Part)this.parts.get(i);
+ this.rootElementIndex = (part.stripRootElement ? 0 : -1);
+ String ns = part.namespace;
if (ns.equals("")) {
ns = this.getNS();
+ }
+ if (!part.element.equals("")) {
+ this.startElem(ns, part.element);
}
- this.startElem(ns, (String)this.partElements.get(i));
EventPipeline ep =
(EventPipeline)this.partEventPipelines.get(i);
((XMLProducer)ep).setConsumer(this);
try {
- this.environment.pushURI((String)this.partURIs.get(i));
+ this.environment.pushURI(part.uri);
ep.process(this.environment);
} catch (Exception e) {
- getLogger().error("ContentAggregator: cannot process
event pipeline for URI " + this.partURIs.get(i), e);
- throw new ProcessingException ("ContentAggregator:
cannot process event pipeline for URI " + this.partURIs.get(i), e);
+ getLogger().error("ContentAggregator: cannot process
event pipeline for URI " + part.uri, e);
+ throw new ProcessingException ("ContentAggregator:
cannot process event pipeline for URI " + part.uri, e);
} finally {
this.manager.release(ep);
this.environment.popURI();
- this.endElem((String)this.partElements.get(i));
+ if (!part.element.equals("")) {
+ this.endElem(part.element);
+ }
}
}
} finally {
@@ -152,9 +173,9 @@
if (this.partEventPipelines.size() == 0) {
EventPipeline eventPipeline = null;
StreamPipeline pipeline = null;
- for (int i = 0; i < this.partElements.size(); i++) {
- getLogger().debug("ContentAggregator: collecting internal
resource "
- + (String)this.partURIs.get(i));
+ for (int i = 0; i < this.parts.size(); i++) {
+ Part part = (Part)this.parts.get(i);
+ getLogger().debug("ContentAggregator: collecting internal
resource " + part.uri);
try {
eventPipeline =
(EventPipeline)this.manager.lookup(Roles.EVENT_PIPELINE);
this.partEventPipelines.add(eventPipeline);
@@ -170,7 +191,7 @@
throw new ProcessingException ("could not set event
pipeline on stream pipeline", cme);
}
try {
- this.environment.pushURI((String)this.partURIs.get(i));
+ this.environment.pushURI(part.uri);
this.sitemap.process(this.environment, pipeline,
eventPipeline);
} catch (Exception cme) {
getLogger().error("ContentAggregator: could not process
pipeline", cme);
@@ -220,16 +241,10 @@
}
getLogger().debug("ContentAggregator: root element='" + element + "'
ns='" + namespace + "'");
}
-
- public void addPart(String uri, String element, String namespace) {
- if (namespace == null) {
- this.partNSs.add("");
- } else {
- this.partNSs.add(namespace);
- }
- this.partURIs.add(uri);
- this.partElements.add(element);
- getLogger().debug("ContentAggregator: part uri='" + uri + "'
element='" + element + "' ns='" + namespace + "'");
+
+ public void addPart(String uri, String element, String namespace, String
stripRootElement) {
+ this.parts.add(new Part(uri, element, namespace, stripRootElement));
+ getLogger().debug("ContentAggregator: part uri='" + uri + "'
element='" + element + "' ns='" + namespace + "' stripRootElement='" +
stripRootElement + "'");
}
/**
@@ -271,9 +286,7 @@
this.parameters = null;
this.rootElement = null;
this.rootElementNS = null;
- this.partURIs.clear();
- this.partElements.clear();
- this.partNSs.clear();
+ this.parts.clear();
this.environment = null;
this.partEventPipelines.clear();
this.currentNS.clear();
@@ -344,11 +357,22 @@
if (ns.equals("")) {
ns = (String)this.getNS();
}
- this.documentHandler.startElement(this.pushNS(ns), localName, qName,
atts);
+ this.pushNS(ns);
+ if (rootElementIndex != 0) {
+ this.documentHandler.startElement(ns, localName, qName, atts);
+ } else {
+ rootElementIndex = currentNS.size();
+ getLogger().debug("ContentAggregator: skipping root element
start event " + rootElementIndex);
+ }
}
public void endElement (String namespaceURI, String localName,
String qName) throws SAXException {
- this.documentHandler.endElement((String)this.popNS(), localName,
qName);
+ if (rootElementIndex != currentNS.size()) {
+ this.documentHandler.endElement((String)this.popNS(), localName,
qName);
+ } else {
+ this.popNS();
+ getLogger().debug("ContentAggregator: ignoring root element end
event " + rootElementIndex);
+ }
}
}
No revision
No revision
1.1.2.106 +5 -28
xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl
Index: sitemap.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/sitemap/java/Attic/sitemap.xsl,v
retrieving revision 1.1.2.105
retrieving revision 1.1.2.106
diff -u -r1.1.2.105 -r1.1.2.106
--- sitemap.xsl 2001/04/24 20:18:23 1.1.2.105
+++ sitemap.xsl 2001/04/24 20:21:27 1.1.2.106
@@ -98,7 +98,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo
Pati</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin
Loritsch</a>
- * @version CVS $Id: sitemap.xsl,v 1.1.2.105 2001/04/24 20:18:23 dims
Exp $
+ * @version CVS $Id: sitemap.xsl,v 1.1.2.106 2001/04/24 20:21:27 giacomo
Exp $
*/
public class <xsl:value-of select="@file-name"/> extends AbstractSitemap
{
static final String LOCATION = "<xsl:value-of
select="translate(@file-path, '/', '.')"/>.<xsl:value-of select="@file-name"/>";
@@ -976,21 +976,14 @@
</xsl:with-param>
</xsl:call-template>
</xsl:if>
- <xsl:choose>
- <xsl:when test="@ns">
- <xsl:value-of select="$ca"/>.setRootElement("<xsl:value-of
select="@element"/>", "<xsl:value-of select="@ns"/>");
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$ca"/>.setRootElement("<xsl:value-of
select="@element"/>", null);
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:value-of select="$ca"/>.setRootElement("<xsl:value-of
select="@element"/>", "<xsl:value-of select="@ns"/>");
<xsl:apply-templates select="./map:part">
<xsl:with-param name="ca"><xsl:value-of select="$ca"/></xsl:with-param>
</xsl:apply-templates>
</xsl:template> <!-- match="map:aggregate" -->
<!-- generate the code to match a aggregates part definition -->
- <xsl:template match="map:aggregate/map:part">
+ <xsl:template match="map:part">
<xsl:param name="ca"/>
<xsl:if test="not (@src)">
<xsl:call-template name="error">
@@ -998,25 +991,9 @@
src attribute missing in aggregates part element
</xsl:with-param>
</xsl:call-template>
- </xsl:if>
- <!--
- <xsl:if test="not (@element)">
- <xsl:call-template name="error">
- <xsl:with-param name="message">
- element attribute missing in aggregates part element
- </xsl:with-param>
- </xsl:call-template>
</xsl:if>
- -->
- <xsl:choose>
- <xsl:when test="@ns">
- <xsl:value-of
select="$ca"/>.addPart(substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
"<xsl:value-of select="@element"/>", "<xsl:value-of select="@ns"/>");
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of
select="$ca"/>.addPart(substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
"<xsl:value-of select="@element"/>", null);
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template> <!-- match="map:aggregate/map:part" -->
+ <xsl:value-of
select="$ca"/>.addPart(substitute(listOfMaps,"<xsl:value-of select="@src"/>"),
"<xsl:value-of select="@element"/>", "<xsl:value-of select="@ns"/>",
"<xsl:value-of select="@strip-root"/>");
+ </xsl:template> <!-- match="map:part" -->
<!-- collect parameter definitions -->
<xsl:template match="map:pipeline//parameter | map:action-set//parameter">
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]