From 30c53da7699493b4a83d15b521f4f6f8776842e6 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Wed, 30 Oct 2002 13:09:11 +0000 Subject: [PATCH] Added sparsePropsSet support. Untabified. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195373 13f79535-47bb-0310-9956-ffa450edef68 --- .../fo/pagination/FoPageSequenceMaster.java | 327 ++++++++++++------ 1 file changed, 224 insertions(+), 103 deletions(-) diff --git a/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java b/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java index a9fa01ba7..1181a31fb 100644 --- a/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java +++ b/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java @@ -9,8 +9,8 @@ package org.apache.fop.fo.pagination; -import java.util.ArrayList; -import java.util.LinkedList; +import java.util.HashMap; +import java.util.BitSet; import java.util.NoSuchElementException; // FOP @@ -30,6 +30,7 @@ import org.apache.fop.fo.FONode; import org.apache.fop.datastructs.Tree; import org.apache.fop.datatypes.PropertyValue; import org.apache.fop.datatypes.NCName; +import org.apache.fop.datatypes.Ints; /** * Implements the fo:page-sequence-master flow object. These Fos are @@ -42,6 +43,138 @@ public class FoPageSequenceMaster extends FONode { private static final String tag = "$Name$"; private static final String revision = "$Revision$"; + /** Map of Integer indices of sparsePropsSet array. + It is indexed by the FO index of the FO associated with a given + position in the sparsePropsSet array. See + {@link org.apache.fop.fo.FONode#sparsePropsSet FONode.sparsePropsSet}. + */ + private static final HashMap sparsePropsMap; + + /** An int array of of the applicable property indices, in + property index order. */ + private static final int[] sparseIndices; + + /** The number of applicable properties. This is the size of the + sparsePropsSet array. */ + private static final int numProps; + + static { + // applicableProps is a HashMap containing the indicies of the + // sparsePropsSet array, indexed by the FO index of the FO slot + // in sparsePropsSet. + sparsePropsMap = new HashMap(1); + numProps = 1; + sparseIndices = new int[] { PropNames.MASTER_NAME }; + sparsePropsMap.put + (Ints.consts.get(PropNames.MASTER_NAME), Ints.consts.get(0)); + } + + /** Constant values for FoSinglePageMasterReference. + See {@link #sparsePropsMap sparsePropsMap}. */ + private static final HashMap s_p_m_r_PropsMap; + + /** See {@link #sparseIndices sparseIndices}. */ + private static final int[] s_p_m_r_Indices; + + /** See {@link #numProps numProps}. */ + private static final int s_p_m_r_numProps; + + static { + // applicableProps is a HashMap containing the indicies of the + // sparsePropsSet array, indexed by the FO index of the FO slot + // in sparsePropsSet. + s_p_m_r_PropsMap = new HashMap(1); + s_p_m_r_numProps = 1; + s_p_m_r_Indices = new int[] { PropNames.MASTER_REFERENCE }; + s_p_m_r_PropsMap.put + (Ints.consts.get(PropNames.MASTER_REFERENCE), + Ints.consts.get(0)); + } + + /** See {@link #sparsePropsMap sparsePropsMap}. */ + private static final HashMap r_p_m_r_PropsMap; + + /** See {@link #sparseIndices sparseIndices}. */ + private static final int[] r_p_m_r_Indices; + + /** See {@link #numProps numProps}. */ + private static final int r_p_m_r_numProps; + + static { + // Collect the sets of properties that apply + BitSet propsets = new BitSet(); + propsets.set(PropNames.MASTER_REFERENCE); + propsets.set(PropNames.MAXIMUM_REPEATS); + + // Map these properties into sparsePropsSet + // sparsePropsSet is a HashMap containing the indicies of the + // sparsePropsSet array, indexed by the FO index of the FO slot + // in sparsePropsSet. + r_p_m_r_PropsMap = new HashMap(); + r_p_m_r_numProps = propsets.cardinality(); + r_p_m_r_Indices = new int[r_p_m_r_numProps]; + int propx = 0; + for (int next = propsets.nextSetBit(0); + next >= 0; + next = propsets.nextSetBit(next + 1)) { + r_p_m_r_Indices[propx] = next; + r_p_m_r_PropsMap.put + (Ints.consts.get(next), Ints.consts.get(propx++)); + } + } + + /** See {@link #sparsePropsMap sparsePropsMap}. */ + private static final HashMap r_p_m_a_PropsMap; + + /** See {@link #sparseIndices sparseIndices}. */ + private static final int[] r_p_m_a_Indices; + + /** See {@link #numProps numProps}. */ + private static final int r_p_m_a_numProps; + + static { + r_p_m_a_PropsMap = new HashMap(1); + r_p_m_a_numProps = 1; + r_p_m_a_Indices = new int[] { PropNames.MAXIMUM_REPEATS }; + r_p_m_a_PropsMap.put + (Ints.consts.get(PropNames.MAXIMUM_REPEATS), + Ints.consts.get(0)); + } + + /** See {@link #sparsePropsMap sparsePropsMap}. */ + private static final HashMap c_p_m_r_PropsMap; + + /** See {@link #sparseIndices sparseIndices}. */ + private static final int[] c_p_m_r_Indices; + + /** See {@link #numProps numProps}. */ + private static final int c_p_m_r_numProps; + + static { + // Collect the sets of properties that apply + BitSet propsets = new BitSet(); + propsets.set(PropNames.MASTER_REFERENCE); + propsets.set(PropNames.PAGE_POSITION); + propsets.set(PropNames.ODD_OR_EVEN); + propsets.set(PropNames.BLANK_OR_NOT_BLANK); + + // Map these properties into sparsePropsSet + // sparsePropsSet is a HashMap containing the indicies of the + // sparsePropsSet array, indexed by the FO index of the FO slot + // in sparsePropsSet. + c_p_m_r_PropsMap = new HashMap(); + c_p_m_r_numProps = propsets.cardinality(); + c_p_m_r_Indices = new int[c_p_m_r_numProps]; + int propx = 0; + for (int next = propsets.nextSetBit(0); + next >= 0; + next = propsets.nextSetBit(next + 1)) { + c_p_m_r_Indices[propx] = next; + c_p_m_r_PropsMap.put + (Ints.consts.get(next), Ints.consts.get(propx++)); + } + } + /** * An array with ints identifying * single-page-master-reference, @@ -54,15 +187,12 @@ public class FoPageSequenceMaster extends FONode { FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES }; - private String masterName; - - //private ArrayList subSequenceList = new ArrayList(1); - public FoPageSequenceMaster(FOTree foTree, FONode parent, FoXMLEvent event) throws Tree.TreeException, FOPException, PropertyException { super(foTree, FObjectNames.PAGE_SEQUENCE_MASTER, parent, event, - FOPropertySets.SEQ_MASTER_SET); + FOPropertySets.SEQ_MASTER_SET, sparsePropsMap, sparseIndices, + numProps); // Process sequence members here try { do { @@ -72,49 +202,35 @@ public class FoPageSequenceMaster extends FONode { int foType = ev.getFoType(); if (foType == FObjectNames.SINGLE_PAGE_MASTER_REFERENCE) { //System.out.println("Found single-page-master-reference"); - //subSequenceList.add(new FoSinglePageMasterReference - //(foTree, this, ev)); - new FoSinglePageMasterReference(foTree, this, ev); + new FoSinglePageMasterReference(foTree, this, ev); } else if (foType == FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE) { //System.out.println // ("Found repeatable-page-master-reference"); - //subSequenceList.add(new FoRepeatablePageMasterReference - //(foTree, this, ev)); - new FoRepeatablePageMasterReference(foTree, this, ev); + new FoRepeatablePageMasterReference(foTree, this, ev); } else if (foType == FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES) { //System.out.println // ("Found repeatable-page-master-alternatives"); - //subSequenceList.add(new FoRepeatablePageMasterAlternatives - //(foTree, this, ev)); - new FoRepeatablePageMasterAlternatives(foTree, this, ev); + new FoRepeatablePageMasterAlternatives(foTree, this, ev); } else throw new FOPException ("Aargh! expectStartElement(events, list)"); + xmlevents.getEndElement(ev); } while (true); } catch (NoSuchElementException e) { throw new FOPException("Unexpected EOF in page-sequence-master."); } if (this.numChildren() == 0) throw new FOPException("No children of page-sequence-master."); - XMLEvent ev = xmlevents.getEndElement(event); + makeSparsePropsSet(); } /** * @return a String with the "master-name" attribute value. */ public String getMasterName() throws PropertyException { - if (masterName == null) { - PropertyValue name = propertySet[PropNames.MASTER_NAME]; - if (name == null) - throw new PropertyException("master-name property not set"); - if (name.getType() != PropertyValue.NCNAME) - throw new PropertyException - ("master-name property not an NCName."); - masterName = ((NCName)name).getNCName(); - } - return masterName; + return ((NCName)getPropertyValue(PropNames.MASTER_NAME)).getNCName(); } /** @@ -123,18 +239,19 @@ public class FoPageSequenceMaster extends FONode { */ public class FoSinglePageMasterReference extends FONode { - public FoSinglePageMasterReference - (FOTree foTree, FONode parent, FoXMLEvent event) - throws Tree.TreeException, FOPException, PropertyException - { - super(foTree, FObjectNames.SINGLE_PAGE_MASTER_REFERENCE, parent, - event, FOPropertySets.SEQ_MASTER_SET); - this.xmlevents.getEndElement(event); - } + public FoSinglePageMasterReference + (FOTree foTree, FONode parent, FoXMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, FObjectNames.SINGLE_PAGE_MASTER_REFERENCE, parent, + event, FOPropertySets.SEQ_MASTER_SET, s_p_m_r_PropsMap, + s_p_m_r_Indices, s_p_m_r_numProps); + this.makeSparsePropsSet(); + } - public PropertyValue getMasterReference() throws PropertyException { - return this.getPropertyValue(PropNames.MASTER_REFERENCE); - } + public PropertyValue getMasterReference() throws PropertyException { + return this.getPropertyValue(PropNames.MASTER_REFERENCE); + } }// FoSinglePageMasterReference @@ -144,22 +261,23 @@ public class FoPageSequenceMaster extends FONode { */ public class FoRepeatablePageMasterReference extends FONode { - public FoRepeatablePageMasterReference - (FOTree foTree, FONode parent, FoXMLEvent event) - throws Tree.TreeException, FOPException, PropertyException - { - super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE, - parent, event, FOPropertySets.SEQ_MASTER_SET); - this.xmlevents.getEndElement(event); - } + public FoRepeatablePageMasterReference + (FOTree foTree, FONode parent, FoXMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE, + parent, event, FOPropertySets.SEQ_MASTER_SET, + r_p_m_r_PropsMap, r_p_m_r_Indices, r_p_m_r_numProps); + this.makeSparsePropsSet(); + } - public PropertyValue getMasterReference() throws PropertyException { - return this.getPropertyValue(PropNames.MASTER_REFERENCE); - } + public PropertyValue getMasterReference() throws PropertyException { + return this.getPropertyValue(PropNames.MASTER_REFERENCE); + } - public PropertyValue getMaximumRepeats() throws PropertyException { - return this.getPropertyValue(PropNames.MAXIMUM_REPEATS); - } + public PropertyValue getMaximumRepeats() throws PropertyException { + return this.getPropertyValue(PropNames.MAXIMUM_REPEATS); + } }// FoRepeatablePageMasterReference @@ -169,17 +287,18 @@ public class FoPageSequenceMaster extends FONode { */ public class FoRepeatablePageMasterAlternatives extends FONode { - public FoRepeatablePageMasterAlternatives - (FOTree foTree, FONode parent, FoXMLEvent event) - throws Tree.TreeException, FOPException, PropertyException - { - super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES, - parent, event, FOPropertySets.SEQ_MASTER_SET); - - // Process conditional-page-master-references here - try { - do { - FoXMLEvent ev = this.xmlevents.expectStartElement + public FoRepeatablePageMasterAlternatives + (FOTree foTree, FONode parent, FoXMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES, + parent, event, FOPropertySets.SEQ_MASTER_SET, + r_p_m_a_PropsMap, r_p_m_a_Indices, r_p_m_a_numProps); + + // Process conditional-page-master-references here + try { + do { + FoXMLEvent ev = this.xmlevents.expectStartElement (FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE, XMLEvent.DISCARD_W_SPACE); if (ev == null) break; // Sub-sequences exhausted @@ -187,47 +306,49 @@ public class FoPageSequenceMaster extends FONode { // ("Found conditional-page-master-reference"); new FoConditionalPageMasterReference(foTree, this, ev); this.xmlevents.getEndElement(ev); - } while (true); - } catch (NoSuchElementException e) { - // End of file reached + } while (true); + } catch (NoSuchElementException e) { + // End of file reached throw new FOPException("EOF in repeatable-page-masters."); - } - XMLEvent ev = this.xmlevents.getEndElement(event); - } - - public PropertyValue getMaximumRepeats() throws PropertyException { - return this.getPropertyValue(PropNames.MAXIMUM_REPEATS); - } - - public class FoConditionalPageMasterReference extends FONode { - - public FoConditionalPageMasterReference - (FOTree foTree, FONode parent, FoXMLEvent event) - throws Tree.TreeException, FOPException, PropertyException - { - super(foTree, FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE, - parent, event, FOPropertySets.SEQ_MASTER_SET); - } - - public PropertyValue getMasterReference() throws PropertyException - { - return this.getPropertyValue(PropNames.MASTER_REFERENCE); - } - - public PropertyValue getPagePosition() throws PropertyException { - return this.getPropertyValue(PropNames.PAGE_POSITION); - } - - public PropertyValue getOddOrEven() throws PropertyException { - return this.getPropertyValue(PropNames.ODD_OR_EVEN); - } - - public PropertyValue getBlankOrNotBlank() throws PropertyException - { - return this.getPropertyValue(PropNames.BLANK_OR_NOT_BLANK); - } - - } // FoConditionalPageMasterReference + } + this.makeSparsePropsSet(); + } + + public PropertyValue getMaximumRepeats() throws PropertyException { + return this.getPropertyValue(PropNames.MAXIMUM_REPEATS); + } + + public class FoConditionalPageMasterReference extends FONode { + + public FoConditionalPageMasterReference + (FOTree foTree, FONode parent, FoXMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE, + parent, event, FOPropertySets.SEQ_MASTER_SET, + c_p_m_r_PropsMap, c_p_m_r_Indices, c_p_m_r_numProps); + this.makeSparsePropsSet(); + } + + public PropertyValue getMasterReference() throws PropertyException + { + return this.getPropertyValue(PropNames.MASTER_REFERENCE); + } + + public PropertyValue getPagePosition() throws PropertyException { + return this.getPropertyValue(PropNames.PAGE_POSITION); + } + + public PropertyValue getOddOrEven() throws PropertyException { + return this.getPropertyValue(PropNames.ODD_OR_EVEN); + } + + public PropertyValue getBlankOrNotBlank() throws PropertyException + { + return this.getPropertyValue(PropNames.BLANK_OR_NOT_BLANK); + } + + } // FoConditionalPageMasterReference }// FoRepeatablePageMasterAlternatives -- 2.39.5