001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: TableCell.java 554104 2007-07-07 01:07:10Z adelmelle $ */
019:
020: package org.apache.fop.fo.flow;
021:
022: import org.xml.sax.Locator;
023:
024: import org.apache.fop.apps.FOPException;
025: import org.apache.fop.datatypes.Length;
026: import org.apache.fop.datatypes.Numeric;
027: import org.apache.fop.fo.FONode;
028: import org.apache.fop.fo.PropertyList;
029: import org.apache.fop.fo.ValidationException;
030: import org.apache.fop.fo.properties.CommonAccessibility;
031: import org.apache.fop.fo.properties.CommonAural;
032: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
033: import org.apache.fop.fo.properties.CommonRelativePosition;
034: import org.apache.fop.fo.properties.KeepProperty;
035: import org.apache.fop.fo.properties.LengthRangeProperty;
036:
037: /**
038: * Class modelling the fo:table-cell object.
039: * @todo check need for all instance variables stored here
040: */
041: public class TableCell extends TableFObj {
042: // The value of properties relevant for fo:table-cell.
043: private CommonBorderPaddingBackground commonBorderPaddingBackground;
044: private LengthRangeProperty blockProgressionDimension;
045: private int columnNumber;
046: private int displayAlign;
047: private int emptyCells;
048: private int endsRow;
049: private int numberColumnsSpanned;
050: private int numberRowsSpanned;
051: private int startsRow;
052: private Length width;
053: // Unused but valid items, commented out for performance:
054: // private CommonAccessibility commonAccessibility;
055: // private CommonAural commonAural;
056: // private CommonRelativePosition commonRelativePosition;
057: // private int relativeAlign;
058: // private Length height;
059: // private LengthRangeProperty inlineProgressionDimension;
060: // private KeepProperty keepTogether;
061: // private KeepProperty keepWithNext;
062: // private KeepProperty keepWithPrevious;
063: // End of property values
064:
065: /** used for FO validation */
066: private boolean blockItemFound = false;
067:
068: /**
069: * @param parent FONode that is the parent of this object
070: */
071: public TableCell(FONode parent) {
072: super (parent);
073: }
074:
075: /**
076: * @see org.apache.fop.fo.FObj#bind(PropertyList)
077: */
078: public void bind(PropertyList pList) throws FOPException {
079: super .bind(pList);
080: commonBorderPaddingBackground = pList
081: .getBorderPaddingBackgroundProps();
082: blockProgressionDimension = pList.get(
083: PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
084: displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
085: emptyCells = pList.get(PR_EMPTY_CELLS).getEnum();
086: endsRow = pList.get(PR_ENDS_ROW).getEnum();
087: columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric()
088: .getValue();
089: numberColumnsSpanned = pList.get(PR_NUMBER_COLUMNS_SPANNED)
090: .getNumeric().getValue();
091: numberRowsSpanned = pList.get(PR_NUMBER_ROWS_SPANNED)
092: .getNumeric().getValue();
093: startsRow = pList.get(PR_STARTS_ROW).getEnum();
094: width = pList.get(PR_WIDTH).getLength();
095: }
096:
097: /**
098: * @see org.apache.fop.fo.FONode#startOfNode
099: */
100: protected void startOfNode() throws FOPException {
101: super .startOfNode();
102: getFOEventHandler().startCell(this );
103: }
104:
105: /**
106: * Make sure content model satisfied, if so then tell the
107: * FOEventHandler that we are at the end of the flow.
108: * @see org.apache.fop.fo.FONode#endOfNode
109: */
110: protected void endOfNode() throws FOPException {
111: if (!blockItemFound) {
112: if (getUserAgent().validateStrictly()) {
113: missingChildElementError("marker* (%block;)+");
114: } else if (firstChild != null) {
115: log
116: .warn("fo:table-cell content that is not "
117: + "enclosed by a fo:block will be dropped/ignored.");
118: }
119: }
120: if ((startsRow() || endsRow())
121: && getParent().getNameId() == FO_TABLE_ROW) {
122: log
123: .warn("starts-row/ends-row for fo:table-cells "
124: + "non-applicable for children of an fo:table-row.");
125: }
126: getFOEventHandler().endCell(this );
127: }
128:
129: /**
130: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
131: * XSL Content Model: marker* (%block;)+
132: */
133: protected void validateChildNode(Locator loc, String nsURI,
134: String localName) throws ValidationException {
135: if (FO_URI.equals(nsURI) && localName.equals("marker")) {
136: if (blockItemFound) {
137: nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
138: }
139: } else if (!isBlockItem(nsURI, localName)) {
140: invalidChildError(loc, nsURI, localName);
141: } else {
142: blockItemFound = true;
143: }
144: }
145:
146: /** @see org.apache.fop.fo.FObj#generatesReferenceAreas() */
147: public boolean generatesReferenceAreas() {
148: return true;
149: }
150:
151: /**
152: * @return the Common Border, Padding, and Background Properties.
153: */
154: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
155: return this .commonBorderPaddingBackground;
156: }
157:
158: /**
159: * @return the "column-number" property.
160: */
161: public int getColumnNumber() {
162: return columnNumber;
163: }
164:
165: /** @return true if "empty-cells" is "show" */
166: public boolean showEmptyCells() {
167: return (this .emptyCells == EN_SHOW);
168: }
169:
170: /**
171: * @return the "number-columns-spanned" property.
172: */
173: public int getNumberColumnsSpanned() {
174: return Math.max(numberColumnsSpanned, 1);
175: }
176:
177: /**
178: * @return the "number-rows-spanned" property.
179: */
180: public int getNumberRowsSpanned() {
181: return Math.max(numberRowsSpanned, 1);
182: }
183:
184: /**
185: * @return the "block-progression-dimension" property.
186: */
187: public LengthRangeProperty getBlockProgressionDimension() {
188: return blockProgressionDimension;
189: }
190:
191: /** @return the display-align property. */
192: public int getDisplayAlign() {
193: return displayAlign;
194: }
195:
196: /**
197: * @return the "width" property.
198: */
199: public Length getWidth() {
200: return width;
201: }
202:
203: /** @return true if the cell starts a row. */
204: public boolean startsRow() {
205: return (startsRow == EN_TRUE);
206: }
207:
208: /** @return true if the cell ends a row. */
209: public boolean endsRow() {
210: return (endsRow == EN_TRUE);
211: }
212:
213: /** @see org.apache.fop.fo.FONode#getLocalName() */
214: public String getLocalName() {
215: return "table-cell";
216: }
217:
218: /**
219: * @see org.apache.fop.fo.FObj#getNameId()
220: */
221: public final int getNameId() {
222: return FO_TABLE_CELL;
223: }
224: }
|