1 51 package org.apache.fop.fo.pagination; 52 53 import org.apache.fop.fo.*; 54 import org.apache.fop.apps.FOPException; 55 56 import java.util.ArrayList ; 58 59 66 public class RepeatablePageMasterAlternatives extends FObj 67 implements SubSequenceSpecifier { 68 69 private static final int INFINITE = -1; 70 71 72 public static class Maker extends FObj.Maker { 73 public FObj make(FObj parent, PropertyList propertyList, 74 String systemId, int line, int column) 75 throws FOPException { 76 return new RepeatablePageMasterAlternatives(parent, propertyList, 77 systemId, line, column); 78 } 79 80 } 81 82 public static FObj.Maker maker() { 83 return new RepeatablePageMasterAlternatives.Maker(); 84 } 85 86 private PageSequenceMaster pageSequenceMaster; 87 88 92 private int maximumRepeats; 93 private int numberConsumed = 0; 94 95 private ArrayList conditionalPageMasterRefs; 96 97 public RepeatablePageMasterAlternatives(FObj parent, PropertyList propertyList, 98 String systemId, int line, int column) 99 throws FOPException { 100 super(parent, propertyList, systemId, line, column); 101 102 if (parent.getName().equals("fo:page-sequence-master")) { 103 this.pageSequenceMaster = (PageSequenceMaster)parent; 104 this.pageSequenceMaster.addSubsequenceSpecifier(this); 105 } else { 106 throw new FOPException("A fo:repeatable-page-master-alternatives" 107 + "must be child of fo:page-sequence-master, not " 108 + parent.getName(), systemId, line, column); 109 } 110 111 String mr = getProperty("maximum-repeats").getString(); 112 if (mr.equals("no-limit")) { 113 this.maximumRepeats=INFINITE; 114 } else { 115 try { 116 this.maximumRepeats = Integer.parseInt(mr); 117 if (this.maximumRepeats < 0) { 118 log.debug("negative maximum-repeats: "+this.maximumRepeats); 119 this.maximumRepeats = 0; 120 } 121 } catch (NumberFormatException nfe) { 122 throw new FOPException("Invalid number for " 123 + "'maximum-repeats' property", systemId, line, column); 124 } 125 } 126 conditionalPageMasterRefs = new ArrayList (); 127 } 128 129 public String getName() { 130 return "fo:repeatable-page-master-alternatives"; 131 } 132 133 public void addConditionalPageMasterReference(ConditionalPageMasterReference cpmr) { 134 this.conditionalPageMasterRefs.add(cpmr); 135 } 136 137 public String getNextPageMasterName(boolean isOddPage, 138 boolean isFirstPage, 139 boolean isEmptyPage) { 140 if (maximumRepeats != -1) { 141 if (numberConsumed < maximumRepeats) { 142 numberConsumed++; 143 } else { 144 return null; 145 } 146 } 147 148 for (int i = 0; i < conditionalPageMasterRefs.size(); i++) { 149 ConditionalPageMasterReference cpmr = 150 (ConditionalPageMasterReference)conditionalPageMasterRefs.get(i); 151 if (cpmr.isValid(isOddPage, isFirstPage, isEmptyPage)) { 152 return cpmr.getMasterName(); 153 } 154 } 155 return null; 156 } 157 158 public void reset() { 159 this.numberConsumed = 0; 160 } 161 162 } 163 | Popular Tags |