From 3eb942fd361204404fbe7f946ae1c319637e4bf1 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Fri, 24 Feb 2006 11:39:01 +0000 Subject: [PATCH] Avoid a NullPointerException when fo:title is empty. Let PSLM and ContentLM create LMs via LayoutManagerMaker. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@380646 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutmgr/LayoutManagerMaker.java | 11 +++++ .../fop/layoutmgr/LayoutManagerMapping.java | 9 ++++ .../layoutmgr/PageSequenceLayoutManager.java | 10 +++-- .../inline/ContentLayoutManager.java | 24 +++++++--- .../standard-testcases/title_empty.xml | 45 +++++++++++++++++++ 5 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 test/layoutengine/standard-testcases/title_empty.xml diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java index 2d88aeff5..c80245c2e 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java @@ -23,6 +23,8 @@ import org.apache.fop.fo.pagination.Flow; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.SideRegion; import org.apache.fop.fo.pagination.StaticContent; +import org.apache.fop.fo.pagination.Title; +import org.apache.fop.layoutmgr.inline.ContentLayoutManager; import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.Block; @@ -67,6 +69,15 @@ public interface LayoutManagerMaker { public FlowLayoutManager makeFlowLayoutManager( PageSequenceLayoutManager pslm, Flow flow); + /** + * Make a ContentLayoutManager object. + * @param pslm the parent PageSequenceLayoutManager object + * @param title the fo:title object this CLM will process + * @return The created ContentLayoutManager object + */ + public ContentLayoutManager makeContentLayoutManager( + PageSequenceLayoutManager pslm, Title title); + /** * Make a StaticContentLayoutManager object. * @param pslm the parent PageSequenceLayoutManager object diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java index 2663d3359..902cdec66 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java @@ -64,6 +64,7 @@ import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.layoutmgr.inline.BasicLinkLayoutManager; import org.apache.fop.layoutmgr.inline.BidiLayoutManager; import org.apache.fop.layoutmgr.inline.CharacterLayoutManager; +import org.apache.fop.layoutmgr.inline.ContentLayoutManager; import org.apache.fop.layoutmgr.inline.ExternalGraphicLayoutManager; import org.apache.fop.layoutmgr.inline.FootnoteLayoutManager; import org.apache.fop.layoutmgr.inline.ICLayoutManager; @@ -175,6 +176,14 @@ public class LayoutManagerMapping implements LayoutManagerMaker { PageSequenceLayoutManager pslm, Flow flow) { return new FlowLayoutManager(pslm, flow); } + + /* + * @see org.apache.fop.layoutmgr.LayoutManagerMaker#makeContentLayoutManager(PageSequenceLayoutManager, Title) + */ + public ContentLayoutManager makeContentLayoutManager(PageSequenceLayoutManager pslm, + Title title) { + return new ContentLayoutManager(pslm, title); + } /* * @see org.apache.fop.layoutmgr.LayoutManagerMaker#makeStaticContentLayoutManager(PageSequenceLayoutManager, StaticContent, Region) diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index 52d14ad96..c8ba02f92 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -128,9 +128,13 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { LineArea title = null; if (pageSeq.getTitleFO() != null) { - ContentLayoutManager clm = new ContentLayoutManager(pageSeq - .getTitleFO(), this); - title = (LineArea) clm.getParentArea(null); + try { + ContentLayoutManager clm = getLayoutManagerMaker(). + makeContentLayoutManager(this, pageSeq.getTitleFO()); + title = (LineArea) clm.getParentArea(null); + } catch (IllegalStateException e) { + // empty title; do nothing + } } areaTreeHandler.getAreaTreeModel().startPageSequence(title); diff --git a/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java index a1f6950c9..f7262cafb 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java @@ -20,6 +20,8 @@ package org.apache.fop.layoutmgr.inline; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.flow.RetrieveMarker; import org.apache.fop.fo.pagination.Title; import org.apache.fop.layoutmgr.AbstractBaseLayoutManager; import org.apache.fop.layoutmgr.KnuthElement; @@ -68,10 +70,14 @@ public class ContentLayoutManager extends AbstractBaseLayoutManager } /** - * Constructor using a fo:title formatting object and its - * PageSequenceLayoutManager parent. + * Constructor using a fo:title formatting object and its PageSequenceLayoutManager parent. + * throws IllegalStateException if the foTitle has no children. + * TODO: convert IllegalStateException to FOPException; + * also in makeLayoutManager and makeContentLayoutManager and callers. + * @param pslm the PageSequenceLayoutManager parent of this LM + * @param foTitle the Title FO for which this LM is made */ - public ContentLayoutManager(Title foTitle, PageSequenceLayoutManager pslm) { + public ContentLayoutManager(PageSequenceLayoutManager pslm, Title foTitle) { // get breaks then add areas to title this.parentLM = pslm; holder = new LineArea(); @@ -80,10 +86,14 @@ public class ContentLayoutManager extends AbstractBaseLayoutManager // use special layout manager to add the inline areas // to the Title. - InlineLayoutManager lm; - lm = new InlineLayoutManager(foTitle); - addChildLM(lm); - fillArea(lm); + try { + LayoutManager lm = pslm.getLayoutManagerMaker().makeLayoutManager(foTitle); + addChildLM(lm); + fillArea(lm); + } catch (IllegalStateException e) { + log.warn("Title has no content"); + throw e; + } } public void initialize() { diff --git a/test/layoutengine/standard-testcases/title_empty.xml b/test/layoutengine/standard-testcases/title_empty.xml new file mode 100644 index 000000000..ba1b0829f --- /dev/null +++ b/test/layoutengine/standard-testcases/title_empty.xml @@ -0,0 +1,45 @@ + + + + + +

+ This test checks that an empty fo:title does not cause a +NullPointerException and does not generate any text. +

+
+ + + + + + + + + + + + + + + + + + + +
-- 2.39.5