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.

RetrieveTableMarker.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.flow;
  19. import org.xml.sax.Attributes;
  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.PropertyList;
  24. import org.apache.fop.fo.flow.table.TableCell;
  25. /**
  26. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_retrieve-table-marker">
  27. * <code>fo:retrieve-table-marker</code></a> formatting object.
  28. */
  29. public class RetrieveTableMarker extends AbstractRetrieveMarker {
  30. /**
  31. * Create a new RetrieveTableMarker instance that is
  32. * a child of the given {@link FONode}.
  33. *
  34. * @param parent the parent {@link FONode}
  35. */
  36. public RetrieveTableMarker(FONode parent) {
  37. super(parent);
  38. }
  39. /**
  40. * {@inheritDoc}
  41. * <i>NOTE: An <code>fo:retrieve-table-marker</code> is only permitted as a descendant
  42. * of an <code>fo:table-header</code> or an <code>fo:table-footer</code>.</i>
  43. */
  44. public void processNode(
  45. String elementName, Locator locator, Attributes attlist, PropertyList pList)
  46. throws FOPException {
  47. if (findAncestor(FO_TABLE_HEADER) < 0
  48. && findAncestor(FO_TABLE_FOOTER) < 0) {
  49. invalidChildError(locator, getParent().getName(), FO_URI, getName(),
  50. "rule.retrieveTableMarkerDescendantOfHeaderOrFooter");
  51. } else {
  52. super.processNode(elementName, locator, attlist, pList);
  53. }
  54. }
  55. /** {@inheritDoc} */
  56. public void bind(PropertyList pList) throws FOPException {
  57. super.bind(pList);
  58. setPosition(pList.get(PR_RETRIEVE_POSITION_WITHIN_TABLE).getEnum());
  59. setPositionLabel((String) pList.get(PR_RETRIEVE_POSITION_WITHIN_TABLE).getObject());
  60. setBoundary(pList.get(PR_RETRIEVE_BOUNDARY_WITHIN_TABLE).getEnum());
  61. setBoundaryLabel((String) pList.get(PR_RETRIEVE_BOUNDARY_WITHIN_TABLE).getObject());
  62. }
  63. @Override
  64. public void startOfNode() throws FOPException {
  65. super.startOfNode();
  66. getFOEventHandler().startRetrieveTableMarker(this);
  67. }
  68. @Override
  69. public void endOfNode() throws FOPException {
  70. super.endOfNode();
  71. getFOEventHandler().endRetrieveTableMarker(this);
  72. }
  73. /**
  74. * Overridden to flag the ancestor table-cell.
  75. *
  76. * @param ancestorID ID of node name to check for (e.g., FO_ROOT)
  77. * @return number of levels above FO where ancestor exists,
  78. * -1 if not found
  79. */
  80. @Override
  81. protected int findAncestor(int ancestorID) {
  82. int found = 1;
  83. FONode temp = getParent();
  84. while (temp != null) {
  85. if (temp instanceof TableCell
  86. && (ancestorID == FO_TABLE_HEADER || ancestorID == FO_TABLE_FOOTER)) {
  87. // note that if the retrieve-table-marker is not in a table-header/footer an exception is
  88. // thrown, so no need to reset this flag in that case
  89. ((TableCell) temp).flagAsHavingRetrieveTableMarker();
  90. }
  91. if (temp.getNameId() == ancestorID) {
  92. return found;
  93. }
  94. found += 1;
  95. temp = temp.getParent();
  96. }
  97. return -1;
  98. }
  99. /**
  100. * Return the value for the <code>retrieve-position-within-table</code>
  101. * property
  102. * @return the value for retrieve-position-within-table; one of
  103. * {@link org.apache.fop.fo.Constants#EN_FIRST_STARTING},
  104. * {@link org.apache.fop.fo.Constants#EN_FIC},
  105. * {@link org.apache.fop.fo.Constants#EN_LAST_STARTING},
  106. * {@link org.apache.fop.fo.Constants#EN_LAST_ENDING}.
  107. */
  108. public int getRetrievePositionWithinTable() {
  109. return getPosition();
  110. }
  111. /**
  112. * Return the value for the <code>retrieve-boundary-within-table</code>
  113. * property
  114. * @return the value for retrieve-boundary-within-table; one of
  115. * {@link org.apache.fop.fo.Constants#EN_TABLE},
  116. * {@link org.apache.fop.fo.Constants#EN_TABLE_FRAGMENT},
  117. * {@link org.apache.fop.fo.Constants#EN_PAGE}.
  118. */
  119. public int getRetrieveBoundaryWithinTable() {
  120. return getBoundary();
  121. }
  122. /** {@inheritDoc} */
  123. public String getLocalName() {
  124. return "retrieve-table-marker";
  125. }
  126. /**
  127. * {@inheritDoc}
  128. * @return {@link org.apache.fop.fo.Constants#FO_RETRIEVE_TABLE_MARKER}
  129. */
  130. public int getNameId() {
  131. return FO_RETRIEVE_TABLE_MARKER;
  132. }
  133. /** {@inheritDoc} */
  134. public void clearChildNodes() {
  135. super.clearChildNodes();
  136. this.currentTextNode = null;
  137. this.lastFOTextProcessed = null;
  138. }
  139. @Override
  140. protected void restoreFOEventHandlerState() {
  141. getFOEventHandler().restoreState(this);
  142. }
  143. }