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.

TableCell.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.Locator;
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.datatypes.Length;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.ValidationException;
  25. import org.apache.fop.fo.properties.CommonAccessibility;
  26. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  27. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  28. import org.apache.fop.fo.properties.LengthRangeProperty;
  29. /**
  30. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-cell">
  31. * <code>fo:table-cell</code></a> object.
  32. */
  33. public class TableCell extends TableFObj implements CommonAccessibilityHolder {
  34. // The value of properties relevant for fo:table-cell.
  35. private CommonAccessibility commonAccessibility;
  36. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  37. private LengthRangeProperty blockProgressionDimension;
  38. private int columnNumber;
  39. private int displayAlign;
  40. private int emptyCells;
  41. private int endsRow;
  42. private int numberColumnsSpanned;
  43. private int numberRowsSpanned;
  44. private int startsRow;
  45. private Length width;
  46. // Unused but valid items, commented out for performance:
  47. // private CommonAural commonAural;
  48. // private CommonRelativePosition commonRelativePosition;
  49. // private int relativeAlign;
  50. // private Length height;
  51. // private LengthRangeProperty inlineProgressionDimension;
  52. // private KeepProperty keepTogether;
  53. // private KeepProperty keepWithNext;
  54. // private KeepProperty keepWithPrevious;
  55. // End of property values
  56. /** used for FO validation */
  57. private boolean blockItemFound = false;
  58. /**
  59. * Create a TableCell instance with the given {@link FONode}
  60. * as parent.
  61. * @param parent {@link FONode} that is the parent of this object
  62. */
  63. public TableCell(FONode parent) {
  64. super(parent);
  65. }
  66. /**
  67. * {@inheritDoc}
  68. */
  69. public void bind(PropertyList pList) throws FOPException {
  70. super.bind(pList);
  71. commonAccessibility = CommonAccessibility.getInstance(pList);
  72. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  73. blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  74. displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
  75. emptyCells = pList.get(PR_EMPTY_CELLS).getEnum();
  76. startsRow = pList.get(PR_STARTS_ROW).getEnum();
  77. // For properly computing columnNumber
  78. if (startsRow() && getParent().getNameId() != FO_TABLE_ROW) {
  79. ((TablePart) getParent()).signalNewRow();
  80. }
  81. endsRow = pList.get(PR_ENDS_ROW).getEnum();
  82. columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric().getValue();
  83. numberColumnsSpanned = pList.get(PR_NUMBER_COLUMNS_SPANNED).getNumeric().getValue();
  84. numberRowsSpanned = pList.get(PR_NUMBER_ROWS_SPANNED).getNumeric().getValue();
  85. width = pList.get(PR_WIDTH).getLength();
  86. }
  87. /** {@inheritDoc} */
  88. protected void startOfNode() throws FOPException {
  89. super.startOfNode();
  90. getFOEventHandler().startCell(this);
  91. }
  92. /**
  93. * Make sure content model satisfied, if so then tell the
  94. * FOEventHandler that we are at the end of the table-cell.
  95. * {@inheritDoc}
  96. */
  97. protected void endOfNode() throws FOPException {
  98. super.endOfNode();
  99. getFOEventHandler().endCell(this);
  100. }
  101. /** {@inheritDoc} */
  102. public void finalizeNode() throws FOPException {
  103. if (!blockItemFound) {
  104. missingChildElementError("marker* (%block;)+", true);
  105. }
  106. if ((startsRow() || endsRow())
  107. && getParent().getNameId() == FO_TABLE_ROW ) {
  108. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  109. getUserAgent().getEventBroadcaster());
  110. eventProducer.startEndRowUnderTableRowWarning(this, getLocator());
  111. }
  112. }
  113. /**
  114. * {@inheritDoc}
  115. * <br>XSL Content Model: marker* (%block;)+
  116. */
  117. protected void validateChildNode(Locator loc, String nsURI, String localName)
  118. throws ValidationException {
  119. if (FO_URI.equals(nsURI)) {
  120. if (localName.equals("marker")) {
  121. if (blockItemFound) {
  122. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  123. }
  124. } else if (!isBlockItem(nsURI, localName)) {
  125. invalidChildError(loc, nsURI, localName);
  126. } else {
  127. blockItemFound = true;
  128. }
  129. }
  130. }
  131. /** {@inheritDoc} */
  132. public boolean generatesReferenceAreas() {
  133. return true;
  134. }
  135. public CommonAccessibility getCommonAccessibility() {
  136. return commonAccessibility;
  137. }
  138. /**
  139. * Get the {@link CommonBorderPaddingBackground} instance
  140. * attached to this TableCell.
  141. * @return the {@link CommonBorderPaddingBackground} instance
  142. */
  143. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  144. return this.commonBorderPaddingBackground;
  145. }
  146. /**
  147. * Get the value for the <code>column-number</code> property.
  148. * @return the "column-number" property.
  149. */
  150. public int getColumnNumber() {
  151. return columnNumber;
  152. }
  153. /**
  154. * Get the value for the <code>empty-cells</code> property.
  155. * @return true if "empty-cells" is "show"
  156. */
  157. public boolean showEmptyCells() {
  158. return (this.emptyCells == EN_SHOW);
  159. }
  160. /**
  161. * Get the value for the <code>number-columns-spanned</code> property
  162. * @return the "number-columns-spanned" property.
  163. */
  164. public int getNumberColumnsSpanned() {
  165. return Math.max(numberColumnsSpanned, 1);
  166. }
  167. /**
  168. * Get the value for the <code>number-rows-spanned</code> property
  169. * @return the "number-rows-spanned" property.
  170. */
  171. public int getNumberRowsSpanned() {
  172. return Math.max(numberRowsSpanned, 1);
  173. }
  174. /**
  175. * Get the value for the <code>block-progression-dimension</code> property
  176. * @return the "block-progression-dimension" property.
  177. */
  178. public LengthRangeProperty getBlockProgressionDimension() {
  179. return blockProgressionDimension;
  180. }
  181. /**
  182. * Get the value for the <code>display-align</code> property
  183. * @return the display-align property.
  184. */
  185. public int getDisplayAlign() {
  186. return displayAlign;
  187. }
  188. /**
  189. * Get the value for the <code>width</code> property
  190. * @return the "width" property.
  191. */
  192. public Length getWidth() {
  193. return width;
  194. }
  195. /**
  196. * Get the value for the <code>starts-row</code> property
  197. * @return true if the cell starts a row.
  198. */
  199. public boolean startsRow() {
  200. return (startsRow == EN_TRUE);
  201. }
  202. /**
  203. * Get the value for the <code>ends-row</code> property
  204. * @return true if the cell ends a row.
  205. */
  206. public boolean endsRow() {
  207. return (endsRow == EN_TRUE);
  208. }
  209. /** {@inheritDoc} */
  210. public String getLocalName() {
  211. return "table-cell";
  212. }
  213. /**
  214. * {@inheritDoc}
  215. * @return {@link org.apache.fop.fo.Constants#FO_TABLE_CELL}
  216. */
  217. public final int getNameId() {
  218. return FO_TABLE_CELL;
  219. }
  220. }