From 4cb4c2e6839111f6baaf96821cf5695d792cb221 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Fri, 16 Apr 2004 05:09:10 +0000 Subject: [PATCH] Added HashMap of ArrayLists of static-content subtrees, indexed by flow-name Provide access to umodifiable Map of above git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197510 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/fo/flow/FoPageSequence.java | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/fop/fo/flow/FoPageSequence.java b/src/java/org/apache/fop/fo/flow/FoPageSequence.java index 62f017051..c7fa6133c 100644 --- a/src/java/org/apache/fop/fo/flow/FoPageSequence.java +++ b/src/java/org/apache/fop/fo/flow/FoPageSequence.java @@ -21,9 +21,16 @@ package org.apache.fop.fo.flow; // FOP +import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; +import java.util.Set; import org.apache.fop.apps.FOPException; import org.apache.fop.datastructs.TreeException; @@ -97,6 +104,20 @@ public class FoPageSequence extends FONode { private int title = -1; /** Child index of first fo:static-content child. */ private int firstStaticContent = -1; + /** + * Private map of Lists of static-content subtrees hashed on + * flow-name. Note that there is no restriction on multiple + * fo:static-content elements being assigned to a single + * flow-name, so the objects keyed by flow-name + * must be able to hold more than one element; hence Lists. + * + * Each element of the HashMap, keyed on the + * flow-name is an ArrayList containing one or + * more instances of FoStaticContent. + */ + private HashMap staticSubtrees = null; + /** Unmodifiable version of staticSubtrees */ + public Map staticContents = null; /** Child index of fo:flow child. */ private int flowChild = -1; @@ -127,18 +148,48 @@ public class FoPageSequence extends FONode { namespaces.relinquishEvent(ev); } // else ignore - // Look for zero or more static-content + // Look for zero or more static-content subtrees nowProcessing = "static-content"; while ((ev = xmlevents.expectStartElement (FObjectNames.STATIC_CONTENT, XmlEvent.DISCARD_W_SPACE)) != null) { // Loop over remaining fo:static-content - if (firstStaticContent == -1) + if (firstStaticContent == -1) { firstStaticContent = numChildren(); - new FoStaticContent(getFOTree(), this, (FoXmlEvent)ev); + staticSubtrees = new HashMap(); + } + FoStaticContent statContent = + new FoStaticContent(getFOTree(), this, (FoXmlEvent)ev); namespaces.relinquishEvent(ev); + // Collect the static-content subtrees for this page-sequence + String flowname = statContent.getFlowName(); + if (! staticSubtrees.containsKey(flowname)) { + // Create a new list for this key + staticSubtrees.put(flowname, new ArrayList(1)); + } + // Add an entry to an existing List + ArrayList statconsList = + (ArrayList)(staticSubtrees.get(flowname)); + statconsList.add(statContent); + } + // Create the unmodifiable map of unmodifiable lists + // TODO make the contents of the events buffer unmodifiable + // Each value in the Map is an ArrayList. Iterate over all of the + // entries, replacing the ArrayList value in each Map.Entry with an + // unmodifiableList constructed from the ArrayList + if (staticSubtrees != null) { + Set entries = staticSubtrees.entrySet(); + Iterator iter = entries.iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry)(iter.next()); + entry.setValue( + Collections.unmodifiableList( + (List)(entry.getValue()))); + } + // Now make an unmodifiableMap from the overall HashMap + // of flow-name indexed ArrayLists + staticContents = Collections.unmodifiableMap(staticSubtrees); } - // Generate a null page for the flow(s) -- 2.39.5