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.

RepeatablePageMasterAlternatives.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. import org.apache.fop.fo.*;
  9. import org.apache.fop.apps.FOPException;
  10. // Java
  11. import java.util.ArrayList;
  12. /**
  13. * Class modeling the fo:repeatable-page-master-alternatives object.
  14. *
  15. * @see <a href="@XSLFO-STD@#fo_repeatable-page-master-alternatives"
  16. * target="_xslfostd">@XSLFO-STDID@
  17. * &para;6.4.10</a>
  18. */
  19. public class RepeatablePageMasterAlternatives extends FObj
  20. implements SubSequenceSpecifier {
  21. private static final int INFINITE = -1;
  22. public static class Maker extends FObj.Maker {
  23. public FObj make(FObj parent,
  24. PropertyList propertyList) throws FOPException {
  25. return new RepeatablePageMasterAlternatives(parent, propertyList);
  26. }
  27. }
  28. public static FObj.Maker maker() {
  29. return new RepeatablePageMasterAlternatives.Maker();
  30. }
  31. private PageSequenceMaster pageSequenceMaster;
  32. /**
  33. * Max times this page master can be repeated.
  34. * INFINITE is used for the unbounded case
  35. */
  36. private int maximumRepeats;
  37. private int numberConsumed = 0;
  38. private ArrayList conditionalPageMasterRefs;
  39. public RepeatablePageMasterAlternatives(FObj parent, PropertyList propertyList)
  40. throws FOPException {
  41. super(parent, propertyList);
  42. if (parent.getName().equals("fo:page-sequence-master")) {
  43. this.pageSequenceMaster = (PageSequenceMaster)parent;
  44. this.pageSequenceMaster.addSubsequenceSpecifier(this);
  45. } else {
  46. throw new FOPException("A fo:repeatable-page-master-alternatives"
  47. + "must be child of fo:page-sequence-master, not "
  48. + parent.getName());
  49. }
  50. String mr = getProperty("maximum-repeats").getString();
  51. if (mr.equals("no-limit")) {
  52. this.maximumRepeats=INFINITE;
  53. } else {
  54. try {
  55. this.maximumRepeats = Integer.parseInt(mr);
  56. if (this.maximumRepeats < 0) {
  57. log.debug("negative maximum-repeats: "+this.maximumRepeats);
  58. this.maximumRepeats = 0;
  59. }
  60. } catch (NumberFormatException nfe) {
  61. throw new FOPException("Invalid number for "
  62. + "'maximum-repeats' property");
  63. }
  64. }
  65. conditionalPageMasterRefs = new ArrayList();
  66. }
  67. public String getName() {
  68. return "fo:repeatable-page-master-alternatives";
  69. }
  70. public void addConditionalPageMasterReference(ConditionalPageMasterReference cpmr) {
  71. this.conditionalPageMasterRefs.add(cpmr);
  72. }
  73. public String getNextPageMasterName(boolean isOddPage,
  74. boolean isFirstPage,
  75. boolean isEmptyPage) {
  76. if (maximumRepeats != -1) {
  77. if (numberConsumed < maximumRepeats) {
  78. numberConsumed++;
  79. } else {
  80. return null;
  81. }
  82. }
  83. for (int i = 0; i < conditionalPageMasterRefs.size(); i++) {
  84. ConditionalPageMasterReference cpmr =
  85. (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i);
  86. if (cpmr.isValid(isOddPage, isFirstPage, isEmptyPage)) {
  87. return cpmr.getMasterName();
  88. }
  89. }
  90. return null;
  91. }
  92. public void reset() {
  93. this.numberConsumed = 0;
  94. }
  95. }