You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by sp...@apache.org on 2006/02/24 12:39:06 UTC

svn commit: r380646 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/layoutmgr/ src/java/org/apache/fop/layoutmgr/inline/ test/layoutengine/standard-testcases/

Author: spepping
Date: Fri Feb 24 03:39:01 2006
New Revision: 380646

URL: http://svn.apache.org/viewcvs?rev=380646&view=rev
Log:
Avoid a NullPointerException when fo:title is empty.
Let PSLM and ContentLM create LMs via LayoutManagerMaker.

Added:
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java?rev=380646&r1=380645&r2=380646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java Fri Feb 24 03:39:01 2006
@@ -23,6 +23,8 @@
 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;
 
@@ -66,6 +68,15 @@
      */
     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.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java?rev=380646&r1=380645&r2=380646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java Fri Feb 24 03:39:01 2006
@@ -64,6 +64,7 @@
 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;
@@ -174,6 +175,14 @@
     public FlowLayoutManager makeFlowLayoutManager(
             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);
     }
     
     /*

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java?rev=380646&r1=380645&r2=380646&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 Fri Feb 24 03:39:01 2006
@@ -128,9 +128,13 @@
         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);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java?rev=380646&r1=380645&r2=380646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ContentLayoutManager.java Fri Feb 24 03:39:01 2006
@@ -20,6 +20,8 @@
 
 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 @@
     }
 
     /**
-     * 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 @@
 
         // 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() {

Added: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml?rev=380646&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml (added)
+++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml Fri Feb 24 03:39:01 2006
@@ -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>

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/title_empty.xml
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org