diff options
author | Simon Pepping <spepping@apache.org> | 2006-02-24 11:39:01 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2006-02-24 11:39:01 +0000 |
commit | 3eb942fd361204404fbe7f946ae1c319637e4bf1 (patch) | |
tree | 01d290ad096877bcb12e4f45ff218153798bd989 | |
parent | 799ffca5bbf2939cfe34f723c826f73dcd28138f (diff) | |
download | xmlgraphics-fop-3eb942fd361204404fbe7f946ae1c319637e4bf1.tar.gz xmlgraphics-fop-3eb942fd361204404fbe7f946ae1c319637e4bf1.zip |
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
5 files changed, 89 insertions, 10 deletions
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; @@ -68,6 +70,15 @@ public interface LayoutManagerMaker { 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 * @param sc the fo:static-content object this SCLM will process 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2005 The Apache Software Foundation + + Licensed 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$ --> +<testcase> + <info> + <p> + This test checks that an empty fo:title does not cause a +NullPointerException and does not generate any text. + </p> + </info> + <fo> + <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> + <fo:layout-master-set> + <fo:simple-page-master master-name="small" + page-height="10cm" page-width="10cm"> + <fo:region-body/> + </fo:simple-page-master> + </fo:layout-master-set> + + <fo:page-sequence master-reference="small"> + <fo:title/> + <fo:flow flow-name="xsl-region-body"> + <fo:block/> + </fo:flow> + </fo:page-sequence> + </fo:root> + </fo> + <checks> + <eval expected="" xpath="//title"/> + </checks> +</testcase> |