From 1b805e46f740ed64d7dcb691f79531e2d709daca Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Tue, 7 May 2002 05:50:04 +0000 Subject: [PATCH] Initial commit of experimental page-handling. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194782 13f79535-47bb-0310-9956-ffa450edef68 --- .../FoConditionalPageMasterReference.java | 38 ++++ .../fop/fo/pagination/FoLayoutMasterSet.java | 155 ++++++++++++++++ .../fo/pagination/FoPageSequenceMaster.java | 175 ++++++++++++++++++ .../FoRepeatablePageMasterAlternatives.java | 51 +++++ .../fop/fo/pagination/FoSimplePageMaster.java | 55 ++++++ .../FoSinglePageMasterReference.java | 35 ++++ 6 files changed, 509 insertions(+) create mode 100644 src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java create mode 100644 src/org/apache/fop/fo/pagination/FoLayoutMasterSet.java create mode 100644 src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java create mode 100644 src/org/apache/fop/fo/pagination/FoRepeatablePageMasterAlternatives.java create mode 100644 src/org/apache/fop/fo/pagination/FoSimplePageMaster.java create mode 100644 src/org/apache/fop/fo/pagination/FoSinglePageMasterReference.java diff --git a/src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java b/src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java new file mode 100644 index 000000000..40839ebae --- /dev/null +++ b/src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java @@ -0,0 +1,38 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * + * @author Peter B. West + * @version $Revision$ $Name$ + */ + +package org.apache.fop.fo.pagination; + +import org.apache.fop.fo.pagination.FoSimplePageMaster; +import org.apache.fop.fo.FOAttributes; +import org.apache.fop.xml.XMLEvent; +import org.apache.fop.apps.FOPException; +//import org.apache.fop.messaging.MessageHandler; + +public class FoConditionalPageMasterReference { + + private FoSimplePageMaster master; + private FOAttributes attributes; + + private int pagePosition; + private int oddOrEven; + private int blankOrNotBlank; + + public FoConditionalPageMasterReference(XMLEvent event) + throws FOPException + { + attributes = new FOAttributes(event); + } + + public void setMinimumRepeats(int min) { + minimumRepeats = min; + } + +} diff --git a/src/org/apache/fop/fo/pagination/FoLayoutMasterSet.java b/src/org/apache/fop/fo/pagination/FoLayoutMasterSet.java new file mode 100644 index 000000000..592dc50be --- /dev/null +++ b/src/org/apache/fop/fo/pagination/FoLayoutMasterSet.java @@ -0,0 +1,155 @@ +package org.apache.fop.fo.pagination; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.NoSuchElementException; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.xml.XMLEvent; +import org.apache.fop.fo.FOTree; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.datastructs.SyncedCircularBuffer; +import org.apache.fop.datastructs.Tree; +import org.apache.fop.fo.pagination.FoPageSequenceMaster; +import org.apache.fop.fo.pagination.FoPageSequenceMaster.SubSequenceSpecifier; +import org.apache.fop.fo.pagination + .FoPageSequenceMaster.SubSequenceSpecifier.ConditionalPageMasterReference; + +/* + * FoLayoutMasterSet.java + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * + * Created: Mon Nov 12 23:30:51 2001 + * + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * FoLayoutMasterSet is the class which processes the + * layout-master-set element. This is the compulsory first element + * under the root element in an FO document. + */ + +public class FoLayoutMasterSet extends FONode { + + /** + * Hash of SimplePageMaster and PageSequenceMaster objects, + * indexed by master-name of the object. + */ + private HashMap pageMasters; + + /** + * Hash of SimplePageMaster objects, + * indexed by master-name of the object. + */ + private HashMap simplePageMasters; + + /** + * @param foTree the FO tree being built + * @param parent the parent FONode of this node + * @param event the XMLEvent that triggered the creation of + * this node + */ + public FoLayoutMasterSet + (FOTree foTree, FONode parent, XMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, parent, event, FONode.LAYOUT); + } + + /** + * Set up all the page masters. !!!Note that the masters are not entered + * in the FO tree.!!! + * fo:layout-master-set contents are + * (simple-page-master|page-sequence-master)+ + */ + public void setupPageMasters() throws FOPException { + // Set up a list with the two possibilities + LinkedList list = new LinkedList(); + list.add((Object)(new XMLEvent.UriLocalName + (XMLEvent.XSLNSpaceIndex, "simple-page-master"))); + list.add((Object)(new XMLEvent.UriLocalName + (XMLEvent.XSLNSpaceIndex, "page-sequence-master"))); + try { + do { + FoSimplePageMaster simple; + String simpleName; + FoPageSequenceMaster pageSeq; + XMLEvent ev = + XMLEvent.expectStartElement(xmlevents, list); + if (ev.localName.equals("simple-page-master")) { + System.out.println("Found simple-page-master"); + try { + simple = new FoSimplePageMaster(foTree, this, ev); + } catch (Tree.TreeException e) { + throw new FOPException + ("TreeException: " + e.getMessage()); + } + simpleName = simple.getMasterName(); + if (pageMasters == null) + pageMasters = new HashMap(); + if (pageMasters.get + ((Object)(simpleName)) != null) + throw new FOPException + ("simple-page-master master-name clash in" + + "pageMasters: " + + simpleName); + //pageMasters.put(simpleName, simple); + if (simplePageMasters == null) + simplePageMasters = new HashMap(); + if (simplePageMasters.get + ((Object)(simpleName)) != null) + throw new FOPException + ("simple-page-master master-name clash in " + + "simplePageMasters: " + simpleName); + simplePageMasters.put(simpleName, simple); + FoPageSequenceMaster seqMaster; + try { + // Construct a new PageSequenceMaster + seqMaster = new FoPageSequenceMaster + (foTree, this, simpleName); + } catch(Tree.TreeException e) { + throw new FOPException + ("TreeException: " + e.getMessage()); + } + // Construct a SubSequence + SubSequenceSpecifier subSeq = + seqMaster.new SubSequenceSpecifier(); + // Construct a default ConditionalPageMasterReference + ConditionalPageMasterReference cond = subSeq.new + ConditionalPageMasterReference(simpleName); + pageMasters.put(simpleName, seqMaster); + } else if (ev.localName.equals("page-sequence-master")) { + System.out.println("Found page-sequence-master"); + try { + pageSeq = new FoPageSequenceMaster(foTree, this, ev); + } catch (Tree.TreeException e) { + throw new FOPException + ("TreeException: " + e.getMessage()); + } + if (pageMasters == null) + pageMasters = new HashMap(); + if (pageMasters.get + ((Object)(pageSeq.getMasterName())) != null) + throw new FOPException + ("page-sequence-master master-name clash: " + + pageSeq.getMasterName()); + pageMasters.put + ((Object)(pageSeq.getMasterName()), pageSeq); + } else + throw new FOPException + ("Aargh! expectStartElement(events, list)"); + } while (true); + } catch (NoSuchElementException e) { + // Masters exhausted + } + catch (PropertyException e) { + throw new FOPException("PropertyException: " + e.getMessage()); + } + } + +}// FoLayoutMasterSet diff --git a/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java b/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java new file mode 100644 index 000000000..c3c164dbc --- /dev/null +++ b/src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java @@ -0,0 +1,175 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * + * @author Peter B. West + */ + +package org.apache.fop.fo.pagination; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.NoSuchElementException; + +// FOP +import org.apache.fop.fo.FOAttributes; +import org.apache.fop.xml.XMLEvent; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.FOTree; +import org.apache.fop.fo.FONode; +import org.apache.fop.datastructs.Tree; + +/** + * Implements the fo:page-sequence-master flow object. These Fos are + * children of fo:layout-master-set FOs. Their contents are specified by + * (single-page-master-reference|repeatable-page-master-reference + * |repeatable-page-master-alternatives)+ + * N.B. The FoPageSequenceMaster is a subclass of FONode. + */ +public class FoPageSequenceMaster extends FONode { + + private String masterName; + + private ArrayList subSequenceList = new ArrayList(1); + + public FoPageSequenceMaster + (FOTree foTree, FONode parent, String masterName) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, parent, null, FONode.NONE); + this.masterName = masterName; + } + + public FoPageSequenceMaster(FOTree foTree, FONode parent, XMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, parent, event, FONode.LAYOUT); + if (event == null) { + System.out.println("Null event; throwing FOPException"); + throw new FOPException + ("Null event passed to FoPageSequenceMaster constructor"); + } + try { + masterName = foAttributes.getFoAttrValue("master-name"); + } catch (PropertyException e) { + throw new FOPException(e.getMessage()); + } + // Process sequence members here + LinkedList list = new LinkedList(); + list.add((Object) + (new XMLEvent.UriLocalName + (XMLEvent.XSLNSpaceIndex, "single-page-master-reference"))); + list.add((Object) + (new XMLEvent.UriLocalName + (XMLEvent.XSLNSpaceIndex, + "repeatable-page-master-reference"))); + list.add((Object) + (new XMLEvent.UriLocalName + (XMLEvent.XSLNSpaceIndex, + "repeatable-page-master-alternatives"))); + try { + do { + XMLEvent ev = XMLEvent.expectStartElement(xmlevents, list); + if (ev.localName.equals("single-page-master-reference")) { + System.out.println("Found single-page-master-reference"); + } else if (ev.localName.equals + ("repeatable-page-master-reference")) { + System.out.println + ("Found repeatable-page-master-reference"); + } else if (ev.localName.equals + ("repeatable-page-master-alternatives")) { + System.out.println + ("Found repeatable-page-master-reference"); + } else + throw new FOPException + ("Aargh! expectStartElement(events, list)"); + } while (true); + } catch (NoSuchElementException e) { + // sub-sequence specifiers exhausted + } + XMLEvent ev = XMLEvent.getEndElement(xmlevents, event); + } + + /** + * @return a String with the "master-name" attribute value. + */ + public String getMasterName() { + return masterName; + } + + /** + * SubSequenceSpecifer objects contain the information about an + * individual sub-sequence. They do not extend FONode + * because they are maintained only in the subSequenceList of an + * FoPageSequenceMaster object. + *

