sylvain 02/02/09 14:34:24
Modified: src/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap
AggregateNode.java AggregateNodeBuilder.java
Log:
Correction of views handling in map:aggregate
Revision Changes Path
1.6 +26 -28
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/AggregateNode.java
Index: AggregateNode.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/AggregateNode.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AggregateNode.java 4 Feb 2002 14:39:53 -0000 1.5
+++ AggregateNode.java 9 Feb 2002 22:34:23 -0000 1.6
@@ -79,29 +79,32 @@
* </li>
* <li>each map:part can have a label
* </li>
- * <li>parts labels are checked first for a matching view, then the aggregate label
is checked
+ * <li>if at least one of the parts has a label matching the current view, only
parts matching
+ * this view are added. Otherwise, all parts are added.
* </li>
* </ul>
- * For more info on aggregation and view, see the mail archive
+ * For more info on aggregation and views, see the mail archive
* <a
href="http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=100525751417953">here</a> or
* <a
href="http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=100517130418424">here</a>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Id: AggregateNode.java,v 1.5 2002/02/04 14:39:53 cziegeler Exp $
+ * @version CVS $Id: AggregateNode.java,v 1.6 2002/02/09 22:34:23 sylvain Exp $
*/
public class AggregateNode extends AbstractProcessingNode {
- private Part[] parts;
private String element;
private String nsURI;
private String nsPrefix;
- /** Views for each part */
- private Map[]partViews;
+ /** All parts */
+ private Part[] allParts;
+
+ /** Pre-filtered Part[] for views that have a matching label in any of the
parts */
+ private Map viewParts;
- /** View for map:aggregate */
- private Map views;
+ /** View nodes to jump to */
+ private Map viewNodes;
public AggregateNode(String element, String nsURI, String nsPrefix) {
this.element = element;
@@ -109,13 +112,13 @@
this.nsPrefix = nsPrefix;
}
- public void setParts(Part[] parts) {
- this.parts = parts;
+ public void setParts(Part[] allParts, Map viewParts) {
+ this.allParts = allParts;
+ this.viewParts = viewParts;
}
- public void setViews(Map views, Map[]partViews) {
- this.views = views;
- this.partViews = partViews;
+ public void setViewNodes(Map viewNodes) {
+ this.viewNodes = viewNodes;
}
public boolean invoke(Environment env, InvokeContext context)
@@ -135,24 +138,19 @@
// Get actual parts, potentially filtered by the view
Part[] actualParts;
+
String cocoonView = env.getView();
if (cocoonView == null) {
// Keep all parts
- actualParts = this.parts;
+ actualParts = this.allParts;
} else {
- // Keep only those parts that are in the view
- actualParts = new Part[this.parts.length];
- for (int i = 0; i < actualParts.length; i++) {
- if (this.partViews[i] != null &&
this.partViews[i].containsKey(cocoonView)) {
- // this part is in the view
- actualParts[i] = this.parts[i];
- } else {
- if (infoEnabled) {
- getLogger().info("Aggregate part " + (i+1) + " is not in
the '" +
- cocoonView + "' view, at " + this.getLocation());
- }
- }
+ // Are there some parts that match this view ?
+ actualParts = (Part[])this.viewParts.get(cocoonView);
+
+ // If not, keep all parts
+ if (actualParts == null) {
+ actualParts = this.allParts;
}
}
@@ -168,8 +166,8 @@
}
// Check aggregate-level view
- if (cocoonView != null && this.views != null) {
- ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView);
+ if (cocoonView != null && this.viewNodes != null) {
+ ProcessingNode viewNode =
(ProcessingNode)this.viewNodes.get(cocoonView);
if (viewNode != null) {
if (infoEnabled) {
getLogger().info("Jumping to view '" + cocoonView + "' from
aggregate at " + this.getLocation());
1.5 +59 -27
xml-cocoon2/src/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/AggregateNodeBuilder.java
Index: AggregateNodeBuilder.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/treeprocessor/sitemap/AggregateNodeBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AggregateNodeBuilder.java 4 Feb 2002 14:39:53 -0000 1.4
+++ AggregateNodeBuilder.java 9 Feb 2002 22:34:23 -0000 1.5
@@ -69,18 +69,16 @@
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Id: AggregateNodeBuilder.java,v 1.4 2002/02/04 14:39:53 cziegeler
Exp $
+ * @version CVS $Id: AggregateNodeBuilder.java,v 1.5 2002/02/09 22:34:23 sylvain
Exp $
*/
public class AggregateNodeBuilder extends AbstractProcessingNodeBuilder
implements LinkedProcessingNodeBuilder {
- /** The collection of views for each part */
- private List partViews;
-
- /** The views for the whole aggregate element */
+ /** The views for the aggregate element */
private Collection views;
+ /** The built node */
private AggregateNode node;
public ProcessingNode buildNode(Configuration config) throws Exception {
@@ -94,12 +92,16 @@
this.treeBuilder.setupNode(this.node, config);
this.views = ((SitemapLanguage)this.treeBuilder).getViewsForStatement("",
"", config);
+
+ // The sitemap builder
+ SitemapLanguage sitemap = (SitemapLanguage)this.treeBuilder;
- // Build parts
- List parts = new ArrayList();
-
- this.partViews = new ArrayList();
-
+ // All parts of the aggregate
+ List allParts = new ArrayList();
+
+ // For each view that a part matches, the list of all parts that match it
+ Map viewParts = new HashMap();
+
Configuration[] childConfigs = config.getChildren();
for (int i = 0; i < childConfigs.length; i++) {
Configuration childConfig = childConfigs[i];
@@ -113,27 +115,63 @@
checkNamespace(childConfig);
- parts.add(new AggregateNode.Part(
+ AggregateNode.Part currentPart = new AggregateNode.Part(
childConfig.getAttribute("src"),
childConfig.getAttribute("element", ""),
childConfig.getAttribute("ns", ""),
childConfig.getAttribute("prefix", ""),
childConfig.getAttributeAsBoolean("strip-root", false)
- ));
-
-
this.partViews.add(((SitemapLanguage)this.treeBuilder).getViewsForStatement("", "",
childConfig));
+ );
+
+ allParts.add(currentPart);
+
+ // Get the views for this part
+ Collection viewsForPart = sitemap.getViewsForStatement("", "",
childConfig);
+
+ // Associate this part to all the views it belongs to
+ if (viewsForPart != null) {
+ Iterator iter = viewsForPart.iterator();
+ while(iter.hasNext()) {
+ String currentView = (String)iter.next();
+
+ // Get collection of parts for current view
+ Collection currentViewParts =
(Collection)viewParts.get(currentView);
+ if (currentViewParts == null) {
+ // None for now : create the collection
+ currentViewParts = new ArrayList();
+ viewParts.put(currentView, currentViewParts);
+ }
+
+ // Add the current part to the parts list of the view
+ currentViewParts.add(currentPart);
+ }
+ }
}
- if (parts.size() == 0) {
+ if (allParts.size() == 0) {
String msg = "There must be at least one part in map:aggregate at " +
config.getLocation();
getLogger().error(msg);
throw new ConfigurationException(msg);
}
- AggregateNode.Part[] partArray = (AggregateNode.Part[])parts.toArray(
- new AggregateNode.Part[parts.size()]);
+ // Now convert all Collections to Array for faster traversal
+ AggregateNode.Part[] allPartsArray = (AggregateNode.Part[])allParts.toArray(
+ new AggregateNode.Part[allParts.size()]);
+
+ Iterator iter = viewParts.entrySet().iterator();
+ while(iter.hasNext()) {
+ Map.Entry entry = (Map.Entry)iter.next();
+
+ // Get collection of parts for this entry
+ Collection coll = (Collection)entry.getValue();
+
+ // Convert to array and replace the entry value
+ entry.setValue(
+ coll.toArray(new AggregateNode.Part[coll.size()])
+ );
+ }
- node.setParts(partArray);
+ node.setParts(allPartsArray, viewParts);
return node;
@@ -141,15 +179,9 @@
public void linkNode() throws Exception {
+ // Give the AggregateNode a Node for each view
SitemapLanguage sitemap = (SitemapLanguage)this.treeBuilder;
-
- // Replace all contents of partViews by the map of views.
- Map[] partViewNodes = new Map[this.partViews.size()];
-
- for (int i = 0; i < partViewNodes.length; i++) {
- partViewNodes[i] =
sitemap.getViewNodes((Collection)this.partViews.get(i));
- }
-
- this.node.setViews(sitemap.getViewNodes(this.views), partViewNodes);
+
+ this.node.setViewNodes(sitemap.getViewNodes(this.views));
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]