import org.xml.sax.Attributes;
+/**
+ * A conditional-page-master-reference formatting object.
+ * This is a reference to a page master with a set of conditions.
+ * The conditions must be satisfied for the referenced master to
+ * be used.
+ * This element is must be the child of a repeatable-page-master-alternatives
+ * element.
+ */
public class ConditionalPageMasterReference extends FObj {
private RepeatablePageMasterAlternatives repeatablePageMasterAlternatives;
public ConditionalPageMasterReference(FONode parent) {
super(parent);
-
- this.name = getElementName();
}
public void handleAttrs(Attributes attlist) throws FOPException {
return masterName;
}
-
+ /**
+ * Check if the conditions for this reference are met.
+ * checks the page number and emptyness to determine if this
+ * matches.
+ */
protected boolean isValid(int currentPageNumber, boolean thisIsFirstPage,
boolean isEmptyPage) {
// page-position
return this.blankOrNotBlank;
}
- protected String getElementName() {
- return "fo:conditional-page-master-reference";
- }
-
-
+ /**
+ * Check that the parent is the right type of formatting object
+ * repeatable-page-master-alternatives.
+ */
protected void validateParent(FONode parent) throws FOPException {
if (parent.getName().equals("fo:repeatable-page-master-alternatives")) {
this.repeatablePageMasterAlternatives =
}
}
-
}
import org.xml.sax.Attributes;
+/**
+ * The layout-master-set formatting object.
+ * This class maintains the set of simple page master and
+ * page sequence masters.
+ * The masters are stored so that the page sequence can obtain
+ * the required page master to create a page.
+ * The page sequence masters can be reset as they hold state
+ * information for a page sequence.
+ */
public class LayoutMasterSet extends FObj {
-
private HashMap simplePageMasters;
private HashMap pageSequenceMasters;
private HashMap allRegions;
- private Root root;
-
public LayoutMasterSet(FONode parent) {
super(parent);
}
public void handleAttrs(Attributes attlist) throws FOPException {
super.handleAttrs(attlist);
- this.simplePageMasters = new HashMap();
- this.pageSequenceMasters = new HashMap();
if (parent.getName().equals("fo:root")) {
- this.root = (Root)parent;
+ Root root = (Root)parent;
root.setLayoutMasterSet(this);
} else {
throw new FOPException("fo:layout-master-set must be child of fo:root, not "
+ parent.getName());
}
- allRegions = new HashMap();
+ this.simplePageMasters = new HashMap();
+ this.pageSequenceMasters = new HashMap();
+ allRegions = new HashMap();
}
+ /**
+ * Add a simple page master.
+ * The name is checked to throw an error if already added.
+ */
protected void addSimplePageMaster(SimplePageMaster simplePageMaster)
throws FOPException {
// check against duplication of master-name
simplePageMaster);
}
+ /**
+ * Get a simple page master by name.
+ * This is used by the page sequence to get a page master for
+ * creating pages.
+ */
protected SimplePageMaster getSimplePageMaster(String masterName) {
return (SimplePageMaster)this.simplePageMasters.get(masterName);
}
+ /**
+ * Add a page sequence master.
+ * The name is checked to throw an error if already added.
+ */
protected void addPageSequenceMaster(String masterName, PageSequenceMaster pageSequenceMaster)
throws FOPException {
// check against duplication of master-name
this.pageSequenceMasters.put(masterName, pageSequenceMaster);
}
+ /**
+ * Get a page sequence master by name.
+ * This is used by the page sequence to get a page master for
+ * creating pages.
+ */
protected PageSequenceMaster getPageSequenceMaster(String masterName) {
return (PageSequenceMaster)this.pageSequenceMasters.get(masterName);
}
return false;
}
+ /**
+ * Reset the state of the page sequence masters.
+ * Use when starting a new page sequence.
+ */
protected void resetPageMasters() {
for (Iterator e = pageSequenceMasters.values().iterator();
e.hasNext(); ) {
public PageMasterReference(FONode parent) {
super(parent);
- this.name = getElementName();
}
public void handleAttrs(Attributes attlist) throws FOPException {
boolean thisIsFirstPage,
boolean isEmptyPage);
- /**
- * Gets the formating object name for this object.
- * Subclasses must provide this.
- *
- * @return the element name of this reference.
- * e.g. fo:repeatable-page-master-reference
- */
- protected abstract String getElementName();
-
/**
* Checks that the parent is the right element. The default implementation
* checks for fo:page-sequence-master
_pageSequenceMaster = (PageSequenceMaster)parent;
if (getMasterName() == null) {
- log.warn("" + getElementName()
+ log.warn("" + getName()
+ " does not have a master-reference and so is being ignored");
} else {
_pageSequenceMaster.addSubsequenceSpecifier(this);
}
} else {
- throw new FOPException(getElementName() + " must be"
+ throw new FOPException(getName() + " must be"
+ "child of fo:page-sequence-master, not "
+ parent.getName());
}
import org.apache.fop.layoutmgr.PageLayoutManager;
// Java
-import java.util.*;
+import java.util.HashMap;
import org.xml.sax.Attributes;
}
-
-
// /**
// * Return children for layout. Only the main flow is laid out directly.
// */
// }
/**
- * Returns the next SubSequenceSpecifier for the given page sequence master. The result
- * is bassed on the current state of this page sequence.
+ * Returns the next SubSequenceSpecifier for the given page sequence master.
+ * The result is bassed on the current state of this page sequence.
*/
- // refactored from PageSequenceMaster
private SubSequenceSpecifier getNextSubsequence(PageSequenceMaster master) {
if (master.getSubSequenceSpecifierCount()
> currentSubsequenceNumber + 1) {
} else {
return null;
}
-
}
/**
}
+ /**
+ * Get the next page master name.
+ * This gets the name of the next page master. If the sequence
+ * is exhausted then an error is indicated and the last page
+ * master name is used.
+ */
private String getNextPageMasterName(PageSequenceMaster sequenceMaster,
int currentPageNumber,
boolean thisIsFirstPage,
import org.apache.fop.apps.FOPException;
// Java
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
import org.xml.sax.Attributes;
+/**
+ * The page-sequence-master formatting object.
+ * This class handles a list of subsequence specifiers
+ * which are simple or complex references to page-masters.
+ */
public class PageSequenceMaster extends FObj {
-
LayoutMasterSet layoutMasterSet;
- Vector subSequenceSpecifiers;
-
+ ArrayList subSequenceSpecifiers;
// The terminology may be confusing. A 'page-sequence-master' consists
// of a sequence of what the XSL spec refers to as
public void handleAttrs(Attributes attlist) throws FOPException {
super.handleAttrs(attlist);
- subSequenceSpecifiers = new Vector();
+ subSequenceSpecifiers = new ArrayList();
if (parent.getName().equals("fo:layout-master-set")) {
this.layoutMasterSet = (LayoutMasterSet)parent;
String pm = this.properties.get("master-name").getString();
if (pm == null) {
log.warn("page-sequence-master does not have "
- + "a page-master-name and so is being ignored");
+ + "a master-name and so is being ignored");
} else {
this.layoutMasterSet.addPageSequenceMaster(pm, this);
}
}
protected void addSubsequenceSpecifier(SubSequenceSpecifier pageMasterReference) {
- subSequenceSpecifiers.addElement(pageMasterReference);
+ subSequenceSpecifiers.add(pageMasterReference);
}
protected SubSequenceSpecifier getSubSequenceSpecifier(int sequenceNumber) {
if (sequenceNumber >= 0
&& sequenceNumber < getSubSequenceSpecifierCount()) {
- return (SubSequenceSpecifier)subSequenceSpecifiers.elementAt(sequenceNumber);
+ return (SubSequenceSpecifier)subSequenceSpecifiers.get(sequenceNumber);
}
return null;
-
-
}
protected int getSubSequenceSpecifierCount() {
}
public void reset() {
- for (Enumeration e = subSequenceSpecifiers.elements();
- e.hasMoreElements(); ) {
- ((SubSequenceSpecifier)e.nextElement()).reset();
+ for (Iterator e = subSequenceSpecifiers.iterator();
+ e.hasNext(); ) {
+ ((SubSequenceSpecifier)e.next()).reset();
}
-
}
-
-
}
+
import org.apache.fop.area.RegionViewport;
import org.apache.fop.area.RegionReference;
-
import org.xml.sax.Attributes;
/**
+ "of simple-page-master, not "
+ parent.getName());
}
-
}
-
/**
* Creates a RegionViewport Area object for this pagination Region.
*/
// this.properties.get("clip");
// this.properties.get("display-align");
- // this.properties.get("overflow");
this.overflow = this.properties.get("overflow").getEnum();
- // this.properties.get("region-name");
// this.properties.get("reference-orientation");
// this.properties.get("writing-mode");
import org.apache.fop.apps.FOPException;
// Java
-import java.util.Vector;
+import java.util.ArrayList;
import org.xml.sax.Attributes;
+/**
+ * A repeatable-page-master-alternatives formatting object.
+ * This contains a list of conditional-page-master-reference
+ * and the page master is found from the reference that
+ * matches the page number and emptyness.
+ */
public class RepeatablePageMasterAlternatives extends FObj
implements SubSequenceSpecifier {
private int maximumRepeats;
private int numberConsumed = 0;
- private Vector conditionalPageMasterRefs;
+ private ArrayList conditionalPageMasterRefs;
public RepeatablePageMasterAlternatives(FONode parent) {
super(parent);
public void handleAttrs(Attributes attlist) throws FOPException {
super.handleAttrs(attlist);
- conditionalPageMasterRefs = new Vector();
+ conditionalPageMasterRefs = new ArrayList();
if (parent.getName().equals("fo:page-sequence-master")) {
this.pageSequenceMaster = (PageSequenceMaster)parent;
+ "'maximum-repeats' property");
}
}
-
}
+ /**
+ * Get the next matching page master from the conditional
+ * page master references.
+ */
public String getNextPageMaster(int currentPageNumber,
boolean thisIsFirstPage,
boolean isEmptyPage) {
for (int i = 0; i < conditionalPageMasterRefs.size(); i++) {
ConditionalPageMasterReference cpmr =
- (ConditionalPageMasterReference)conditionalPageMasterRefs.elementAt(i);
+ (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i);
// 0-indexed page number
if (cpmr.isValid(currentPageNumber + 1, thisIsFirstPage,
} else {
this.maximumRepeats = (maximumRepeats < 0) ? 0 : maximumRepeats;
}
-
}
private int getMaximumRepeats() {
}
public void addConditionalPageMasterReference(ConditionalPageMasterReference cpmr) {
- this.conditionalPageMasterRefs.addElement(cpmr);
+ this.conditionalPageMasterRefs.add(cpmr);
}
public void reset() {
this.numberConsumed = 0;
}
-
protected PageSequenceMaster getPageSequenceMaster() {
return pageSequenceMaster;
}
import org.xml.sax.Attributes;
+/**
+ * A repeatable-page-master-reference formatting object.
+ * This handles a reference with a specified number of repeating
+ * instances of the referenced page master (may have no limit).
+ */
public class RepeatablePageMasterReference extends PageMasterReference
implements SubSequenceSpecifier {
+ "'maximum-repeats' property");
}
}
-
}
public String getNextPageMaster(int currentPageNumber,
return this.maximumRepeats;
}
- protected String getElementName() {
- return "fo:repeatable-page-master-reference";
- }
-
public void reset() {
this.numberConsumed = 0;
}
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.AreaTree;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.extensions.ExtensionObj;
// Java
import java.util.ArrayList;
/**
- * The fo:root formatting object. Contains page masters, root extensions,
- * page-sequences.
+ * The fo:root formatting object. Contains page masters, page-sequences.
*/
public class Root extends FObj {
import java.util.Iterator;
import org.xml.sax.Attributes;
-
+/**
+ * A simple-page-master formatting object.
+ * This creates a simple page from the specified regions
+ * and attributes.
+ */
public class SimplePageMaster extends FObj {
-
/**
* Page regions (regionClass, Region)
*/
private HashMap _regions;
- LayoutMasterSet layoutMasterSet;
PageMaster pageMaster;
String masterName;
super.handleAttrs(attlist);
if (parent.getName().equals("fo:layout-master-set")) {
- this.layoutMasterSet = (LayoutMasterSet)parent;
+ LayoutMasterSet layoutMasterSet = (LayoutMasterSet)parent;
masterName = this.properties.get("master-name").getString();
if (masterName == null) {
log.warn("simple-page-master does not have "
+ "a master-name and so is being ignored");
} else {
- this.layoutMasterSet.addSimplePageMaster(this);
+ layoutMasterSet.addSimplePageMaster(this);
}
} else {
throw new FOPException("fo:simple-page-master must be child "
+ parent.getName());
}
_regions = new HashMap();
-
}
+ /**
+ * At the end of this element read all the information and create
+ * the page master.
+ */
protected void end() {
int pageWidth =
this.properties.get("page-width").getLength().mvalue();
MarginProps mProps = propMgr.getMarginProps();
/* Create the page reference area rectangle in first quadrant coordinates
- * (ie, 0,0 is at bottom,left of the "page meida" and y increases
+ * (ie, 0,0 is at bottom,left of the "page media" and y increases
* when moving towards the top of the page.
* The media rectangle itself is (0,0,pageWidth,pageHeight).
*/
this.pageMaster = new PageMaster(new PageViewport(page,
new Rectangle(0,0,
pageWidth,pageHeight)));
+
+ _regions = null;
+ children = null;
+ properties = null;
}
public PageMaster getPageMaster() {
return masterName;
}
-
protected void addChild(FONode child) {
if (child instanceof Region) {
addRegion((Region)child);
}
}
return false;
-
}
-
}
+
*/
package org.apache.fop.fo.pagination;
-import org.apache.fop.fo.*;
-import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.FONode;
+/**
+ * A single-page-master-reference formatting object.
+ * This is a reference for a single page. It returns the
+ * master name only once until reset.
+ */
public class SinglePageMasterReference extends PageMasterReference
implements SubSequenceSpecifier {
} else {
return null;
}
-
}
public void reset() {
this.state = FIRST;
}
-
- protected String getElementName() {
- return "fo:single-page-master-reference";
- }
-
}
+