When created from fo:single-page-master-reference, + * fo:repeatable-page-master-reference or + * fo:repeatable-page-master-alternatives and + * fo:conditional-page-master-references, the attributes on those + * nodes are merged into the attributes of the parent + * FoPageSequenceMaster object, so that they will be available + * to any children of this node, both + * during the parsing of the fo input and during the page construction + * process. + *

Note that there is some ambiguity about the place of properties + * defined on the members of the layout-master-set subtree. Do + * these properties participate in the properties environment of + * elements in page-sequence subtrees? + */ + public class SubSequenceSpecifier { + public static final int UNBOUNDED = -1; + private int minRepeats = 1; + private int maxRepeats = UNBOUNDED; + private ArrayList conditionals = new ArrayList(1); + + public SubSequenceSpecifier() { + // Insert the SSS into the parent FoPageSequenceMaster's + // list + FoPageSequenceMaster.this.subSequenceList.add(this); + } + + public SubSequenceSpecifier(int maxRepeats) { + this(); + minRepeats = 0; + this.maxRepeats = maxRepeats; + } + + public SubSequenceSpecifier(int minRepeats, int maxRepeats) { + this(maxRepeats); + this.minRepeats = minRepeats; + } + + /** + * ConditionalPageMasterReference objects implement the + * corresponding flow object. The encode a set of conditions in + * the indicated master-reference (to a + * SimplePageMasterReference) will be activated. + */ + public class ConditionalPageMasterReference { + private String masterReference = ""; + private int pagePosition = Properties.PagePosition.ANY; + private int oddOrEven = Properties.OddOrEven.ANY; + private int blankOrNotBlank = Properties.BlankOrNotBlank.ANY; + + public ConditionalPageMasterReference(String masterReference) { + // Insert into including SubSequenceSpecifier's + // conditionals list + SubSequenceSpecifier.this.conditionals.add(this); + this.masterReference = masterReference; + } + + public ConditionalPageMasterReference + (String masterReference, int pagePosition, + int oddOrEven, int blankOrNotBlank) { + this(masterReference); + this.pagePosition = pagePosition; + this.oddOrEven = oddOrEven; + this.blankOrNotBlank = blankOrNotBlank; + } + } + } +} diff --git a/src/org/apache/fop/fo/pagination/FoRepeatablePageMasterAlternatives.java b/src/org/apache/fop/fo/pagination/FoRepeatablePageMasterAlternatives.java new file mode 100644 index 000000000..2be06fae5 --- /dev/null +++ b/src/org/apache/fop/fo/pagination/FoRepeatablePageMasterAlternatives.java @@ -0,0 +1,51 @@ +/* + * FoRepeatablePageMasterAlternatives.java + * Created: Sun Jan 27 01:19:31 2002 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * + * @author + * @version $Revision$ $Name$ + */ + +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.fo.FOAttributes; +import org.apache.fop.xml.XMLEvent; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.datastructs.SyncedCircularBuffer; + +/** + * FoRepeatablePageMasterAlternatives is the class which processes + * and represents the o:repeatable-page-master-alternatives element. + * fo:repeatable-page-master-alternatives is the most flexible of the + * page masters in the layout-master-set. It is also the only sub-sequence + * into which all other sub-sequences can be mapped. Because of this, it + * is the only sub-sequence type actually used. + */ +public class FoRepeatablePageMasterAlternatives { + + private FOAttributes attributes; + private LinkedList conditions; + private int maximumRepeats; + private int minimumRepeats; + + public FoRepeatablePageMasterAlternatives + (FOTree foTree, SyncedCircularBuffer xmlevents, XMLEvent event) + throws FOPException + { + + } + + public void setMinimumRepeats(int min) { + minimumRepeats = min; + } + + public void setMaximumRepeats(int max) { + maximumRepeats = max; + } + +}// FoRepeatablePageMasterAlternatives diff --git a/src/org/apache/fop/fo/pagination/FoSimplePageMaster.java b/src/org/apache/fop/fo/pagination/FoSimplePageMaster.java new file mode 100644 index 000000000..e23120c51 --- /dev/null +++ b/src/org/apache/fop/fo/pagination/FoSimplePageMaster.java @@ -0,0 +1,55 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * + * @author Peter B. West + */ + +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.fo.FOAttributes; +import org.apache.fop.xml.XMLEvent; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FOTree; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.datastructs.Tree; +import org.apache.fop.datastructs.SyncedCircularBuffer; + +/** + * Implements the fo:simple-page-master flow object + */ +public class FoSimplePageMaster extends FONode { + + private String masterName; + + /** + * @param foTree the FO tree being built + * @param parent the parent FONode of this node + * @param event the XMLEvent that triggered the creation of + * this node + */ + public FoSimplePageMaster(FOTree foTree, FONode parent, XMLEvent event) + throws Tree.TreeException, FOPException, PropertyException + { + super(foTree, parent, event, FONode.LAYOUT); + System.out.println("FOAttributes: " + event); + try { + masterName = foAttributes.getFoAttrValue("master-name"); + } catch (PropertyException e) { + throw new FOPException(e.getMessage()); + } + // Process regions here + XMLEvent ev = XMLEvent.getEndElement(xmlevents, event); + } + + /** + * @return a String with the "master-name" attribute value. + */ + public String getMasterName() { + return masterName; + } +} diff --git a/src/org/apache/fop/fo/pagination/FoSinglePageMasterReference.java b/src/org/apache/fop/fo/pagination/FoSinglePageMasterReference.java new file mode 100644 index 000000000..89771e11a --- /dev/null +++ b/src/org/apache/fop/fo/pagination/FoSinglePageMasterReference.java @@ -0,0 +1,35 @@ +/* + * FoSinglePageMasterReference.java + * Created: Sun Jan 27 01:19:31 2002 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * + * @author + * @version $Revision$ $Name$ + */ + +package org.apache.fop.fo.pagination; + +// FOP +import org.apache.fop.fo.FOAttributes; +import org.apache.fop.xml.XMLEvent; +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.datastructs.SyncedCircularBuffer; + +public class FoSinglePageMasterReference implements SubSequenceSpecifier { + + private FOAttributes attributes + private masterReference; + + public FoSinglePageMasterReference + (SyncedCircularBuffer xmlevents, XMLEvent event) throws FOPException { + + } + + public getMasterReference() { + return masterReference; + } + +}// FoSinglePageMasterReference -- 2.39.5