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.

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