Index: src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java =================================================================== --- src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java (revision 697149) +++ src/java/org/apache/fop/fo/pagination/ConditionalPageMasterReference.java (working copy) @@ -94,61 +94,33 @@ * @param isFirstPage True if page is first page * @param isLastPage True if page is last page * @param isBlankPage True if page is blank - * @param isOnlyPage True if page is the only page * @return True if the conditions for this reference are met */ protected boolean isValid(boolean isOddPage, boolean isFirstPage, boolean isLastPage, - boolean isOnlyPage, boolean isBlankPage) { - // page-position - if (isOnlyPage) { - if (pagePosition != EN_ONLY) { - return false; - } - } else if (isFirstPage) { - if (pagePosition == EN_REST) { - return false; - } else if (pagePosition == EN_LAST) { - return false; - } - } else if (isLastPage) { - if (pagePosition == EN_REST) { - return false; - } else if (pagePosition == EN_FIRST) { - return false; - } - } else { - if (pagePosition == EN_FIRST) { - return false; - } else if (pagePosition == EN_LAST) { - return false; - } - } - // odd-or-even - if (isOddPage) { - if (oddOrEven == EN_EVEN) { - return false; - } - } else { - if (oddOrEven == EN_ODD) { - return false; - } - } + return ( + // page-position + (pagePosition == EN_ANY + || (pagePosition == EN_FIRST && isFirstPage) + || (pagePosition == EN_LAST && isLastPage) + || (pagePosition == EN_ONLY && (isFirstPage && isLastPage)) + || (pagePosition == EN_REST && !(isFirstPage || isLastPage)) + ) + // odd-or-even + && (oddOrEven == EN_ANY + || (oddOrEven == EN_ODD && isOddPage) + || (oddOrEven == EN_EVEN && !isOddPage) + ) + // blank-or-not-blank + && (blankOrNotBlank == EN_ANY + || (blankOrNotBlank == EN_BLANK && isBlankPage) + || (blankOrNotBlank == EN_NOT_BLANK && !isBlankPage) + )); - // blank-or-not-blank - if (isBlankPage) { - if (blankOrNotBlank == EN_NOT_BLANK) { - return false; - } - } else { - if (blankOrNotBlank == EN_BLANK) { - return false; - } - } - return true; + } /** Index: src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java =================================================================== --- src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java (revision 697149) +++ src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java (working copy) @@ -117,7 +117,6 @@ public String getNextPageMasterName(boolean isOddPage, boolean isFirstPage, boolean isLastPage, - boolean isOnlyPage, boolean isBlankPage) { if (getMaximumRepeats() != INFINITE) { if (numberConsumed < getMaximumRepeats()) { @@ -132,7 +131,7 @@ for (int i = 0; i < conditionalPageMasterRefs.size(); i++) { ConditionalPageMasterReference cpmr = (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i); - if (cpmr.isValid(isOddPage, isFirstPage, isLastPage, isOnlyPage, isBlankPage)) { + if (cpmr.isValid(isOddPage, isFirstPage, isLastPage, isBlankPage)) { return cpmr.getMasterReference(); } } Index: src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java =================================================================== --- src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java (revision 697149) +++ src/java/org/apache/fop/fo/pagination/SubSequenceSpecifier.java (working copy) @@ -31,7 +31,6 @@ * @param isOddPage True if the next page number is odd * @param isFirstPage True if the next page is the first * @param isLastPage True if the next page is the last - * @param isOnlyPage True if the next page is the only page * @param isBlankPage True if the next page is blank * @return the page master name * @throws PageProductionException if there's a problem determining the next page master @@ -39,7 +38,6 @@ String getNextPageMasterName(boolean isOddPage, boolean isFirstPage, boolean isLastPage, - boolean isOnlyPage, boolean isBlankPage) throws PageProductionException; Index: src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java =================================================================== --- src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java (revision 697149) +++ src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java (working copy) @@ -177,7 +177,6 @@ * @param isOddPage True if the next page number is odd * @param isFirstPage True if the next page is the first * @param isLastPage True if the next page is the last - * @param isOnlyPage True if the next page is the only page * @param isBlankPage True if the next page is blank * @return the requested page master * @throws PageProductionException if there's a problem determining the next page master @@ -185,7 +184,6 @@ public SimplePageMaster getNextSimplePageMaster(boolean isOddPage, boolean isFirstPage, boolean isLastPage, - boolean isOnlyPage, boolean isBlankPage) throws PageProductionException { if (currentSubSequence == null) { @@ -198,7 +196,7 @@ } } String pageMasterName = currentSubSequence - .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isOnlyPage, isBlankPage); + .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isBlankPage); boolean canRecover = true; while (pageMasterName == null) { SubSequenceSpecifier nextSubSequence = getNextSubSequence(); @@ -213,7 +211,7 @@ currentSubSequence = nextSubSequence; } pageMasterName = currentSubSequence - .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isOnlyPage, isBlankPage); + .getNextPageMasterName(isOddPage, isFirstPage, isLastPage, isBlankPage); } SimplePageMaster pageMaster = this.layoutMasterSet .getSimplePageMaster(pageMasterName); Index: src/java/org/apache/fop/fo/pagination/PageSequence.java =================================================================== --- src/java/org/apache/fop/fo/pagination/PageSequence.java (revision 697149) +++ src/java/org/apache/fop/fo/pagination/PageSequence.java (working copy) @@ -127,19 +127,19 @@ protected void validateChildNode(Locator loc, String nsURI, String localName) throws ValidationException { if (FO_URI.equals(nsURI)) { - if (localName.equals("title")) { + if ("title".equals(localName)) { if (titleFO != null) { tooManyNodesError(loc, "fo:title"); - } else if (flowMap.size() > 0) { + } else if (!flowMap.isEmpty()) { nodesOutOfOrderError(loc, "fo:title", "fo:static-content"); } else if (mainFlow != null) { nodesOutOfOrderError(loc, "fo:title", "fo:flow"); } - } else if (localName.equals("static-content")) { + } else if ("static-content".equals(localName)) { if (mainFlow != null) { nodesOutOfOrderError(loc, "fo:static-content", "fo:flow"); } - } else if (localName.equals("flow")) { + } else if ("flow".equals(localName)) { if (mainFlow != null) { tooManyNodesError(loc, "fo:flow"); } @@ -157,15 +157,20 @@ public void addChildNode(FONode child) throws FOPException { int childId = child.getNameId(); - if (childId == FO_TITLE) { - this.titleFO = (Title) child; - } else if (childId == FO_FLOW) { - this.mainFlow = (Flow) child; - addFlow(mainFlow); - } else if (childId == FO_STATIC_CONTENT) { - addFlow((StaticContent) child); - String flowName = ((StaticContent) child).getFlowName(); - flowMap.put(flowName, child); + switch (childId) { + case FO_TITLE: + this.titleFO = (Title)child; + break; + case FO_FLOW: + this.mainFlow = (Flow)child; + addFlow(mainFlow); + break; + case FO_STATIC_CONTENT: + addFlow((StaticContent)child); + flowMap.put(((StaticContent)child).getFlowName(), child); + break; + default: + assert false; } } @@ -245,17 +250,14 @@ * page sequence * @param isLastPage indicator whether this page is the last page of the * page sequence - * @param isOnlyPage indicator whether this page is the only page of the - * page sequence * @param isBlank indicator whether the page will be blank * @return the SimplePageMaster to use for this page * @throws PageProductionException if there's a problem determining the page master */ public SimplePageMaster getNextSimplePageMaster(int page, - boolean isFirstPage, - boolean isLastPage, - boolean isOnlyPage, - boolean isBlank) throws PageProductionException { + boolean isFirstPage, + boolean isLastPage, + boolean isBlank) throws PageProductionException { if (pageSequenceMaster == null) { return simplePageMaster; @@ -266,11 +268,10 @@ + " isOdd=" + isOddPage + " isFirst=" + isFirstPage + " isLast=" + isLastPage - + " isOnly=" + isOnlyPage + " isBlank=" + isBlank + ")"); } return pageSequenceMaster.getNextSimplePageMaster(isOddPage, - isFirstPage, isLastPage, isOnlyPage, isBlank); + isFirstPage, isLastPage, isBlank); } /** @@ -278,29 +279,17 @@ * @return true if there is a previous item, false if the current one was the first one. */ public boolean goToPreviousSimplePageMaster() { - if (pageSequenceMaster == null) { - return true; - } else { - return pageSequenceMaster.goToPreviousSimplePageMaster(); - } + return pageSequenceMaster == null || pageSequenceMaster.goToPreviousSimplePageMaster(); } /** @return true if the page-sequence has a page-master with page-position="last" */ public boolean hasPagePositionLast() { - if (pageSequenceMaster == null) { - return false; - } else { - return pageSequenceMaster.hasPagePositionLast(); - } + return pageSequenceMaster != null && pageSequenceMaster.hasPagePositionLast(); } /** @return true if the page-sequence has a page-master with page-position="only" */ public boolean hasPagePositionOnly() { - if (pageSequenceMaster == null) { - return false; - } else { - return pageSequenceMaster.hasPagePositionOnly(); - } + return pageSequenceMaster != null && pageSequenceMaster.hasPagePositionOnly(); } /** Index: src/java/org/apache/fop/render/rtf/RTFHandler.java =================================================================== --- src/java/org/apache/fop/render/rtf/RTFHandler.java (revision 697149) +++ src/java/org/apache/fop/render/rtf/RTFHandler.java (working copy) @@ -222,7 +222,7 @@ PageSequenceMaster master = pageSeq.getRoot().getLayoutMasterSet().getPageSequenceMaster(reference); this.pagemaster = master.getNextSimplePageMaster( - false, false, false, false, false); + false, false, false, false); } } Index: src/java/org/apache/fop/layoutmgr/PageProvider.java =================================================================== --- src/java/org/apache/fop/layoutmgr/PageProvider.java (revision 697149) +++ src/java/org/apache/fop/layoutmgr/PageProvider.java (working copy) @@ -234,13 +234,13 @@ indexOfCachedLastPage = (isLastPage ? intIndex : -1); } if (replace) { - disardCacheStartingWith(intIndex); + discardCacheStartingWith(intIndex); page = cacheNextPage(index, isBlank, isLastPage); } return page; } - private void disardCacheStartingWith(int index) { + private void discardCacheStartingWith(int index) { while (index < cachedPages.size()) { this.cachedPages.remove(cachedPages.size() - 1); if (!pageSeq.goToPreviousSimplePageMaster()) { @@ -251,8 +251,9 @@ private Page cacheNextPage(int index, boolean isBlank, boolean isLastPage) { String pageNumberString = pageSeq.makeFormattedPageNumber(index); + boolean isFirstPage = (startPageOfPageSequence == index); SimplePageMaster spm = pageSeq.getNextSimplePageMaster( - index, (startPageOfPageSequence == index), isLastPage, false, isBlank); + index, isFirstPage, isLastPage, isBlank); Region body = spm.getRegion(FO_REGION_BODY); if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) {