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.

TableRow.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.table;
  19. import org.xml.sax.Attributes;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.datatypes.Length;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.PropertyList;
  25. import org.apache.fop.fo.ValidationException;
  26. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  27. import org.apache.fop.fo.properties.KeepProperty;
  28. import org.apache.fop.fo.properties.LengthRangeProperty;
  29. /**
  30. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-row">
  31. * <code>fo:table-row</code></a> object.
  32. */
  33. public class TableRow extends TableCellContainer {
  34. // The value of properties relevant for fo:table-row.
  35. private LengthRangeProperty blockProgressionDimension;
  36. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  37. private int breakAfter;
  38. private int breakBefore;
  39. private Length height;
  40. private KeepProperty keepTogether;
  41. private KeepProperty keepWithNext;
  42. private KeepProperty keepWithPrevious;
  43. // Unused but valid items, commented out for performance:
  44. // private CommonAccessibility commonAccessibility;
  45. // private CommonAural commonAural;
  46. // private CommonRelativePosition commonRelativePosition;
  47. // private int visibility;
  48. // End of property values
  49. /**
  50. * Create a TableRow instance with the given {@link FONode}
  51. * as parent.
  52. * @param parent {@link FONode} that is the parent of this object
  53. */
  54. public TableRow(FONode parent) {
  55. super(parent);
  56. }
  57. /** {@inheritDoc} */
  58. public void bind(PropertyList pList) throws FOPException {
  59. blockProgressionDimension
  60. = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  61. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  62. breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
  63. breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
  64. height = pList.get(PR_HEIGHT).getLength();
  65. keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
  66. keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
  67. keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
  68. super.bind(pList);
  69. }
  70. /** {@inheritDoc} */
  71. public void processNode(String elementName, Locator locator,
  72. Attributes attlist, PropertyList pList) throws FOPException {
  73. super.processNode(elementName, locator, attlist, pList);
  74. if (!inMarker()) {
  75. TablePart part = (TablePart) parent;
  76. pendingSpans = part.pendingSpans;
  77. columnNumberManager = part.columnNumberManager;
  78. }
  79. }
  80. /** {@inheritDoc} */
  81. protected void addChildNode(FONode child) throws FOPException {
  82. if (!inMarker()) {
  83. TableCell cell = (TableCell) child;
  84. TablePart part = (TablePart) getParent();
  85. addTableCellChild(cell, part.isFirst(this));
  86. }
  87. super.addChildNode(child);
  88. }
  89. /** {@inheritDoc} */
  90. protected void startOfNode() throws FOPException {
  91. super.startOfNode();
  92. getFOEventHandler().startRow(this);
  93. }
  94. /** {@inheritDoc} */
  95. protected void endOfNode() throws FOPException {
  96. super.endOfNode();
  97. getFOEventHandler().endRow(this);
  98. }
  99. /** {@inheritDoc} */
  100. public void finalizeNode() throws FOPException {
  101. if (firstChild == null) {
  102. missingChildElementError("(table-cell+)");
  103. }
  104. if (!inMarker()) {
  105. pendingSpans = null;
  106. columnNumberManager = null;
  107. }
  108. }
  109. /**
  110. * {@inheritDoc} String, String)
  111. * <br>XSL Content Model: (table-cell+)
  112. */
  113. protected void validateChildNode(Locator loc, String nsURI,
  114. String localName)
  115. throws ValidationException {
  116. if (FO_URI.equals(nsURI)) {
  117. if (!localName.equals("table-cell")) {
  118. invalidChildError(loc, nsURI, localName);
  119. }
  120. }
  121. }
  122. /** {@inheritDoc} */
  123. TablePart getTablePart() {
  124. return (TablePart) parent;
  125. }
  126. /** {@inheritDoc} */
  127. boolean isTableRow() {
  128. return true;
  129. }
  130. /** @return the "break-after" property. */
  131. public int getBreakAfter() {
  132. return breakAfter;
  133. }
  134. /** @return the "break-before" property. */
  135. public int getBreakBefore() {
  136. return breakBefore;
  137. }
  138. /** @return the "keep-with-previous" property. */
  139. public KeepProperty getKeepWithPrevious() {
  140. return keepWithPrevious;
  141. }
  142. /** @return the "keep-with-next" property. */
  143. public KeepProperty getKeepWithNext() {
  144. return keepWithNext;
  145. }
  146. /** @return the "keep-together" property. */
  147. public KeepProperty getKeepTogether() {
  148. return keepTogether;
  149. }
  150. /**
  151. * Convenience method to check if a keep-together
  152. * constraint is specified.
  153. * @return true if keep-together is active.
  154. */
  155. public boolean mustKeepTogether() {
  156. return !getKeepTogether().getWithinPage().isAuto()
  157. || !getKeepTogether().getWithinColumn().isAuto();
  158. }
  159. /**
  160. * Convenience method to check if a keep-with-next
  161. * constraint is specified.
  162. * @return true if keep-with-next is active.
  163. */
  164. public boolean mustKeepWithNext() {
  165. return !getKeepWithNext().getWithinPage().isAuto()
  166. || !getKeepWithNext().getWithinColumn().isAuto();
  167. }
  168. /**
  169. * Convenience method to check if a keep-with-previous
  170. * constraint is specified.
  171. * @return true if keep-with-previous is active.
  172. */
  173. public boolean mustKeepWithPrevious() {
  174. return !getKeepWithPrevious().getWithinPage().isAuto()
  175. || !getKeepWithPrevious().getWithinColumn().isAuto();
  176. }
  177. /**
  178. * @return the "block-progression-dimension" property.
  179. */
  180. public LengthRangeProperty getBlockProgressionDimension() {
  181. return blockProgressionDimension;
  182. }
  183. /**
  184. * @return the "height" property.
  185. */
  186. public Length getHeight() {
  187. return height;
  188. }
  189. /**
  190. * @return the Common Border, Padding, and Background Properties.
  191. */
  192. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  193. return commonBorderPaddingBackground;
  194. }
  195. /** {@inheritDoc} */
  196. public String getLocalName() {
  197. return "table-row";
  198. }
  199. /**
  200. * {@inheritDoc}
  201. * @return {@link org.apache.fop.fo.Constants#FO_TABLE_ROW}
  202. */
  203. public int getNameId() {
  204. return FO_TABLE_ROW;
  205. }
  206. }