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.

SinglePageMasterReference.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo.pagination;
  19. // XML
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.FObj;
  24. import org.apache.fop.fo.PropertyList;
  25. import org.apache.fop.fo.ValidationException;
  26. /**
  27. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_single-page-master-reference">
  28. * <code>fo:single-page-master-reference</code></a> object.
  29. * This is a reference for a single page. It returns the
  30. * master name only once until reset.
  31. */
  32. public class SinglePageMasterReference extends FObj
  33. implements SubSequenceSpecifier {
  34. // The value of properties relevant for fo:single-page-master-reference.
  35. private String masterReference;
  36. // End of property values
  37. private static final int FIRST = 0;
  38. private static final int DONE = 1;
  39. private int state;
  40. /**
  41. * Creates a new SinglePageMasterReference instance that is
  42. * a child of the given {@link FONode}.
  43. * @param parent {@link FONode} that is the parent of this object
  44. */
  45. public SinglePageMasterReference(FONode parent) {
  46. super(parent);
  47. this.state = FIRST;
  48. }
  49. /** {@inheritDoc} */
  50. public void bind(PropertyList pList) throws FOPException {
  51. masterReference = pList.get(PR_MASTER_REFERENCE).getString();
  52. if (masterReference == null || masterReference.equals("")) {
  53. missingPropertyError("master-reference");
  54. }
  55. }
  56. /** {@inheritDoc} */
  57. protected void startOfNode() throws FOPException {
  58. PageSequenceMaster pageSequenceMaster = (PageSequenceMaster) parent;
  59. pageSequenceMaster.addSubsequenceSpecifier(this);
  60. }
  61. /**
  62. * {@inheritDoc}
  63. * <br>XSL Content Model: empty
  64. */
  65. protected void validateChildNode(Locator loc, String nsURI, String localName)
  66. throws ValidationException {
  67. if (FO_URI.equals(nsURI)) {
  68. invalidChildError(loc, nsURI, localName);
  69. }
  70. }
  71. /** {@inheritDoc} */
  72. public String getNextPageMasterName(boolean isOddPage,
  73. boolean isFirstPage,
  74. boolean isLastPage,
  75. boolean isBlankPage) {
  76. if (this.state == FIRST) {
  77. this.state = DONE;
  78. return masterReference;
  79. } else {
  80. return null;
  81. }
  82. }
  83. /** {@inheritDoc} */
  84. public void reset() {
  85. this.state = FIRST;
  86. }
  87. /** {@inheritDoc} */
  88. public boolean goToPrevious() {
  89. if (state == FIRST) {
  90. return false;
  91. } else {
  92. this.state = FIRST;
  93. return true;
  94. }
  95. }
  96. /** {@inheritDoc} */
  97. public boolean hasPagePositionLast() {
  98. return false;
  99. }
  100. /** {@inheritDoc} */
  101. public boolean hasPagePositionOnly() {
  102. return false;
  103. }
  104. /** {@inheritDoc} */
  105. public String getLocalName() {
  106. return "single-page-master-reference";
  107. }
  108. /**
  109. * {@inheritDoc}
  110. * @return {@link org.apache.fop.fo.Constants#FO_SINGLE_PAGE_MASTER_REFERENCE}
  111. */
  112. public int getNameId() {
  113. return FO_SINGLE_PAGE_MASTER_REFERENCE;
  114. }
  115. }