Author: cbowditch
Date: Tue Jan 10 16:14:05 2012
New Revision: 1229622
URL: http://svn.apache.org/viewvc?rev=1229622&view=rev
Log:
Bugzilla #50391:
Add support for different flow-name of fo:region-body in FOP
Submitted by: Peter Hancock
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/flow/table/AllTests.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/AllTests.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOElementMapping.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreaker.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
xmlgraphics/fop/trunk/status.xml
xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOElementMapping.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOElementMapping.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOElementMapping.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOElementMapping.java Tue
Jan 10 16:14:05 2012
@@ -24,6 +24,8 @@ import java.util.HashMap;
import org.apache.xmlgraphics.util.QName;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
+
/**
* Element mapping class for all XSL-FO elements.
*/
@@ -205,7 +207,9 @@ public class FOElementMapping extends El
static class PageSequenceMasterMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
- return new org.apache.fop.fo.pagination.PageSequenceMaster(parent);
+ return new org.apache.fop.fo.pagination.PageSequenceMaster(parent,
+ BlockLevelEventProducer.Provider.get(
+ parent.getUserAgent().getEventBroadcaster()));
}
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java
Tue Jan 10 16:14:05 2012
@@ -27,6 +27,7 @@ import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.ValidationException;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
/**
* Class modelling the <a
href="http://www.w3.org/TR/xsl/#fo_conditional-page-master-reference">
@@ -41,6 +42,8 @@ import org.apache.fop.fo.ValidationExcep
public class ConditionalPageMasterReference extends FObj {
// The value of properties relevant for
fo:conditional-page-master-reference.
private String masterReference;
+ // The simple page master referenced
+ private SimplePageMaster master;
private int pagePosition;
private int oddOrEven;
private int blankOrNotBlank;
@@ -127,8 +130,8 @@ public class ConditionalPageMasterRefere
* Get the value for the <code>master-reference</code> property.
* @return the "master-reference" property
*/
- public String getMasterReference() {
- return masterReference;
+ public SimplePageMaster getMaster() {
+ return master;
}
/**
@@ -151,4 +154,19 @@ public class ConditionalPageMasterRefere
public int getNameId() {
return FO_CONDITIONAL_PAGE_MASTER_REFERENCE;
}
+
+ /**
+ * called by the parent RepeatablePageMasterAlternatives to resolve object
references
+ * from simple page master reference names
+ * @param layoutMasterSet the layout-master-set
+ * @throws ValidationException when a named reference cannot be resolved
+ * */
+ public void resolveReferences(LayoutMasterSet layoutMasterSet) throws
ValidationException {
+ master = layoutMasterSet.getSimplePageMaster(masterReference);
+ if (master == null) {
+ BlockLevelEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster())
+ .noMatchingPageMaster(this, parent.getName(), masterReference,
getLocator());
+ }
+ }
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
Tue Jan 10 16:14:05 2012
@@ -20,7 +20,6 @@
package org.apache.fop.fo.pagination;
// Java
-import java.util.Iterator;
import java.util.Map;
import org.xml.sax.Locator;
@@ -75,6 +74,7 @@ public class LayoutMasterSet extends FOb
missingChildElementError("(simple-page-master|page-sequence-master)+");
}
checkRegionNames();
+ resolveSubSequenceReferences();
}
/**
@@ -104,7 +104,7 @@ public class LayoutMasterSet extends FOb
for (Region region : spmRegions.values()) {
if (allRegions.containsKey(region.getRegionName())) {
String defaultRegionName
- = allRegions.get(region.getRegionName());
+ = allRegions.get(region.getRegionName());
if
(!defaultRegionName.equals(region.getDefaultRegionName())) {
getFOValidationEventProducer().regionNameMappedToMultipleRegionClasses(this,
region.getRegionName(),
@@ -118,6 +118,14 @@ public class LayoutMasterSet extends FOb
}
}
+ private void resolveSubSequenceReferences() throws ValidationException {
+ for (PageSequenceMaster psm : pageSequenceMasters.values()) {
+ for (SubSequenceSpecifier subSequenceSpecifier :
psm.getSubSequenceSpecifier()) {
+ subSequenceSpecifier.resolveReferences(this);
+ }
+ }
+ }
+
/**
* Add a simple page master.
* The name is checked to throw an error if already added.
@@ -150,7 +158,7 @@ public class LayoutMasterSet extends FOb
* @return the requested simple-page-master
*/
public SimplePageMaster getSimplePageMaster(String masterName) {
- return this.simplePageMasters.get(masterName);
+ return simplePageMasters.get(masterName);
}
/**
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageProductionException.java
Tue Jan 10 16:14:05 2012
@@ -25,8 +25,8 @@ import org.xml.sax.Locator;
import org.xml.sax.helpers.LocatorImpl;
import org.apache.fop.events.Event;
-import org.apache.fop.events.EventFormatter;
import org.apache.fop.events.EventExceptionManager.ExceptionFactory;
+import org.apache.fop.events.EventFormatter;
/**
* Exception thrown by FOP if there is a problem while producing new pages.
@@ -38,6 +38,15 @@ public class PageProductionException ext
private String localizedMessage;
private Locator locator;
+
+ /**
+ * Creates a new PageProductionException.
+ * @param message the message
+ */
+ public PageProductionException(String message) {
+ super(message);
+ }
+
/**
* Creates a new PageProductionException.
* @param message the message
@@ -48,12 +57,13 @@ public class PageProductionException ext
setLocator(locator);
}
+
/**
* Set a location associated with the exception.
* @param locator the locator holding the location.
*/
public void setLocator(Locator locator) {
- this.locator = new LocatorImpl(locator);
+ this.locator = locator != null ? new LocatorImpl(locator) : null;
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequence.java
Tue Jan 10 16:14:05 2012
@@ -48,7 +48,7 @@ public class PageSequence extends Abstra
// the set of flows includes StaticContent flows also
/** Map of flows to their flow name (flow-name, Flow) */
- private Map<String, Flow> flowMap;
+ private Map<String, FONode> flowMap;
/**
* The currentSimplePageMaster is either the page master for the
@@ -96,7 +96,7 @@ public class PageSequence extends Abstra
/** {@inheritDoc} */
protected void startOfNode() throws FOPException {
super.startOfNode();
- flowMap = new java.util.HashMap<String, Flow>();
+ flowMap = new java.util.HashMap<String, FONode>();
this.simplePageMaster
=
getRoot().getLayoutMasterSet().getSimplePageMaster(masterReference);
@@ -239,7 +239,7 @@ public class PageSequence extends Abstra
}
/** @return the flow map for this page-sequence */
- public Map<String, Flow> getFlowMap() {
+ public Map<String, FONode> getFlowMap() {
return this.flowMap;
}
@@ -270,7 +270,7 @@ public class PageSequence extends Abstra
+ " isBlank=" + isBlank + ")");
}
return pageSequenceMaster.getNextSimplePageMaster(isOddPage,
- isFirstPage, isLastPage, isBlank);
+ isFirstPage, isLastPage, isBlank, getMainFlow().getFlowName());
}
/**
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
Tue Jan 10 16:14:05 2012
@@ -20,6 +20,7 @@
package org.apache.fop.fo.pagination;
// Java
+import java.util.Collections;
import java.util.List;
import org.xml.sax.Locator;
@@ -47,6 +48,7 @@ public class PageSequenceMaster extends
private List<SubSequenceSpecifier> subSequenceSpecifiers;
private SubSequenceSpecifier currentSubSequence;
private int currentSubSequenceNumber = -1;
+ private BlockLevelEventProducer blockLevelEventProducer;
// The terminology may be confusing. A 'page-sequence-master' consists
// of a sequence of what the XSL spec refers to as
@@ -60,9 +62,11 @@ public class PageSequenceMaster extends
* given {@link FONode}.
*
* @param parent {@link FONode} that is the parent of this object
+ * @param blockLevelEventProducer event producer
*/
- public PageSequenceMaster(FONode parent) {
+ public PageSequenceMaster(FONode parent, BlockLevelEventProducer
blockLevelEventProducer) {
super(parent);
+ this.blockLevelEventProducer = blockLevelEventProducer;
}
/** {@inheritDoc} */
@@ -126,6 +130,10 @@ public class PageSequenceMaster extends
return null;
}
+ List<SubSequenceSpecifier> getSubSequenceSpecifier() {
+ return Collections.unmodifiableList(subSequenceSpecifiers);
+ }
+
/**
* Resets the subsequence specifiers subsystem.
*/
@@ -177,52 +185,58 @@ public class PageSequenceMaster extends
* @param isFirstPage True if the next page is the first
* @param isLastPage True if the next page is the last
* @param isBlankPage True if the next page is blank
+ * @param mainFlowName the name of the main flow of the page sequence
* @return the requested page master
* @throws PageProductionException if there's a problem determining the
next page master
*/
public SimplePageMaster getNextSimplePageMaster(boolean isOddPage,
boolean isFirstPage,
boolean isLastPage,
- boolean isBlankPage)
+ boolean isBlankPage,
+ String mainFlowName)
throws
PageProductionException {
if (currentSubSequence == null) {
currentSubSequence = getNextSubSequence();
if (currentSubSequence == null) {
- BlockLevelEventProducer eventProducer =
BlockLevelEventProducer.Provider.get(
- getUserAgent().getEventBroadcaster());
- eventProducer.missingSubsequencesInPageSequenceMaster(this,
+
blockLevelEventProducer.missingSubsequencesInPageSequenceMaster(this,
masterName, getLocator());
}
+ if (currentSubSequence.isInfinite() &&
!currentSubSequence.canProcess(mainFlowName)) {
+ throw new PageProductionException(
+ "The current sub-sequence will not terminate whilst processing
then main flow");
+ }
}
- String pageMasterName = currentSubSequence
- .getNextPageMasterName(isOddPage, isFirstPage, isLastPage,
isBlankPage);
+
+ SimplePageMaster pageMaster = currentSubSequence
+ .getNextPageMaster(isOddPage, isFirstPage, isLastPage,
isBlankPage);
+
boolean canRecover = true;
- while (pageMasterName == null) {
+
+ while (pageMaster == null) {
SubSequenceSpecifier nextSubSequence = getNextSubSequence();
+
if (nextSubSequence == null) {
- BlockLevelEventProducer eventProducer =
BlockLevelEventProducer.Provider.get(
- getUserAgent().getEventBroadcaster());
- eventProducer.pageSequenceMasterExhausted(this,
+ //Sub-sequence exhausted so attempt to reuse it
+ blockLevelEventProducer.pageSequenceMasterExhausted(this,
masterName, canRecover, getLocator());
currentSubSequence.reset();
+ if (!currentSubSequence.canProcess(mainFlowName)) {
+ throw new PageProductionException(
+ "The last simple-page-master does not reference the main
flow");
+ }
canRecover = false;
} else {
currentSubSequence = nextSubSequence;
}
- pageMasterName = currentSubSequence
- .getNextPageMasterName(isOddPage, isFirstPage, isLastPage,
isBlankPage);
- }
- SimplePageMaster pageMaster = this.layoutMasterSet
- .getSimplePageMaster(pageMasterName);
- if (pageMaster == null) {
- BlockLevelEventProducer eventProducer =
BlockLevelEventProducer.Provider.get(
- getUserAgent().getEventBroadcaster());
- eventProducer.noMatchingPageMaster(this,
- masterName, pageMasterName, getLocator());
+
+ pageMaster = currentSubSequence
+ .getNextPageMaster(isOddPage, isFirstPage, isLastPage,
isBlankPage);
}
+
return pageMaster;
}
+
/** {@inheritDoc} */
public String getLocalName() {
return "page-sequence-master";
@@ -235,5 +249,7 @@ public class PageSequenceMaster extends
public int getNameId() {
return FO_PAGE_SEQUENCE_MASTER;
}
+
+
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
Tue Jan 10 16:14:05 2012
@@ -20,6 +20,7 @@
package org.apache.fop.fo.pagination;
// Java
+import java.util.ArrayList;
import java.util.List;
import org.xml.sax.Locator;
@@ -114,25 +115,24 @@ public class RepeatablePageMasterAlterna
}
/** {@inheritDoc} */
- public String getNextPageMasterName(boolean isOddPage,
+ public SimplePageMaster getNextPageMaster(boolean isOddPage,
boolean isFirstPage,
boolean isLastPage,
boolean isBlankPage) {
- if (getMaximumRepeats() != INFINITE) {
- if (numberConsumed < getMaximumRepeats()) {
- numberConsumed++;
- } else {
- return null;
- }
- } else {
- numberConsumed++;
+
+ if (!isInfinite() && numberConsumed >= getMaximumRepeats()) {
+ return null;
}
+ numberConsumed++;
+
for (ConditionalPageMasterReference cpmr : conditionalPageMasterRefs) {
if (cpmr.isValid(isOddPage, isFirstPage, isLastPage, isBlankPage))
{
- return cpmr.getMasterReference();
+ return cpmr.getMaster();
}
}
+
+
return null;
}
@@ -189,4 +189,50 @@ public class RepeatablePageMasterAlterna
return FO_REPEATABLE_PAGE_MASTER_ALTERNATIVES;
}
+
+
+ /** {@inheritDoc} */
+ public void resolveReferences(LayoutMasterSet layoutMasterSet) throws
ValidationException {
+ for (ConditionalPageMasterReference conditionalPageMasterReference
+ : conditionalPageMasterRefs) {
+ conditionalPageMasterReference.resolveReferences(layoutMasterSet);
+ }
+
+ }
+
+ /** {@inheritDoc} */
+ public boolean canProcess(String flowName) {
+
+ boolean willTerminate = true;
+
+
+ //Look for rest spm that cannot terminate
+ ArrayList<ConditionalPageMasterReference> rest
+ = new ArrayList<ConditionalPageMasterReference>();
+ for (ConditionalPageMasterReference cpmr
+ : conditionalPageMasterRefs) {
+ if (cpmr.isValid(true, false, false, false)
+ || cpmr.isValid(false, false, false, false)) {
+ rest.add(cpmr);
+ }
+ }
+ if (!rest.isEmpty()) {
+ willTerminate = false;
+ for (ConditionalPageMasterReference cpmr : rest) {
+ willTerminate |=
cpmr.getMaster().getRegion(FO_REGION_BODY).getRegionName()
+ .equals(flowName);
+ }
+ }
+
+
+ return willTerminate;
+ }
+
+ /** {@inheritDoc} */
+ public boolean isInfinite() {
+ return getMaximumRepeats() == INFINITE;
+ }
+
+
+
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterReference.java
Tue Jan 10 16:14:05 2012
@@ -28,6 +28,7 @@ import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.ValidationException;
import org.apache.fop.fo.properties.Property;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
/**
* Class modelling the <a
href="http://www.w3.org/TR/xsl/#fo_repeatable-page-master-reference">
@@ -40,6 +41,8 @@ public class RepeatablePageMasterReferen
// The value of properties relevant for
fo:repeatable-page-master-reference.
private String masterReference;
+ // The simple page master referenced
+ private SimplePageMaster master;
private Property maximumRepeats;
// End of property values
@@ -87,18 +90,15 @@ public class RepeatablePageMasterReferen
}
/** {@inheritDoc} */
- public String getNextPageMasterName(boolean isOddPage,
+ public SimplePageMaster getNextPageMaster(boolean isOddPage,
boolean isFirstPage,
boolean isLastPage,
boolean isEmptyPage) {
- if (getMaximumRepeats() != INFINITE) {
- if (numberConsumed < getMaximumRepeats()) {
- numberConsumed++;
- } else {
- return null;
- }
+ if (getMaximumRepeats() != INFINITE && numberConsumed >=
getMaximumRepeats()) {
+ return null;
}
- return masterReference;
+ numberConsumed++;
+ return master;
}
/**
@@ -159,4 +159,27 @@ public class RepeatablePageMasterReferen
}
+ /** {@inheritDoc} */
+ public void resolveReferences(LayoutMasterSet layoutMasterSet) throws
ValidationException {
+ master = layoutMasterSet.getSimplePageMaster(masterReference);
+ if (master == null) {
+ BlockLevelEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster())
+ .noMatchingPageMaster(this, parent.getName(), masterReference,
getLocator());
+ }
+
+ }
+
+ /** {@inheritDoc} */
+ public boolean canProcess(String flowName) {
+ return
master.getRegion(FO_REGION_BODY).getRegionName().equals(flowName);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isInfinite() {
+ return getMaximumRepeats() == INFINITE;
+ }
+
+
+
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SimplePageMaster.java
Tue Jan 10 16:14:05 2012
@@ -21,7 +21,6 @@ package org.apache.fop.fo.pagination;
// Java
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.xml.sax.Locator;
@@ -29,8 +28,8 @@ import org.xml.sax.Locator;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.Numeric;
-import org.apache.fop.datatypes.SimplePercentBaseContext;
import org.apache.fop.datatypes.PercentBaseContext;
+import org.apache.fop.datatypes.SimplePercentBaseContext;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SinglePageMasterReference.java
Tue Jan 10 16:14:05 2012
@@ -27,6 +27,7 @@ import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.ValidationException;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
/**
* Class modelling the <a
href="http://www.w3.org/TR/xsl/#fo_single-page-master-reference">
@@ -39,6 +40,10 @@ public class SinglePageMasterReference e
// The value of properties relevant for fo:single-page-master-reference.
private String masterReference;
+
+ // The simple page master referenced
+ private SimplePageMaster master;
+
// End of property values
private static final int FIRST = 0;
@@ -83,13 +88,13 @@ public class SinglePageMasterReference e
}
/** {@inheritDoc} */
- public String getNextPageMasterName(boolean isOddPage,
+ public SimplePageMaster getNextPageMaster(boolean isOddPage,
boolean isFirstPage,
boolean isLastPage,
boolean isBlankPage) {
if (this.state == FIRST) {
this.state = DONE;
- return masterReference;
+ return master;
} else {
return null;
}
@@ -133,5 +138,25 @@ public class SinglePageMasterReference e
return FO_SINGLE_PAGE_MASTER_REFERENCE;
}
+ /** {@inheritDoc} */
+ public void resolveReferences(LayoutMasterSet layoutMasterSet) throws
ValidationException {
+ master = layoutMasterSet.getSimplePageMaster(masterReference);
+ if (master == null) {
+ BlockLevelEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster())
+ .noMatchingPageMaster(this, parent.getName(), masterReference,
getLocator());
+ }
+ }
+
+ /** {@inheritDoc} */
+ public boolean canProcess(String flowName) {
+ return
master.getRegion(FO_REGION_BODY).getRegionName().equals(flowName);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isInfinite() {
+ return false;
+ }
+
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java
Tue Jan 10 16:14:05 2012
@@ -19,6 +19,7 @@
package org.apache.fop.fo.pagination;
+import org.apache.fop.fo.ValidationException;
/**
* Classes that implement this interface can be added to a {@link
PageSequenceMaster},
@@ -36,7 +37,7 @@ public interface SubSequenceSpecifier {
* @return the page master name
* @throws PageProductionException if there's a problem determining the
next page master
*/
- String getNextPageMasterName(boolean isOddPage,
+ SimplePageMaster getNextPageMaster(boolean isOddPage,
boolean isFirstPage,
boolean isLastPage,
boolean isBlankPage)
@@ -60,5 +61,26 @@ public interface SubSequenceSpecifier {
/** @return true if the subsequence has a page master for page-position
"only" */
boolean hasPagePositionOnly();
+ /**
+ * called by the parent LayoutMasterSet to resolve object references
+ * from simple page master reference names
+ * @param layoutMasterSet the layout-master-set
+ * @throws ValidationException when a named reference cannot be resolved
+ * */
+ void resolveReferences(LayoutMasterSet layoutMasterSet) throws
ValidationException;
+
+ /**
+ *
+ * @param flowName name of the main flow
+ * @return true iff page sequence is a finite sequence or can process the
entire main flow
+ */
+ boolean canProcess(String flowName);
+
+ /**
+ * Test that this is a finite sequence
+ * @return true iff this is a finite sequence
+ */
+ boolean isInfinite();
+
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java
Tue Jan 10 16:14:05 2012
@@ -276,10 +276,9 @@ public abstract class AbstractPageSequen
* Makes a new page
*
* @param isBlank whether this page is blank or not
- * @param isLast whether this page is the last page or not
* @return a new page
*/
- protected Page makeNewPage(boolean isBlank, boolean isLast) {
+ protected Page makeNewPage(boolean isBlank) {
if (curPage != null) {
finishPage();
}
@@ -360,19 +359,19 @@ public abstract class AbstractPageSequen
if (forcePageCount == Constants.EN_EVEN) {
if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have an
odd number of pages
- curPage = makeNewPage(true, false);
+ curPage = makeNewPage(true);
}
} else if (forcePageCount == Constants.EN_ODD) {
if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have an
even number of pages
- curPage = makeNewPage(true, false);
+ curPage = makeNewPage(true);
}
} else if (forcePageCount == Constants.EN_END_ON_EVEN) {
if (currentPageNum % 2 != 0) { // we are now on an odd page
- curPage = makeNewPage(true, false);
+ curPage = makeNewPage(true);
}
} else if (forcePageCount == Constants.EN_END_ON_ODD) {
if (currentPageNum % 2 == 0) { // we are now on an even page
- curPage = makeNewPage(true, false);
+ curPage = makeNewPage(true);
}
} else if (forcePageCount == Constants.EN_NO_FORCE) {
// i hope: nothing special at all
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/ExternalDocumentLayoutManager.java
Tue Jan 10 16:14:05 2012
@@ -167,7 +167,7 @@ public class ExternalDocumentLayoutManag
private void makePageForImage(ImageInfo info, ImageLayout layout) {
this.imageLayout = layout;
- curPage = makeNewPage(false, false);
+ curPage = makeNewPage(false);
fillPage(info.getOriginalURI());
finishPage();
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreaker.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreaker.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreaker.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreaker.java
Tue Jan 10 16:14:05 2012
@@ -412,7 +412,7 @@ public class PageBreaker extends Abstrac
addAreas(alg, restartPoint, partCount - restartPoint,
originalList, effectiveList);
//...and add a blank last page
setLastPageIndex(currentPageNum + 1);
- pslm.setCurrentPage(pslm.makeNewPage(true, true));
+ pslm.setCurrentPage(pslm.makeNewPage(true));
return;
}
}
@@ -535,14 +535,14 @@ public class PageBreaker extends Abstrac
if (forceNewPageWithSpan) {
log.trace("Forcing new page with span");
- curPage = pslm.makeNewPage(false, false);
+ curPage = pslm.makeNewPage(false);
curPage.getPageViewport().createSpan(true);
} else if (pv.getCurrentSpan().hasMoreFlows()) {
log.trace("Moving to next flow");
pv.getCurrentSpan().moveToNextFlow();
} else {
log.trace("Making new page");
- /*curPage = */pslm.makeNewPage(false, false);
+ /*curPage = */pslm.makeNewPage(false);
}
return;
default:
@@ -550,11 +550,11 @@ public class PageBreaker extends Abstrac
+ " breakVal=" + getBreakClassName(breakVal));
if (needBlankPageBeforeNew(breakVal)) {
log.trace("Inserting blank page");
- /*curPage = */pslm.makeNewPage(true, false);
+ /*curPage = */pslm.makeNewPage(true);
}
if (needNewPage(breakVal)) {
log.trace("Making new page");
- /*curPage = */pslm.makeNewPage(false, false);
+ /*curPage = */pslm.makeNewPage(false);
}
}
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageProvider.java
Tue Jan 10 16:14:05 2012
@@ -27,7 +27,6 @@ import org.apache.commons.logging.LogFac
import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.fo.pagination.Region;
import org.apache.fop.fo.pagination.SimplePageMaster;
/**
@@ -52,7 +51,7 @@ public class PageProvider implements Con
private int startPageOfCurrentElementList;
private int startColumnOfCurrentElementList;
private boolean spanAllForCurrentElementList;
- private List cachedPages = new java.util.ArrayList();
+ private List<Page> cachedPages = new java.util.ArrayList<Page>();
private int lastPageIndex = -1;
private int indexOfCachedLastPage = -1;
@@ -298,7 +297,7 @@ public class PageProvider implements Con
}
cacheNextPage(index, isBlank, isLastPage,
this.spanAllForCurrentElementList);
}
- Page page = (Page)cachedPages.get(intIndex);
+ Page page = cachedPages.get(intIndex);
boolean replace = false;
if (page.getPageViewport().isBlank() != isBlank) {
log.debug("blank condition doesn't match. Replacing
PageViewport.");
@@ -332,15 +331,6 @@ public class PageProvider implements Con
SimplePageMaster spm = pageSeq.getNextSimplePageMaster(
index, isFirstPage, isLastPage, isBlank);
- Region body = spm.getRegion(FO_REGION_BODY);
- if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName()))
{
- // this is fine by the XSL Rec (fo:flow's flow-name can be mapped
to
- // any region), but we don't support it yet.
- BlockLevelEventProducer eventProducer =
BlockLevelEventProducer.Provider.get(
- pageSeq.getUserAgent().getEventBroadcaster());
- eventProducer.flowNotMappingToRegionBody(this,
- pageSeq.getMainFlow().getFlowName(), spm.getMasterName(),
spm.getLocator());
- }
Page page = new Page(spm, index, pageNumberString, isBlank, spanAll);
//Set unique key obtained from the AreaTreeHandler
page.getPageViewport().setKey(areaTreeHandler.generatePageViewportKey());
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
Tue Jan 10 16:14:05 2012
@@ -101,7 +101,7 @@ public class PageSequenceLayoutManager e
log.debug("Starting layout");
}
- curPage = makeNewPage(false, false);
+ curPage = makeNewPage(false);
PageBreaker breaker = new PageBreaker(this);
int flowBPD = getCurrentPV().getBodyRegion().getRemainingBPD();
@@ -141,6 +141,18 @@ public class PageSequenceLayoutManager e
pageNumber, PageProvider.RELTO_PAGE_SEQUENCE);
}
+ @Override
+ protected Page makeNewPage(boolean isBlank) {
+ Page newPage;
+
+ do {
+ newPage = super.makeNewPage(isBlank);
+ } while (!getPageSequence().getMainFlow().getFlowName()
+
.equals(newPage.getSimplePageMaster().getRegion(FO_REGION_BODY).getRegionName()));
+
+ return newPage;
+ }
+
private void layoutSideRegion(int regionID) {
SideRegion reg =
(SideRegion)curPage.getSimplePageMaster().getRegion(regionID);
if (reg == null) {
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
Tue Jan 10 16:14:05 2012
@@ -32,7 +32,6 @@ import java.util.Iterator;
import java.util.Map;
import org.w3c.dom.Document;
-
import org.xml.sax.SAXException;
import org.apache.commons.io.IOUtils;
@@ -118,13 +117,13 @@ import org.apache.fop.render.rtf.rtflib.
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfHyperLink;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfList;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem.RtfListItemLabel;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfPage;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun;
-import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem.RtfListItemLabel;
import org.apache.fop.render.rtf.rtflib.tools.BuilderContext;
import org.apache.fop.render.rtf.rtflib.tools.PercentContext;
import org.apache.fop.render.rtf.rtflib.tools.TableContext;
@@ -218,7 +217,7 @@ public class RTFHandler extends FOEventH
PageSequenceMaster master
=
pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference);
this.pagemaster = master.getNextSimplePageMaster(
- false, false, false, false);
+ false, false, false, false,
pageSeq.getMainFlow().getFlowName());
}
}
Modified: xmlgraphics/fop/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Tue Jan 10 16:14:05 2012
@@ -61,6 +61,9 @@
documents. Example: the fix of marks layering will be such a case when
it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Code" dev="CB" type="add" fixes-bug="50391"
due-to="Peter Hancock">
+ Add support for different flow-name of fo:region-body in FOP
+ </action>
<action context="Code" dev="CB" type="add" fixes-bug="51664"
due-to="Mehdi Houshmand">
Tagged PDF performance improvement plus tests
</action>
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/flow/table/AllTests.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/flow/table/AllTests.java?rev=1229622&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/flow/table/AllTests.java
(added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/flow/table/AllTests.java
Tue Jan 10 16:14:05 2012
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.flow.table;
+
+import org.junit.runners.Suite;
+
+/**
+ * All test to be added in FOTreeTestSuite
+ *
+ */
[email protected]({ CollapsedConditionalBorderTestCase.class,
IllegalRowSpanTestCase.class,
+ RowGroupBuilderTestCase.class, TableColumnColumnNumberTestCase.class,
+ TooManyColumnsTestCase.class })
+
+public final class AllTests {
+}
+
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/AllTests.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/AllTests.java?rev=1229622&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/AllTests.java
(added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/AllTests.java
Tue Jan 10 16:14:05 2012
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.pagination;
+
+import org.junit.runners.Suite;
+import org.junit.runner.RunWith;
+
+/**
+ * All test to be added in FOTreeTestSuite
+ *
+ */
+@RunWith(Suite.class)
[email protected]({ PageSequenceMasterTestCase.class,
+ RepeatablePageMasterAlternativesTestCase.class})
+
+public final class AllTests {
+
+}
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java?rev=1229622&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java
(added)
+++
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/PageSequenceMasterTestCase.java
Tue Jan 10 16:14:05 2012
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.pagination;
+
+import static org.junit.Assert.fail;
+
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.fo.FONode;
+import org.apache.fop.layoutmgr.BlockLevelEventProducer;
+
+import org.junit.Test;
+
+
+/**
+ * Unit Test for PageSequenceMaster
+ *
+ */
+public class PageSequenceMasterTestCase {
+
+ /**
+ * Test that PageProductionException is thrown if the final
simple-page-master
+ * cannot handle the main-flow of the page sequence
+ * @throws Exception exception
+ */
+ @Test
+ public void testGetNextSimplePageMasterException() throws Exception {
+
+ final String mainFlowRegionName = "main";
+ final String emptyFlowRegionName = "empty";
+ // Create stubs
+
+ FONode mockParent = mock(FONode.class);
+ Root mockRoot = mock(Root.class);
+ LayoutMasterSet mockLayoutMasterSet = mock(LayoutMasterSet.class);
+
+ // This will represent a page master that does not map to the main
flow
+ // of the page sequence
+ SimplePageMaster mockEmptySPM = mock(SimplePageMaster.class);
+ Region mockRegion = mock(Region.class);
+ SinglePageMasterReference mockSinglePageMasterReference
+ = mock(SinglePageMasterReference.class);
+ BlockLevelEventProducer mockBlockLevelEventProducer =
mock(BlockLevelEventProducer.class);
+
+ //Stub behaviour
+ when(mockParent.getRoot()).thenReturn(mockRoot);
+ when(mockRoot.getLayoutMasterSet()).thenReturn(mockLayoutMasterSet);
+
+ //The layout master set should return the empty page master
+
when(mockLayoutMasterSet.getSimplePageMaster(anyString())).thenReturn(mockEmptySPM);
+ when(mockEmptySPM.getRegion(anyInt())).thenReturn(mockRegion);
+
+ when(mockRegion.getRegionName()).thenReturn(emptyFlowRegionName);
+
+ when(mockSinglePageMasterReference.getNextPageMaster(anyBoolean(),
anyBoolean(),
+ anyBoolean(), anyBoolean()))
+ .thenReturn(null, mockEmptySPM);
+
+ PageSequenceMaster pageSequenceMaster = new
PageSequenceMaster(mockParent,
+ mockBlockLevelEventProducer);
+ pageSequenceMaster.startOfNode();
+
pageSequenceMaster.addSubsequenceSpecifier(mockSinglePageMasterReference);
+
+ try {
+ pageSequenceMaster.getNextSimplePageMaster(false, false, false,
false,
+ mainFlowRegionName);
+ fail("The next simple page master does not refer to the main
flow");
+ } catch (PageProductionException ppe) {
+ //Passed test
+ }
+ }
+
+}
+
Added:
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java?rev=1229622&view=auto
==============================================================================
---
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java
(added)
+++
xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternativesTestCase.java
Tue Jan 10 16:14:05 2012
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.pagination;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.expr.NumericProperty;
+import org.apache.fop.fo.properties.Property;
+
+
+
+/**
+ * Unit Test for RepeatablePageMasterAlternatives
+ *
+ */
+public class RepeatablePageMasterAlternativesTestCase
+implements Constants {
+
+ /**
+ *
+ * @throws Exception exception
+ */
+ @Test
+ public void testIsInfinite1() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ ConditionalPageMasterReference cpmr = createCPMR("empty");
+
+ when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats);
+
+ assertTrue("is infinite", objectUnderTest.isInfinite());
+ }
+
+ /**
+ *
+ * @throws Exception exception
+ */
+ @Test
+ public void testIsInfinite2() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ ConditionalPageMasterReference cpmr = createCPMR("empty");
+
+ NumericProperty numericProperty = mock(NumericProperty.class);
+
+ final int maxRepeatNum = 0;
+ assertTrue(maxRepeatNum != EN_NO_LIMIT);
+
+ when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum);
+ when(maximumRepeats.getNumeric()).thenReturn(numericProperty);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(createCPMR("empty"),
+ maximumRepeats);
+
+ assertTrue("is infinite", !objectUnderTest.isInfinite());
+ }
+
+ /**
+ * Test that an infinite sequence of empty page masters has
+ * willTerminiate() returning false
+ * @throws Exception exception
+ */
+ @Test
+ public void testCanProcess1() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ ConditionalPageMasterReference cpmr = createCPMR("empty");
+
+ when(maximumRepeats.getEnum()).thenReturn(EN_NO_LIMIT);
+ when(cpmr.isValid(anyBoolean(), anyBoolean(), anyBoolean(),
anyBoolean()))
+ .thenReturn(true);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(cpmr, maximumRepeats);
+
+ //Fixture assertion
+ assertTrue("Should be infinite", objectUnderTest.isInfinite());
+
+ //Test assertion
+ assertTrue("Infinite sequences that do not process the main flow will "
+ + " not terminate",
+ !objectUnderTest.canProcess("main-flow"));
+ }
+ /**
+ * Test that a finite sequence of simple page masters has
+ * willTerminate() returning true
+ *
+ * @throws Exception exception
+ */
+ @Test
+ public void testCanProcess2() throws Exception {
+ // Create fixture
+ Property maximumRepeats = mock(Property.class);
+ NumericProperty numericProperty = mock(NumericProperty.class);
+
+ final int maxRepeatNum = 0;
+
+ when(maximumRepeats.getEnum()).thenReturn(maxRepeatNum);
+ when(maximumRepeats.getNumeric()).thenReturn(numericProperty);
+
+ RepeatablePageMasterAlternatives objectUnderTest
+ = createRepeatablePageMasterAlternatives(createCPMR("empty"),
+ maximumRepeats);
+
+ //Fixture assertion
+ assertTrue("Should be finite sequence", !objectUnderTest.isInfinite());
+
+ //Test assertion
+ assertTrue("Finite sequences will terminate",
+ objectUnderTest.canProcess("main-flow"));
+ }
+
+ private ConditionalPageMasterReference createCPMR(String regionName) {
+ ConditionalPageMasterReference cpmr =
mock(ConditionalPageMasterReference.class);
+ SimplePageMaster master = mock(SimplePageMaster.class);
+ Region region = mock(Region.class);
+ when(master.getRegion(anyInt())).thenReturn(region);
+ when(region.getRegionName()).thenReturn(regionName);
+ when(cpmr.getMaster()).thenReturn(master);
+
+ return cpmr;
+ }
+
+ private RepeatablePageMasterAlternatives
createRepeatablePageMasterAlternatives(
+ ConditionalPageMasterReference cpmr, Property maximumRepeats)
throws Exception {
+
+ PropertyList pList = mock(PropertyList.class);
+
+ when(pList.get(anyInt())).thenReturn(maximumRepeats);
+
+ PageSequenceMaster parent = mock(PageSequenceMaster.class);
+
+ RepeatablePageMasterAlternatives sut = new
RepeatablePageMasterAlternatives(parent);
+
+ sut.startOfNode();
+ sut.bind(pList);
+ sut.addConditionalPageMasterReference(cpmr);
+ return sut;
+ }
+
+}
+
Modified:
xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java?rev=1229622&r1=1229621&r2=1229622&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
(original)
+++
xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
Tue Jan 10 16:14:05 2012
@@ -22,22 +22,14 @@ package org.apache.fop.fotreetest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-import org.apache.fop.fo.flow.table.CollapsedConditionalBorderTestCase;
-import org.apache.fop.fo.flow.table.IllegalRowSpanTestCase;
-import org.apache.fop.fo.flow.table.RowGroupBuilderTestCase;
-import org.apache.fop.fo.flow.table.TableColumnColumnNumberTestCase;
-import org.apache.fop.fo.flow.table.TooManyColumnsTestCase;
-
/**
* JUnit test suit for running layout engine test under JUnit control.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- TooManyColumnsTestCase.class,
- IllegalRowSpanTestCase.class,
- RowGroupBuilderTestCase.class,
- TableColumnColumnNumberTestCase.class,
- CollapsedConditionalBorderTestCase.class,
+ org.apache.fop.fo.flow.table.AllTests.class,
+ org.apache.fop.fo.pagination.AllTests.class,
FOTreeTestCase.class })
+
public final class FOTreeTestSuite {
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]