diff options
Diffstat (limited to 'src/java/org/apache/fop/area')
-rw-r--r-- | src/java/org/apache/fop/area/AreaTreeModel.java | 19 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/AreaTreeParser.java | 21 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/PageSequence.java | 53 | ||||
-rw-r--r-- | src/java/org/apache/fop/area/RenderPagesModel.java | 17 |
4 files changed, 84 insertions, 26 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeModel.java b/src/java/org/apache/fop/area/AreaTreeModel.java index bdbb88f2a..c43db31bb 100644 --- a/src/java/org/apache/fop/area/AreaTreeModel.java +++ b/src/java/org/apache/fop/area/AreaTreeModel.java @@ -22,10 +22,8 @@ package org.apache.fop.area; // Java import java.util.List; -// XML import org.xml.sax.SAXException; -// Apache import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -55,10 +53,13 @@ public class AreaTreeModel { /** * Start a page sequence on this model. - * @param title the title of the new page sequence + * @param pageSequence the page sequence about to start */ - public void startPageSequence(LineArea title) { - currentPageSequence = new PageSequence(title); + public void startPageSequence(PageSequence pageSequence) { + if (pageSequence == null) { + throw new NullPointerException("pageSequence must not be null"); + } + this.currentPageSequence = pageSequence; pageSequenceList.add(currentPageSequence); currentPageSequenceIndex = pageSequenceList.size() - 1; } @@ -91,6 +92,14 @@ public class AreaTreeModel { public void endDocument() throws SAXException {}; /** + * Returns the currently active page-sequence. + * @return the currently active page-sequence + */ + public PageSequence getCurrentPageSequence() { + return this.currentPageSequence; + } + + /** * Get the page sequence count. * @return the number of page sequences in the document. */ diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java index d4cdf5239..fafb99ed6 100644 --- a/src/java/org/apache/fop/area/AreaTreeParser.java +++ b/src/java/org/apache/fop/area/AreaTreeParser.java @@ -141,7 +141,6 @@ public class AreaTreeParser { private Stack areaStack = new Stack(); private boolean firstFlow; - private boolean pendingStartPageSequence; private Stack delegateStack = new Stack(); private ContentHandler delegate; @@ -349,8 +348,12 @@ public class AreaTreeParser { private class PageSequenceMaker extends AbstractMaker { public void startElement(Attributes attributes) { - pendingStartPageSequence = true; - //treeModel.startPageSequence(null); Done after title or on the first viewport + PageSequence pageSequence = new PageSequence(null); + String lang = attributes.getValue("language"); + pageSequence.setLanguage(lang); + String country = attributes.getValue("country"); + pageSequence.setCountry(country); + areaStack.push(pageSequence); } } @@ -364,19 +367,19 @@ public class AreaTreeParser { public void endElement() { LineArea line = (LineArea)areaStack.pop(); - treeModel.startPageSequence(line); - pendingStartPageSequence = false; + PageSequence pageSequence = (PageSequence)areaStack.peek(); + pageSequence.setTitle(line); } - } private class PageViewportMaker extends AbstractMaker { public void startElement(Attributes attributes) { - if (pendingStartPageSequence) { - treeModel.startPageSequence(null); - pendingStartPageSequence = false; + if (!areaStack.isEmpty()) { + PageSequence pageSequence = (PageSequence)areaStack.peek(); + treeModel.startPageSequence(pageSequence); + areaStack.pop(); } if (currentPageViewport != null) { throw new IllegalStateException("currentPageViewport must be null"); diff --git a/src/java/org/apache/fop/area/PageSequence.java b/src/java/org/apache/fop/area/PageSequence.java index d39ec7cf2..3b65f7701 100644 --- a/src/java/org/apache/fop/area/PageSequence.java +++ b/src/java/org/apache/fop/area/PageSequence.java @@ -28,13 +28,15 @@ public class PageSequence { private List pages = new java.util.ArrayList(); private LineArea title; + private String language; + private String country; /** * Main constructor * @param title the title for the page-sequence, may be null */ public PageSequence(LineArea title) { - this.title = title; + setTitle(title); } /** @@ -45,6 +47,14 @@ public class PageSequence { } /** + * Sets the page sequence's title. + * @param title the title + */ + public void setTitle(LineArea title) { + this.title = title; + } + + /** * Adds a new page to the page sequence * @param page the page to be added */ @@ -76,4 +86,45 @@ public class PageSequence { public boolean isFirstPage(PageViewport page) { return page.equals(getPage(0)); } + + /** + * Returns the language of the page-sequence. + * @return the language (the value of the language property, "none" is mapped to null) + */ + public String getLanguage() { + return this.language; + } + + /** + * Sets the language that applies to this page-sequence. + * @param language the language to set ("none" is mapped to null) + */ + public void setLanguage(String language) { + if ("none".equals(language)) { + this.language = null; + } else { + this.language = language; + } + } + + /** + * Returns the country of the page-sequence. + * @return the country (the value of the country property, "none" is mapped to null) + */ + public String getCountry() { + return this.country; + } + + /** + * Sets the country that applies to this page-sequence. + * @param country the country to set ("none" is mapped to null) + */ + public void setCountry(String country) { + if ("none".equals(country)) { + this.country = null; + } else { + this.country = country; + } + } + } diff --git a/src/java/org/apache/fop/area/RenderPagesModel.java b/src/java/org/apache/fop/area/RenderPagesModel.java index 1b3a22706..e080e9cbe 100644 --- a/src/java/org/apache/fop/area/RenderPagesModel.java +++ b/src/java/org/apache/fop/area/RenderPagesModel.java @@ -81,16 +81,11 @@ public class RenderPagesModel extends AreaTreeModel { } } - /** - * Start a new page sequence. - * This tells the renderer that a new page sequence has - * started with the given title. - * @param title the title of the new page sequence - */ - public void startPageSequence(LineArea title) { - super.startPageSequence(title); + /** {@inheritDoc} */ + public void startPageSequence(PageSequence pageSequence) { + super.startPageSequence(pageSequence); if (renderer.supportsOutOfOrder()) { - renderer.startPageSequence(title); + renderer.startPageSequence(getCurrentPageSequence()); } } @@ -112,7 +107,7 @@ public class RenderPagesModel extends AreaTreeModel { boolean ready = renderer.supportsOutOfOrder() && page.isResolved(); if (ready) { if (!renderer.supportsOutOfOrder() && page.getPageSequence().isFirstPage(page)) { - renderer.startPageSequence(this.currentPageSequence.getTitle()); + renderer.startPageSequence(getCurrentPageSequence()); } try { renderer.renderPage(page); @@ -159,7 +154,7 @@ public class RenderPagesModel extends AreaTreeModel { if (pageViewport.isResolved() || renderUnresolved) { if (!renderer.supportsOutOfOrder() && pageViewport.getPageSequence().isFirstPage(pageViewport)) { - renderer.startPageSequence(this.currentPageSequence.getTitle()); + renderer.startPageSequence(getCurrentPageSequence()); } try { renderer.renderPage(pageViewport); |