You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PageSequenceMaster.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo.pagination;
  8. // FOP
  9. import org.apache.fop.fo.*;
  10. import org.apache.fop.fo.properties.*;
  11. import org.apache.fop.layout.PageMaster;
  12. import org.apache.fop.apps.FOPException;
  13. // Java
  14. import java.util.ArrayList;
  15. /**
  16. * Class modeling the fo:page-sequence-master object.
  17. *
  18. * @see <a href="@XSLFO-STD@#fo_page-sequence-master"
  19. target="_xslfostd">@XSLFO-STDID@
  20. * &para;6.4.7</a>
  21. */
  22. public class PageSequenceMaster extends FObj {
  23. public static class Maker extends FObj.Maker {
  24. public FObj make(FObj parent,
  25. PropertyList propertyList) throws FOPException {
  26. return new PageSequenceMaster(parent, propertyList);
  27. }
  28. }
  29. public static FObj.Maker maker() {
  30. return new PageSequenceMaster.Maker();
  31. }
  32. private LayoutMasterSet layoutMasterSet;
  33. private ArrayList subSequenceSpecifiers;
  34. private SubSequenceSpecifier currentSubSequence;
  35. private int currentSubSequenceNumber;
  36. private String masterName;
  37. // The terminology may be confusing. A 'page-sequence-master' consists
  38. // of a sequence of what the XSL spec refers to as
  39. // 'sub-sequence-specifiers'. These are, in fact, simple or complex
  40. // references to page-masters. So the methods use the former
  41. // terminology ('sub-sequence-specifiers', or SSS),
  42. // but the actual FO's are MasterReferences.
  43. protected PageSequenceMaster(FObj parent, PropertyList propertyList)
  44. throws FOPException {
  45. super(parent, propertyList);
  46. if (parent.getName().equals("fo:layout-master-set")) {
  47. this.layoutMasterSet = (LayoutMasterSet)parent;
  48. this.masterName = this.properties.get("master-name").getString();
  49. if (this.masterName == null) {
  50. log.warn("page-sequence-master does not have "
  51. + "a page-master-name and so is being ignored");
  52. } else {
  53. this.layoutMasterSet.addPageSequenceMaster(masterName, this);
  54. }
  55. } else {
  56. throw new FOPException("fo:page-sequence-master must be child "
  57. + "of fo:layout-master-set, not "
  58. + parent.getName());
  59. }
  60. subSequenceSpecifiers = new ArrayList();
  61. currentSubSequenceNumber = -1;
  62. currentSubSequence = null;
  63. }
  64. protected void addSubsequenceSpecifier(SubSequenceSpecifier pageMasterReference) {
  65. subSequenceSpecifiers.add(pageMasterReference);
  66. }
  67. protected SubSequenceSpecifier getNextSubSequence() {
  68. currentSubSequenceNumber++;
  69. if (currentSubSequenceNumber >= 0
  70. && currentSubSequenceNumber < subSequenceSpecifiers.size()) {
  71. return (SubSequenceSpecifier)subSequenceSpecifiers
  72. .get(currentSubSequenceNumber);
  73. }
  74. return null;
  75. }
  76. public void reset() {
  77. currentSubSequenceNumber = -1;
  78. currentSubSequence = null;
  79. for (int i = 0; i< subSequenceSpecifiers.size(); i++ ) {
  80. ((SubSequenceSpecifier)subSequenceSpecifiers.get(i)).reset();
  81. }
  82. }
  83. public SimplePageMaster getNextSimplePageMaster(boolean oddPage,
  84. boolean blankPage)
  85. throws FOPException {
  86. boolean firstPage = false;
  87. if (currentSubSequence==null) {
  88. currentSubSequence = getNextSubSequence();
  89. if (currentSubSequence==null) {
  90. throw new FOPException("no subsequences in page-sequence-master '"
  91. + masterName + "'");
  92. }
  93. firstPage = true;
  94. }
  95. String pageMasterName = currentSubSequence
  96. .getNextPageMasterName(oddPage, firstPage, blankPage);
  97. boolean canRecover = true;
  98. while (pageMasterName==null) {
  99. SubSequenceSpecifier nextSubSequence = getNextSubSequence();
  100. firstPage = true;
  101. if (nextSubSequence==null) {
  102. if (!canRecover) {
  103. throw new FOPException("subsequences exhausted in page-sequence-master '"
  104. + masterName
  105. + "', cannot recover");
  106. }
  107. log.warn("subsequences exhausted in page-sequence-master '"
  108. + masterName
  109. + "', use previous subsequence");
  110. currentSubSequence.reset();
  111. canRecover = false;
  112. } else {
  113. currentSubSequence = nextSubSequence;
  114. }
  115. pageMasterName = currentSubSequence
  116. .getNextPageMasterName(oddPage, firstPage, blankPage);
  117. }
  118. SimplePageMaster pageMaster=this.layoutMasterSet
  119. .getSimplePageMaster(pageMasterName);
  120. if (pageMaster==null) {
  121. throw new FOPException("No simple-page-master matching '"
  122. + pageMasterName + "' in page-sequence-master '"
  123. + masterName +"'");
  124. }
  125. return pageMaster;
  126. }
  127. public String getName() {
  128. return "fo:page-sequence-master";
  129. }
  130. }