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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. private boolean hasRetrieveTableMarker;
  59. /**
  60. * Create a TableCell instance with the given {@link FONode}
  61. * as parent.
  62. * @param parent {@link FONode} that is the parent of this object
  63. */
  64. public TableCell(FONode parent) {
  65. super(parent);
  66. }
  67. /**
  68. * {@inheritDoc}
  69. */
  70. public void bind(PropertyList pList) throws FOPException {
  71. super.bind(pList);
  72. commonAccessibility = CommonAccessibility.getInstance(pList);
  73. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  74. blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  75. displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
  76. emptyCells = pList.get(PR_EMPTY_CELLS).getEnum();
  77. startsRow = pList.get(PR_STARTS_ROW).getEnum();
  78. // For properly computing columnNumber
  79. if (startsRow() && getParent().getNameId() != FO_TABLE_ROW) {
  80. ((TablePart) getParent()).signalNewRow();
  81. }
  82. endsRow = pList.get(PR_ENDS_ROW).getEnum();
  83. columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric().getValue();
  84. numberColumnsSpanned = pList.get(PR_NUMBER_COLUMNS_SPANNED).getNumeric().getValue();
  85. numberRowsSpanned = pList.get(PR_NUMBER_ROWS_SPANNED).getNumeric().getValue();
  86. width = pList.get(PR_WIDTH).getLength();
  87. }
  88. /** {@inheritDoc} */
  89. protected void startOfNode() throws FOPException {
  90. super.startOfNode();
  91. getFOEventHandler().startCell(this);
  92. }
  93. /**
  94. * Make sure content model satisfied, if so then tell the
  95. * FOEventHandler that we are at the end of the table-cell.
  96. * {@inheritDoc}
  97. */
  98. protected void endOfNode() throws FOPException {
  99. super.endOfNode();
  100. getFOEventHandler().endCell(this);
  101. }
  102. /** {@inheritDoc} */
  103. public void finalizeNode() throws FOPException {
  104. if (!blockItemFound) {
  105. missingChildElementError("marker* (%block;)+", true);
  106. }
  107. if ((startsRow() || endsRow())
  108. && getParent().getNameId() == FO_TABLE_ROW ) {
  109. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  110. getUserAgent().getEventBroadcaster());
  111. eventProducer.startEndRowUnderTableRowWarning(this, getLocator());
  112. }
  113. }
  114. /**
  115. * {@inheritDoc}
  116. * <br>XSL Content Model: marker* (%block;)+
  117. */
  118. protected void validateChildNode(Locator loc, String nsURI, String localName)
  119. throws ValidationException {
  120. if (FO_URI.equals(nsURI)) {
  121. if (localName.equals("marker")) {
  122. if (blockItemFound) {
  123. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  124. }
  125. } else if (!isBlockItem(nsURI, localName)) {
  126. invalidChildError(loc, nsURI, localName);
  127. } else {
  128. blockItemFound = true;
  129. }
  130. }
  131. }
  132. /** {@inheritDoc} */
  133. public boolean generatesReferenceAreas() {
  134. return true;
  135. }
  136. /** {@inheritDoc} */
  137. public CommonAccessibility getCommonAccessibility() {
  138. return commonAccessibility;
  139. }
  140. /**
  141. * Get the {@link CommonBorderPaddingBackground} instance
  142. * attached to this TableCell.
  143. * @return the {@link CommonBorderPaddingBackground} instance
  144. */
  145. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  146. return this.commonBorderPaddingBackground;
  147. }
  148. /**
  149. * Get the value for the <code>column-number</code> property.
  150. * @return the "column-number" property.
  151. */
  152. public int getColumnNumber() {
  153. return columnNumber;
  154. }
  155. /**
  156. * Get the value for the <code>empty-cells</code> property.
  157. * @return true if "empty-cells" is "show"
  158. */
  159. public boolean showEmptyCells() {
  160. return (this.emptyCells == EN_SHOW);
  161. }
  162. /**
  163. * Get the value for the <code>number-columns-spanned</code> property
  164. * @return the "number-columns-spanned" property.
  165. */
  166. public int getNumberColumnsSpanned() {
  167. return Math.max(numberColumnsSpanned, 1);
  168. }
  169. /**
  170. * Get the value for the <code>number-rows-spanned</code> property
  171. * @return the "number-rows-spanned" property.
  172. */
  173. public int getNumberRowsSpanned() {
  174. return Math.max(numberRowsSpanned, 1);
  175. }
  176. /**
  177. * Get the value for the <code>block-progression-dimension</code> property
  178. * @return the "block-progression-dimension" property.
  179. */
  180. public LengthRangeProperty getBlockProgressionDimension() {
  181. return blockProgressionDimension;
  182. }
  183. /**
  184. * Get the value for the <code>display-align</code> property
  185. * @return the display-align property.
  186. */
  187. public int getDisplayAlign() {
  188. return displayAlign;
  189. }
  190. /**
  191. * Get the value for the <code>width</code> property
  192. * @return the "width" property.
  193. */
  194. public Length getWidth() {
  195. return width;
  196. }
  197. /**
  198. * Get the value for the <code>starts-row</code> property
  199. * @return true if the cell starts a row.
  200. */
  201. public boolean startsRow() {
  202. return (startsRow == EN_TRUE);
  203. }
  204. /**
  205. * Get the value for the <code>ends-row</code> property
  206. * @return true if the cell ends a row.
  207. */
  208. public boolean endsRow() {
  209. return (endsRow == EN_TRUE);
  210. }
  211. /** {@inheritDoc} */
  212. public String getLocalName() {
  213. return "table-cell";
  214. }
  215. /**
  216. * {@inheritDoc}
  217. * @return {@link org.apache.fop.fo.Constants#FO_TABLE_CELL}
  218. */
  219. public final int getNameId() {
  220. return FO_TABLE_CELL;
  221. }
  222. public void flagAsHavingRetrieveTableMarker() {
  223. hasRetrieveTableMarker = true;
  224. }
  225. public boolean hasRetrieveTableMarker() {
  226. return hasRetrieveTableMarker;
  227. }
  228. }