From 5bebce9f044d1df718aa10eec0483729ff23f6d2 Mon Sep 17 00:00:00 2001 From: arved Date: Tue, 10 Oct 2000 02:11:25 +0000 Subject: [PATCH] region-name/multiple flow support git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_14_0_regions@193719 13f79535-47bb-0310-9956-ffa450edef68 --- src/codegen/properties.xml | 8 + .../fop/fo/StandardPropertyListMapping.java | 2 + src/org/apache/fop/fo/flow/Flow.java | 29 ++- src/org/apache/fop/fo/flow/StaticContent.java | 22 ++- .../ConditionalPageMasterReference.java | 4 +- .../fop/fo/pagination/LayoutMasterSet.java | 61 +++++++ .../fop/fo/pagination/PageSequence.java | 171 +++++++++++++++--- .../fop/fo/pagination/PageSequenceMaster.java | 27 ++- .../apache/fop/fo/pagination/RegionAfter.java | 27 ++- .../fop/fo/pagination/RegionBefore.java | 27 ++- .../apache/fop/fo/pagination/RegionBody.java | 26 +++ .../RepeatablePageMasterReference.java | 2 +- .../fop/fo/pagination/SimplePageMaster.java | 65 ++++++- .../pagination/SinglePageMasterReference.java | 2 +- 14 files changed, 424 insertions(+), 49 deletions(-) diff --git a/src/codegen/properties.xml b/src/codegen/properties.xml index a08505b25..ca76d6eae 100644 --- a/src/codegen/properties.xml +++ b/src/codegen/properties.xml @@ -966,6 +966,14 @@ auto + + region-name + RegionName + false + String + + + diff --git a/src/org/apache/fop/fo/StandardPropertyListMapping.java b/src/org/apache/fop/fo/StandardPropertyListMapping.java index c1d52d141..47beac469 100644 --- a/src/org/apache/fop/fo/StandardPropertyListMapping.java +++ b/src/org/apache/fop/fo/StandardPropertyListMapping.java @@ -165,6 +165,8 @@ public class StandardPropertyListMapping implements PropertyListMapping { propertyTable.put("scaling",Scaling.maker()); propertyTable.put("vertical-align",VerticalAlign.maker()); propertyTable.put("overflow",Overflow.maker()); + propertyTable.put("region-name",RegionName.maker()); + builder.addPropertyList(uri, propertyTable); } } diff --git a/src/org/apache/fop/fo/flow/Flow.java b/src/org/apache/fop/fo/flow/Flow.java index 3d68ef470..d7072635b 100644 --- a/src/org/apache/fop/fo/flow/Flow.java +++ b/src/org/apache/fop/fo/flow/Flow.java @@ -76,12 +76,16 @@ public class Flow extends FObj { } PageSequence pageSequence; - + protected String flowName; + protected Status currentStatus; + protected Flow(FObj parent, PropertyList propertyList) throws FOPException { super(parent, propertyList); this.name = "fo:flow"; + currentStatus = new Status(Status.AREA_FULL_NONE); + if (parent.getName().equals("fo:page-sequence")) { this.pageSequence = (PageSequence) parent; } else { @@ -89,7 +93,13 @@ public class Flow extends FObj { + "page-sequence, not " + parent.getName()); } - pageSequence.setFlow(this); + flowName = this.properties.get("flow-name").getString(); + if (flowName.equals("")) + { + throw new FOPException("A 'flow-name' is required for fo:flow"); + } + + pageSequence.setFlow(flowName, this); } public Status layout(Area area) throws FOPException { @@ -128,4 +138,19 @@ public class Flow extends FObj { } return new Status(Status.OK); } + + public Status getCurrentStatus() + { + return currentStatus; + } + + public void setCurrentStatus(Status currentStatus) + { + this.currentStatus = currentStatus; + } + + public String getFlowName() + { + return flowName; + } } diff --git a/src/org/apache/fop/fo/flow/StaticContent.java b/src/org/apache/fop/fo/flow/StaticContent.java index 9394c21d7..dcc829a64 100644 --- a/src/org/apache/fop/fo/flow/StaticContent.java +++ b/src/org/apache/fop/fo/flow/StaticContent.java @@ -74,7 +74,8 @@ public class StaticContent extends FObj { } PageSequence pageSequence; - + String regionClass; + protected StaticContent(FObj parent, PropertyList propertyList) throws FOPException { super(parent, propertyList); @@ -88,14 +89,20 @@ public class StaticContent extends FObj { + parent.getName()); } String flowName = this.properties.get("flow-name").getString(); + if (flowName.equals("")) + { + throw new FOPException("A 'flow-name' is required for " + + "fo:static-content"); + } - pageSequence.setStaticContent(flowName, this); + regionClass = pageSequence.setStaticContent(flowName, this); } public Status layout(Area area) throws FOPException { int numChildren = this.children.size(); // Set area absolute height so that link rectangles will be drawn correctly in xsl-before and xsl-after + /* String flowName = this.properties.get("flow-name").getString(); if(flowName.equals("xsl-region-before")) { @@ -105,7 +112,16 @@ public class StaticContent extends FObj { { area.setAbsoluteHeight(area.getPage().getBody().getMaxHeight()); } - + */ + if(regionClass.equals("before")) + { + area.setAbsoluteHeight(-area.getMaxHeight()); + } + else if(regionClass.equals("after")) + { + area.setAbsoluteHeight(area.getPage().getBody().getMaxHeight()); + } + for (int i = 0; i < numChildren; i++) { FObj fo = (FObj) children.elementAt(i); diff --git a/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java b/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java index 5db191dfe..4be8320e9 100644 --- a/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java @@ -85,8 +85,8 @@ public class ConditionalPageMasterReference this.repeatablePageMasterAlternatives = (RepeatablePageMasterAlternatives) parent; setMasterName( this.properties.get("master-name").getString() ); - if (getMasterName() == null) { - System.err.println("WARNING: single-page-master-reference" + + if (getMasterName().equals("")) { + System.err.println("WARNING: conditional-page-master-reference" + "does not have a master-name and so is being ignored"); } else { this.repeatablePageMasterAlternatives.addConditionalPageMasterReference(this); diff --git a/src/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/org/apache/fop/fo/pagination/LayoutMasterSet.java index b0f8c32de..b89a98770 100644 --- a/src/org/apache/fop/fo/pagination/LayoutMasterSet.java +++ b/src/org/apache/fop/fo/pagination/LayoutMasterSet.java @@ -59,6 +59,8 @@ import org.apache.fop.apps.FOPException; // Java import java.util.Hashtable; +import java.util.Enumeration; +import java.util.Vector; public class LayoutMasterSet extends FObj { @@ -76,6 +78,8 @@ public class LayoutMasterSet extends FObj { private Hashtable simplePageMasters; private Hashtable pageSequenceMasters; private Root root; + private String currentPageMasterName; + private Hashtable allRegions; protected LayoutMasterSet(FObj parent, PropertyList propertyList) throws FOPException { @@ -84,6 +88,7 @@ public class LayoutMasterSet extends FObj { this.simplePageMasters = new Hashtable(); this.pageSequenceMasters = new Hashtable(); + this.allRegions = new Hashtable(); if (parent.getName().equals("fo:root")) { this.root = (Root)parent; @@ -105,6 +110,8 @@ public class LayoutMasterSet extends FObj { if (null != psm) { pm = psm.getNextPageMaster( currentPageNumber, thisIsFirstPage ); + // call in this sequence + currentPageMasterName = psm.getNextPageMasterName(); } else { SimplePageMaster spm = getSimplePageMaster( pageSequenceName ); if (null == spm) @@ -112,6 +119,7 @@ public class LayoutMasterSet extends FObj { throw new FOPException( "'master-name' for 'fo:page-sequence'" + "matches no 'simple-page-master' or 'page-sequence-master'" ); } + currentPageMasterName = spm.getMasterName(); pm = spm.getNextPageMaster(); } return pm; @@ -124,6 +132,7 @@ public class LayoutMasterSet extends FObj { if (existsName(masterName)) throw new FOPException( "'master-name' must be unique" + "across page-masters and page-sequence-masters" ); + this.simplePageMasters.put(masterName, simplePageMaster); } @@ -153,4 +162,56 @@ public class LayoutMasterSet extends FObj { else return false; } + + public Vector findPageMasterNames( String flowName ) + { + Vector results = new Vector(); + for (Enumeration e = simplePageMasters.elements(); e.hasMoreElements(); ) + { + SimplePageMaster spm = (SimplePageMaster)e.nextElement(); + if (spm.getRegions().containsKey(flowName)) + { + results.addElement(spm.getMasterName()); + } + } + return results; + } + + public String regionNameMapsTo( String pageMasterName, String flowName) + { + SimplePageMaster spm = (SimplePageMaster)simplePageMasters.get(pageMasterName); + Hashtable regions = spm.getRegions(); + return (String)regions.get(flowName); + } + + public String getCurrentPageMasterName() + { + return currentPageMasterName; + } + + public void checkRegionNames() throws FOPException + { + // Section 7.33.15 check to see that if a region-name is a + // duplicate, that it maps to the same region-class. + for (Enumeration spm = simplePageMasters.elements(); spm.hasMoreElements(); ) + { + SimplePageMaster simplePageMaster = (SimplePageMaster)spm.nextElement(); + Hashtable spmRegions = simplePageMaster.getRegions(); + for (Enumeration e = spmRegions.keys(); e.hasMoreElements(); ) + { + String regionName = (String)e.nextElement(); + String regionClass = (String)spmRegions.get(regionName); + if (allRegions.containsKey(regionName)) + { + String localClass = (String)allRegions.get(regionName); + if (!localClass.equals(regionClass)) + { + throw new FOPException("Duplicate region-names must map " + + "to the same region-class"); + } + } + allRegions.put(regionName,regionClass); + } + } + } } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index da51a47cd..6cdc6be50 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -67,6 +67,7 @@ import org.apache.fop.apps.FOPException; // Java import java.util.Hashtable; import java.util.Vector; +import java.util.Enumeration; public class PageSequence extends FObj { @@ -89,13 +90,23 @@ public class PageSequence extends FObj static final int AUTO_ODD = 3; protected Root root; - protected Flow flow; + // protected Flow flow; + // (001008) language in spec suggests that page sequence must have at + // least one flow, but may have more. The contents BNF in section + // 6.4.5 of the spec is likely incorrect. + protected Hashtable flows; // protected Title title; - protected StaticContent staticBefore; - protected StaticContent staticAfter; + + protected Hashtable beforeStaticContents; + protected Hashtable afterStaticContents; protected LayoutMasterSet layoutMasterSet; protected String masterName; + // used for mapping regions <=> static contents in correct SPM + protected String currentPageMasterName; + + protected Hashtable flowNames; + protected Page currentPage; protected int currentPageNumber = 0; protected static int runningPageNumberCounter = 0; //keeps count of page number from previous PageSequence @@ -107,6 +118,12 @@ public class PageSequence extends FObj super(parent, propertyList); this.name = "fo:page-sequence"; + // region support + flowNames = new Hashtable(); // all 'flow-name's in this page sequence + beforeStaticContents = new Hashtable(); + afterStaticContents = new Hashtable(); + flows = new Hashtable(); // all Flow's in this page sequence + if ( parent.getName().equals("fo:root") ) { this.runningPageNumberCounter=0; //else not initialized correctly @@ -121,6 +138,9 @@ public class PageSequence extends FObj } layoutMasterSet = root.getLayoutMasterSet(); + // best time to run some checks on LayoutMasterSet + layoutMasterSet.checkRegionNames(); + thisIsFirstPage=true; // we are now on the first page of the page sequence InitialPageNumber ipn = (InitialPageNumber) this.properties.get("initial-page-number"); String ipnValue=ipn.getString(); @@ -164,7 +184,10 @@ public class PageSequence extends FObj PageMaster pageMaster = this.layoutMasterSet.getNextPageMaster( masterName, currentPageNumber, thisIsFirstPage ); - + + // store the current 'master-name' for access by format() + currentPageMasterName = this.layoutMasterSet.getCurrentPageMasterName(); + // a legal alternative is to use the last sub-sequence // specification. That's not done here. if ( pageMaster == null ) @@ -210,57 +233,153 @@ public class PageSequence extends FObj this.runningPageNumberCounter=this.currentPageNumber; MessageHandler.log(" [" + currentPageNumber); - if ( (this.staticBefore != null) && + if ( (!this.beforeStaticContents.isEmpty()) && (currentPage.getBefore() != null) ) { AreaContainer beforeArea = currentPage.getBefore(); beforeArea.setIDReferences(areaTree.getIDReferences()); - this.staticBefore.layout(beforeArea); + // locate the correct fo:static-content from the "beforeStaticContents" + // Hashtable, using the "currentPageMasterName" as the key. + StaticContent before = + (StaticContent)this.beforeStaticContents.get(currentPageMasterName); + if (null == before) + MessageHandler.errorln("No static-content found for region-before " + + "in page-master '" + currentPageMasterName + "'"); + else + before.layout(beforeArea); } - if ( (this.staticAfter != null) && + if ( (!this.beforeStaticContents.isEmpty()) && (currentPage.getAfter() != null) ) { AreaContainer afterArea = currentPage.getAfter(); afterArea.setIDReferences(areaTree.getIDReferences()); - this.staticAfter.layout(afterArea); + // locate the correct fo:static-content from the "afterStaticContents" + // Hashtable, using the "currentPageMasterName" as the key. + StaticContent after = + (StaticContent)this.afterStaticContents.get(currentPageMasterName); + if (null == after) + MessageHandler.errorln("No static-content found for region-after " + + "in page-master '" + currentPageMasterName + "'"); + else + after.layout(afterArea); } if ( (status.getCode() == Status.FORCE_PAGE_BREAK_EVEN) && ((currentPageNumber % 2) == 1) ) { + // linkage to ConditionalPageMasterReference for blank pages? } else if ( (status.getCode() == Status.FORCE_PAGE_BREAK_ODD) && ((currentPageNumber % 2) == 0) ) { + // linkage to ConditionalPageMasterReference for blank pages? } else { AreaContainer bodyArea = currentPage.getBody(); bodyArea.setIDReferences(areaTree.getIDReferences()); - status = this.flow.layout(bodyArea); + // locate the correct fo:flow from the "flows" + // Hashtable, using the "currentPageMasterName" as the key. + Flow flow = + (Flow)this.flows.get(currentPageMasterName); + if (null == flow) + MessageHandler.errorln("No flow found for region-body " + + "in page-master '" + currentPageMasterName + "'"); + else + { + status = flow.layout(bodyArea); + flow.setCurrentStatus(status); + } } MessageHandler.log("]"); areaTree.addPage(currentPage); - } while ( status.isIncomplete() ); + } while ( flowsAreIncomplete() ); MessageHandler.errorln(""); } - public void setFlow(Flow flow) { - this.flow = flow; + public void setFlow(String name, Flow flow) + throws FOPException { + + if (flowNames.containsKey(name)) + { + throw new FOPException("flow-names must be unique within an fo:page-sequence"); + } + + // store the Flow against the SimplePageMaster(s) that contain(s) it + Vector pageMasterNames = this.layoutMasterSet.findPageMasterNames(name); + if (pageMasterNames.isEmpty()) + { + MessageHandler.errorln("flow-name maps to no region(s) in page-masters"); + } + else + { + for (Enumeration e = pageMasterNames.elements(); e.hasMoreElements(); ) + { + String pageMasterName = (String)e.nextElement(); + if (this.layoutMasterSet.regionNameMapsTo(pageMasterName,name).equals("fo:region-body")) + { + flows.put(pageMasterName,flow); + flowNames.put(name,"body"); + } + else + { + MessageHandler.errorln("Flow flow-name does not map to fo:region-body"); + flowNames.put(name,"unsupported"); + } + } + } } - public void setStaticContent(String name, StaticContent staticContent) { - if ( name.equals("xsl-region-before") ) - { - this.staticBefore = staticContent; - } - else if ( name.equals("xsl-region-after") ) - { - this.staticAfter = staticContent; - } - else - { - MessageHandler.errorln("WARNING: this version of FOP only supports " - + "static-content in xsl-region-before and xsl-region-after"); - } + public String setStaticContent(String name, StaticContent staticContent) + throws FOPException { + + // region class that static content maps to + String regionClass = null; + + // store the flow name + if (flowNames.containsKey(name)) + { + throw new FOPException("flow-names must be unique within an fo:page-sequence"); + } + + // store the StaticContent against the SimplePageMaster(s) that contain(s) it + Vector pageMasterNames = this.layoutMasterSet.findPageMasterNames(name); + if (pageMasterNames.isEmpty()) + { + MessageHandler.errorln("flow-name maps to no region(s) in page-masters"); + } + else + { + for (Enumeration e = pageMasterNames.elements(); e.hasMoreElements(); ) + { + String pageMasterName = (String)e.nextElement(); + if (this.layoutMasterSet.regionNameMapsTo(pageMasterName,name).equals("fo:region-before")) + { + beforeStaticContents.put(pageMasterName,staticContent); + regionClass = "before"; + } + else if (this.layoutMasterSet.regionNameMapsTo(pageMasterName,name).equals("fo:region-after")) + { + afterStaticContents.put(pageMasterName,staticContent); + regionClass = "after"; + } + else + { + MessageHandler.errorln("StaticContent flow-name maps to unsupported region"); + regionClass = "unsupported"; + } + flowNames.put(name,regionClass); + } + } + return regionClass; } + + public boolean flowsAreIncomplete() + { + boolean isIncomplete = false; + for (Enumeration e = flows.elements(); e.hasMoreElements(); ) + { + isIncomplete = ((Flow)e.nextElement()).getCurrentStatus().isIncomplete(); + } + return isIncomplete; + } } diff --git a/src/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/org/apache/fop/fo/pagination/PageSequenceMaster.java index 1090d9f3e..735304888 100644 --- a/src/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -77,7 +77,11 @@ public class PageSequenceMaster extends FObj { LayoutMasterSet layoutMasterSet; Vector subSequenceSpecifiers; SubSequenceSpecifier currentPmr; - + + // SimplePageMasters are not exposed outside this class. Hence, this + // variable tracks the current master-name for the last SPM. + String currentPageMasterName; + // The terminology may be confusing. A 'page-sequence-master' consists // of a sequence of what the XSL spec refers to as // 'sub-sequence-specifiers'. These are, in fact, simple or complex @@ -94,7 +98,7 @@ public class PageSequenceMaster extends FObj { if (parent.getName().equals("fo:layout-master-set")) { this.layoutMasterSet = (LayoutMasterSet) parent; String pm = this.properties.get("master-name").getString(); - if (pm == null) { + if (pm.equals("")) { System.err.println("WARNING: page-sequence-master does not have " + "a page-master-name and so is being ignored"); } else { @@ -109,12 +113,13 @@ public class PageSequenceMaster extends FObj { protected void addSubsequenceSpecifier( SubSequenceSpecifier pageMasterReference ) { - subSequenceSpecifiers.add( pageMasterReference ); + subSequenceSpecifiers.addElement( pageMasterReference ); } protected SubSequenceSpecifier getNextSubsequenceSpecifier() { - currentPmr = (SubSequenceSpecifier)subSequenceSpecifiers.remove( 0 ); + currentPmr = (SubSequenceSpecifier)subSequenceSpecifiers.elementAt( 0 ); + subSequenceSpecifiers.removeElementAt(0); return currentPmr; } @@ -135,6 +140,18 @@ public class PageSequenceMaster extends FObj { currentPmr.getNextPageMaster( currentPageNumber, thisIsFirstPage ); } - return this.layoutMasterSet.getSimplePageMaster( nextPageMaster ).getPageMaster(); + SimplePageMaster spm = this.layoutMasterSet.getSimplePageMaster( nextPageMaster ); + currentPageMasterName = spm.getMasterName(); // store for outside access + return spm.getPageMaster(); } + + /** + * Return the 'master-name' for the last SimplePageMaster + * processed in this class + * @returns String master name for last SPM + */ + public String getNextPageMasterName() + { + return currentPageMasterName; + } } diff --git a/src/org/apache/fop/fo/pagination/RegionAfter.java b/src/org/apache/fop/fo/pagination/RegionAfter.java index 9b8872e1f..a18054ea4 100644 --- a/src/org/apache/fop/fo/pagination/RegionAfter.java +++ b/src/org/apache/fop/fo/pagination/RegionAfter.java @@ -69,12 +69,32 @@ public class RegionAfter extends FObj { } SimplePageMaster layoutMaster; - + String regionName; + protected RegionAfter(FObj parent, PropertyList propertyList) throws FOPException { super(parent, propertyList); this.name = "fo:region-after"; + // regions may have name, or default + if (null == this.properties.get("region-name")) + regionName = "xsl-region-after"; + else if (this.properties.get("region-name").getString().equals("")) + regionName = "xsl-region-after"; + else + { + regionName = this.properties.get("region-name").getString(); + // check that name is OK. Not very pretty. + if (regionName.equals( "xsl-region-before" ) || regionName.equals( "xsl-region-start" ) + || regionName.equals( "xsl-region-end" ) || regionName.equals( "xsl-region-body" ) + || regionName.equals( "xsl-before-float-separator" ) + || regionName.equals( "xsl-footnote-separator" )) + { + throw new FOPException("region-name '" + regionName + + "' for fo:region-after not permitted."); + } + } + if (parent.getName().equals("fo:simple-page-master")) { this.layoutMaster = (SimplePageMaster) parent; this.layoutMaster.setRegionAfter(this); @@ -101,4 +121,9 @@ public class RegionAfter extends FObj { allocationRectangleWidth - marginLeft - marginRight,extent); } + + public String getRegionName() + { + return regionName; + } } diff --git a/src/org/apache/fop/fo/pagination/RegionBefore.java b/src/org/apache/fop/fo/pagination/RegionBefore.java index 55747c196..d8df30b0d 100644 --- a/src/org/apache/fop/fo/pagination/RegionBefore.java +++ b/src/org/apache/fop/fo/pagination/RegionBefore.java @@ -69,12 +69,32 @@ public class RegionBefore extends FObj { } SimplePageMaster layoutMaster; - + String regionName; + protected RegionBefore(FObj parent, PropertyList propertyList) throws FOPException { super(parent, propertyList); this.name = "fo:region-before"; + // regions may have name, or default + if (null == this.properties.get("region-name")) + regionName = "xsl-region-before"; + else if (this.properties.get("region-name").getString().equals("")) + regionName = "xsl-region-before"; + else + { + regionName = this.properties.get("region-name").getString(); + // check that name is OK. Not very pretty. + if (regionName.equals( "xsl-region-after" ) || regionName.equals( "xsl-region-start" ) + || regionName.equals( "xsl-region-end" ) || regionName.equals( "xsl-region-body" ) + || regionName.equals( "xsl-before-float-separator" ) + || regionName.equals( "xsl-footnote-separator" )) + { + throw new FOPException("region-name '" + regionName + + "' for fo:region-before not permitted."); + } + } + if (parent.getName().equals("fo:simple-page-master")) { this.layoutMaster = (SimplePageMaster) parent; this.layoutMaster.setRegionBefore(this); @@ -100,4 +120,9 @@ public class RegionBefore extends FObj { allocationRectangleWidth - marginLeft - marginRight, extent); } + + public String getRegionName() + { + return regionName; + } } diff --git a/src/org/apache/fop/fo/pagination/RegionBody.java b/src/org/apache/fop/fo/pagination/RegionBody.java index 72a86819b..d6c2f1d43 100644 --- a/src/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/org/apache/fop/fo/pagination/RegionBody.java @@ -68,11 +68,32 @@ public class RegionBody extends FObj { return new RegionBody.Maker(); } + String regionName; + protected RegionBody(FObj parent, PropertyList propertyList) throws FOPException { super(parent, propertyList); this.name = "fo:region-body"; + // regions may have name, or default + if (null == this.properties.get("region-name")) + regionName = "xsl-region-body"; + else if (this.properties.get("region-name").getString().equals("")) + regionName = "xsl-region-body"; + else + { + regionName = this.properties.get("region-name").getString(); + // check that name is OK. Not very pretty. + if (regionName.equals( "xsl-region-before" ) || regionName.equals( "xsl-region-start" ) + || regionName.equals( "xsl-region-end" ) || regionName.equals( "xsl-region-after" ) + || regionName.equals( "xsl-before-float-separator" ) + || regionName.equals( "xsl-footnote-separator" )) + { + throw new FOPException("region-name '" + regionName + + "' for fo:region-body not permitted."); + } + } + if (parent.getName().equals("fo:simple-page-master")) { ((SimplePageMaster) parent).setRegionBody(this); } else { @@ -97,4 +118,9 @@ public class RegionBody extends FObj { marginRight, allocationRectangleHeight - marginTop - marginBottom); } + + public String getRegionName() + { + return regionName; + } } diff --git a/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java b/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java index ac9c32723..ec195fa84 100644 --- a/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java @@ -86,7 +86,7 @@ public class RepeatablePageMasterReference extends PageMasterReference if (parent.getName().equals("fo:page-sequence-master")) { this.pageSequenceMaster = (PageSequenceMaster) parent; setMasterName( this.properties.get("master-name").getString() ); - if (getMasterName() == null) { + if (getMasterName().equals("")) { System.err.println("WARNING: repeatable-page-master-reference" + "does not have a master-name and so is being ignored"); } else { diff --git a/src/org/apache/fop/fo/pagination/SimplePageMaster.java b/src/org/apache/fop/fo/pagination/SimplePageMaster.java index 556273354..685c7a9be 100644 --- a/src/org/apache/fop/fo/pagination/SimplePageMaster.java +++ b/src/org/apache/fop/fo/pagination/SimplePageMaster.java @@ -58,6 +58,8 @@ import org.apache.fop.layout.PageMaster; import org.apache.fop.layout.Region; import org.apache.fop.apps.FOPException; +import java.util.Hashtable; + public class SimplePageMaster extends FObj { public static class Maker extends FObj.Maker { @@ -74,6 +76,8 @@ public class SimplePageMaster extends FObj { RegionBody regionBody; RegionBefore regionBefore; RegionAfter regionAfter; + private Hashtable regions; + private String masterName; LayoutMasterSet layoutMasterSet; PageMaster pageMaster; @@ -83,14 +87,17 @@ public class SimplePageMaster extends FObj { super(parent, propertyList); this.name = "fo:simple-page-master"; + this.regions = new Hashtable(); + if (parent.getName().equals("fo:layout-master-set")) { this.layoutMasterSet = (LayoutMasterSet) parent; String pm = this.properties.get("master-name").getString(); - if (pm == null) { + if (pm.equals("")) { MessageHandler.errorln("WARNING: simple-page-master does not have " + "a master-name and so is being ignored"); } else { this.layoutMasterSet.addSimplePageMaster(pm, this); + this.masterName = pm; } } else { throw new FOPException("fo:simple-page-master must be child " @@ -130,15 +137,59 @@ public class SimplePageMaster extends FObj { return this.pageMaster; } - protected void setRegionAfter(RegionAfter region) { - this.regionAfter = region; + protected void setRegionAfter(RegionAfter region) + throws FOPException { + if (regions.containsKey(region.getRegionName())) + { + throw new FOPException("region names must be unique" + + " within simple-page-master '" + + getMasterName() + "'"); + } + else + { + regions.put(region.getRegionName(), region.getName()); + } + this.regionAfter = region; } - protected void setRegionBefore(RegionBefore region) { - this.regionBefore = region; + protected void setRegionBefore(RegionBefore region) + throws FOPException { + if (regions.containsKey(region.getRegionName())) + { + throw new FOPException("region names must be unique" + + " within simple-page-master '" + + getMasterName() + "'"); + } + else + { + regions.put(region.getRegionName(), region.getName()); + } + this.regionBefore = region; } - protected void setRegionBody(RegionBody region) { - this.regionBody = region; + protected void setRegionBody(RegionBody region) + throws FOPException { + if (regions.containsKey(region.getRegionName())) + { + throw new FOPException("region names must be unique" + + " within simple-page-master '" + + getMasterName() + "'"); + } + else + { + regions.put(region.getRegionName(), region.getName()); + } + this.regionBody = region; } + + public Hashtable getRegions() + { + return regions; + } + + public String getMasterName() + { + return masterName; + } + } diff --git a/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java b/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java index cf6071c4e..34d96bc28 100644 --- a/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java +++ b/src/org/apache/fop/fo/pagination/SinglePageMasterReference.java @@ -86,7 +86,7 @@ public class SinglePageMasterReference extends PageMasterReference this.pageSequenceMaster = (PageSequenceMaster) parent; setMasterName( this.properties.get("master-name").getString() ); - if (getMasterName() == null) { + if (getMasterName().equals("")) { MessageHandler.error("WARNING: single-page-master-reference" + "does not have a master-name and so is being ignored"); } else { -- 2.39.5