aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core/src
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2017-06-20 07:45:25 +0000
committerSimon Steiner <ssteiner@apache.org>2017-06-20 07:45:25 +0000
commitac0ddecca6c8b19e293b2472933b27a32ccc5961 (patch)
tree10d506c5277206e92c6c1828eaab81b8db2d90ca /fop-core/src
parenteb517b921d2e34fe9bb4c1fb29ff102608967d8a (diff)
downloadxmlgraphics-fop-ac0ddecca6c8b19e293b2472933b27a32ccc5961.tar.gz
xmlgraphics-fop-ac0ddecca6c8b19e293b2472933b27a32ccc5961.zip
FOP-2714: Infinite loop when region name not found
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1799312 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src')
-rw-r--r--fop-core/src/main/java/org/apache/fop/fo/pagination/RegionBody.java2
-rw-r--r--fop-core/src/main/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java19
-rw-r--r--fop-core/src/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java34
3 files changed, 50 insertions, 5 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fo/pagination/RegionBody.java b/fop-core/src/main/java/org/apache/fop/fo/pagination/RegionBody.java
index 164c1cee5..210f25e1f 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/pagination/RegionBody.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/pagination/RegionBody.java
@@ -141,7 +141,7 @@ public class RegionBody extends Region {
}
/** {@inheritDoc} */
- protected String getDefaultRegionName() {
+ public String getDefaultRegionName() {
return "xsl-region-body";
}
diff --git a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
index cfcaabb33..6b993424c 100644
--- a/fop-core/src/main/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
+++ b/fop-core/src/main/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
@@ -34,6 +34,8 @@ import org.apache.fop.complexscripts.bidi.BidiResolver;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.PageSequenceMaster;
+import org.apache.fop.fo.pagination.Region;
+import org.apache.fop.fo.pagination.RegionBody;
import org.apache.fop.fo.pagination.SideRegion;
import org.apache.fop.fo.pagination.StaticContent;
import org.apache.fop.layoutmgr.inline.ContentLayoutManager;
@@ -189,16 +191,27 @@ public class PageSequenceLayoutManager extends AbstractPageSequenceLayoutManager
// cannot layout areas from the main flow. Blank pages can be created from empty pages.
if (!isBlank) {
- while (!getPageSequence().getMainFlow().getFlowName()
- .equals(newPage.getSimplePageMaster()
- .getRegion(FO_REGION_BODY).getRegionName())) {
+ int i = 0;
+ while (!flowNameEquals(newPage, i > 0)) {
newPage = super.makeNewPage(isBlank);
+ i++;
}
}
return newPage;
}
+ private boolean flowNameEquals(Page newPage, boolean strict) {
+ String psName = getPageSequence().getMainFlow().getFlowName();
+ Region body = newPage.getSimplePageMaster().getRegion(FO_REGION_BODY);
+ String name = body.getRegionName();
+ if (strict && !name.equals(psName) && !name.equals(((RegionBody)body).getDefaultRegionName())) {
+ throw new RuntimeException(
+ "The flow-name \"" + name + "\" could not be mapped to a region-name in the layout-master-set");
+ }
+ return psName.equals(name);
+ }
+
private void layoutSideRegion(int regionID) {
SideRegion reg = (SideRegion)curPage.getSimplePageMaster().getRegion(regionID);
if (reg == null) {
diff --git a/fop-core/src/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java b/fop-core/src/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java
index e810f80c5..e6a0975a8 100644
--- a/fop-core/src/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/layoutmgr/PageSequenceLayoutManagerTestCase.java
@@ -31,6 +31,7 @@ import org.apache.fop.area.PageViewport;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.Region;
+import org.apache.fop.fo.pagination.RegionBody;
import org.apache.fop.fo.pagination.Root;
import org.apache.fop.fo.pagination.SimplePageMaster;
@@ -106,7 +107,7 @@ public class PageSequenceLayoutManagerTestCase {
final Page page = mock(Page.class);
final SimplePageMaster spm = mock(SimplePageMaster.class);
final PageViewport pageViewport = mock(PageViewport.class);
- final Region region = mock(Region.class);
+ final Region region = mock(RegionBody.class);
when(page.getSimplePageMaster()).thenReturn(spm);
when(page.getPageViewport()).thenReturn(pageViewport);
@@ -116,4 +117,35 @@ public class PageSequenceLayoutManagerTestCase {
return page;
}
+
+ @Test
+ public void testRegionNameNotFound() {
+ final PageSequence pseq = mock(PageSequence.class);
+ final AreaTreeHandler ath = mock(AreaTreeHandler.class);
+ final Flow flow = mock(Flow.class);
+ final Root root = mock(Root.class);
+
+ when(flow.getFlowName()).thenReturn(MAIN_FLOW_NAME);
+ when(pseq.getRoot()).thenReturn(root);
+ when(pseq.getMainFlow()).thenReturn(flow);
+
+ PageSequenceLayoutManager pageSequenceLayoutManager = new PageSequenceLayoutManager(ath, pseq) {
+ public void activateLayout() {
+ makeNewPage(false);
+ }
+ protected Page createPage(int pageNumber, boolean isBlank) {
+ return createPageForRegionName("test");
+ }
+ protected void finishPage() {
+ }
+ };
+ RuntimeException re = null;
+ try {
+ pageSequenceLayoutManager.activateLayout();
+ } catch (RuntimeException e) {
+ re = e;
+ }
+ assertEquals(re.getMessage(),
+ "The flow-name \"test\" could not be mapped to a region-name in the layout-master-set");
+ }
}