git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1799312 13f79535-47bb-0310-9956-ffa450edef68tags/fop-2_3
} | } | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
protected String getDefaultRegionName() { | |||||
public String getDefaultRegionName() { | |||||
return "xsl-region-body"; | return "xsl-region-body"; | ||||
} | } | ||||
import org.apache.fop.fo.Constants; | import org.apache.fop.fo.Constants; | ||||
import org.apache.fop.fo.pagination.PageSequence; | import org.apache.fop.fo.pagination.PageSequence; | ||||
import org.apache.fop.fo.pagination.PageSequenceMaster; | 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.SideRegion; | ||||
import org.apache.fop.fo.pagination.StaticContent; | import org.apache.fop.fo.pagination.StaticContent; | ||||
import org.apache.fop.layoutmgr.inline.ContentLayoutManager; | import org.apache.fop.layoutmgr.inline.ContentLayoutManager; | ||||
// cannot layout areas from the main flow. Blank pages can be created from empty pages. | // cannot layout areas from the main flow. Blank pages can be created from empty pages. | ||||
if (!isBlank) { | 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); | newPage = super.makeNewPage(isBlank); | ||||
i++; | |||||
} | } | ||||
} | } | ||||
return newPage; | 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) { | private void layoutSideRegion(int regionID) { | ||||
SideRegion reg = (SideRegion)curPage.getSimplePageMaster().getRegion(regionID); | SideRegion reg = (SideRegion)curPage.getSimplePageMaster().getRegion(regionID); | ||||
if (reg == null) { | if (reg == null) { |
import org.apache.fop.fo.pagination.Flow; | import org.apache.fop.fo.pagination.Flow; | ||||
import org.apache.fop.fo.pagination.PageSequence; | import org.apache.fop.fo.pagination.PageSequence; | ||||
import org.apache.fop.fo.pagination.Region; | 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.Root; | ||||
import org.apache.fop.fo.pagination.SimplePageMaster; | import org.apache.fop.fo.pagination.SimplePageMaster; | ||||
final Page page = mock(Page.class); | final Page page = mock(Page.class); | ||||
final SimplePageMaster spm = mock(SimplePageMaster.class); | final SimplePageMaster spm = mock(SimplePageMaster.class); | ||||
final PageViewport pageViewport = mock(PageViewport.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.getSimplePageMaster()).thenReturn(spm); | ||||
when(page.getPageViewport()).thenReturn(pageViewport); | when(page.getPageViewport()).thenReturn(pageViewport); | ||||
return page; | 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"); | |||||
} | |||||
} | } |