]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Initial commit of experimental page-handling.
authorPeter Bernard West <pbwest@apache.org>
Tue, 7 May 2002 05:50:04 +0000 (05:50 +0000)
committerPeter Bernard West <pbwest@apache.org>
Tue, 7 May 2002 05:50:04 +0000 (05:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194782 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java [new file with mode: 0644]
src/org/apache/fop/fo/pagination/FoLayoutMasterSet.java [new file with mode: 0644]
src/org/apache/fop/fo/pagination/FoPageSequenceMaster.java [new file with mode: 0644]
src/org/apache/fop/fo/pagination/FoRepeatablePageMasterAlternatives.java [new file with mode: 0644]
src/org/apache/fop/fo/pagination/FoSimplePageMaster.java [new file with mode: 0644]
src/org/apache/fop/fo/pagination/FoSinglePageMasterReference.java [new file with mode: 0644]

diff --git a/src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java b/src/org/apache/fop/fo/pagination/FoConditionalPageMasterReference.java
new file mode 100644 (file)
index 0000000..40839eb
--- /dev/null
@@ -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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @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 (file)
index 0000000..592dc50
--- /dev/null
@@ -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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * <tt>FoLayoutMasterSet</tt> is the class which processes the
+ * <i>layout-master-set</i> element.  This is the compulsory first element
+ * under the <i>root</i> 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 <tt>XMLEvent</tt> 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 (file)
index 0000000..c3c164d
--- /dev/null
@@ -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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ */
+
+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 <tt>String</tt> with the "master-name" attribute value.
+     */
+    public String getMasterName() {
+        return masterName;
+    }
+
+    /**
+     * <i>SubSequenceSpecifer</i> objects contain the information about an
+     * individual sub-sequence.  They do <i>not</i> extend <tt>FONode</tt>
+     * because they are maintained only in the <i>subSequenceList</i> of an
+     * <tt>FoPageSequenceMaster</tt> object.
+     * <p>When created from <i>fo:single-page-master-reference</i>,
+     * <i>fo:repeatable-page-master-reference</i> or
+     * <i>fo:repeatable-page-master-alternatives</i> and
+     * <i>fo:conditional-page-master-reference</i>s, the attributes on those
+     * nodes are merged into the attributes of the parent
+     * <tt>FoPageSequenceMaster</tt> 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.
+     * <p>Note that there is some ambiguity about the place of properties
+     * defined on the members of the <i>layout-master-set</i> 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;
+        }
+
+        /**
+         * <i>ConditionalPageMasterReference</i> objects implement the
+         * corresponding flow object.  The encode a set of conditions in
+         * the indicated master-reference (to a
+         * <tt>SimplePageMasterReference</tt>) 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 (file)
index 0000000..2be06fa
--- /dev/null
@@ -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 <a href="mailto: "Peter B. West</a>
+ * @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;
+
+/**
+ * <i>FoRepeatablePageMasterAlternatives</i> is the class which processes
+ * and represents the <i>o:repeatable-page-master-alternatives</i> 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 (file)
index 0000000..e23120c
--- /dev/null
@@ -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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ */
+
+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 <tt>XMLEvent</tt> 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 <tt>String</tt> 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 (file)
index 0000000..89771e1
--- /dev/null
@@ -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 <a href="mailto: "Peter B. West</a>
+ * @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