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-ffa450edef68tags/fop-0_92-beta
@@ -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 |
@@ -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) |
@@ -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); |
@@ -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() { |
@@ -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> |