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: BlockContainer.java 554094 2007-07-07 00:04:25Z 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.FObj;
029: import org.apache.fop.fo.PropertyList;
030: import org.apache.fop.fo.ValidationException;
031: import org.apache.fop.fo.properties.CommonAbsolutePosition;
032: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
033: import org.apache.fop.fo.properties.CommonMarginBlock;
034: import org.apache.fop.fo.properties.KeepProperty;
035: import org.apache.fop.fo.properties.LengthRangeProperty;
036:
037: /**
038: * Class modelling the fo:block-container object.
039: */
040: public class BlockContainer extends FObj {
041: // The value of properties relevant for fo:block-container.
042: private CommonAbsolutePosition commonAbsolutePosition;
043: private CommonBorderPaddingBackground commonBorderPaddingBackground;
044: private CommonMarginBlock commonMarginBlock;
045: private LengthRangeProperty blockProgressionDimension;
046: private int breakAfter;
047: private int breakBefore;
048: // private ToBeImplementedProperty clip;
049: private int displayAlign;
050: private Length height;
051: private LengthRangeProperty inlineProgressionDimension;
052: private KeepProperty keepTogether;
053: private KeepProperty keepWithNext;
054: private KeepProperty keepWithPrevious;
055: private int overflow;
056: private Numeric referenceOrientation;
057: private int span;
058: private Length width;
059: private int writingMode;
060: // Unused but valid items, commented out for performance:
061: // private int intrusionDisplace;
062: // private Numeric zIndex;
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 BlockContainer(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: commonAbsolutePosition = pList.getAbsolutePositionProps();
081: commonBorderPaddingBackground = pList
082: .getBorderPaddingBackgroundProps();
083: commonMarginBlock = pList.getMarginBlockProps();
084: blockProgressionDimension = pList.get(
085: PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
086: breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
087: breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
088: // clip = pList.get(PR_CLIP);
089: displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
090: height = pList.get(PR_HEIGHT).getLength();
091: inlineProgressionDimension = pList.get(
092: PR_INLINE_PROGRESSION_DIMENSION).getLengthRange();
093: keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
094: keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
095: keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
096: overflow = pList.get(PR_OVERFLOW).getEnum();
097: referenceOrientation = pList.get(PR_REFERENCE_ORIENTATION)
098: .getNumeric();
099: span = pList.get(PR_SPAN).getEnum();
100: width = pList.get(PR_WIDTH).getLength();
101: writingMode = pList.get(PR_WRITING_MODE).getEnum();
102: }
103:
104: /**
105: * @see org.apache.fop.fo.FONode#startOfNode
106: */
107: protected void startOfNode() throws FOPException {
108: super .startOfNode();
109: getFOEventHandler().startBlockContainer(this );
110: }
111:
112: /**
113: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
114: * XSL Content Model: marker* (%block;)+
115: * But: "In addition an fo:block-container that does not generate an
116: * absolutely positioned area may have a sequence of zero or more
117: * fo:markers as its initial children."
118: * @todo - implement above restriction if possible
119: */
120: protected void validateChildNode(Locator loc, String nsURI,
121: String localName) throws ValidationException {
122: if (FO_URI.equals(nsURI) && localName.equals("marker")) {
123: if (blockItemFound) {
124: nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
125: }
126: } else if (!isBlockItem(nsURI, localName)) {
127: invalidChildError(loc, nsURI, localName);
128: } else {
129: blockItemFound = true;
130: }
131: }
132:
133: /**
134: * @see org.apache.fop.fo.FONode#endOfNode
135: */
136: protected void endOfNode() throws FOPException {
137: if (!blockItemFound) {
138: missingChildElementError("marker* (%block;)+");
139: }
140:
141: getFOEventHandler().endBlockContainer(this );
142: }
143:
144: /**
145: * @return true (BlockContainer can generate Reference Areas)
146: */
147: public boolean generatesReferenceAreas() {
148: return true;
149: }
150:
151: /**
152: * @return the Common Absolute Position Properties.
153: */
154: public CommonAbsolutePosition getCommonAbsolutePosition() {
155: return commonAbsolutePosition;
156: }
157:
158: /**
159: * @return the Common Margin Properties-Block.
160: */
161: public CommonMarginBlock getCommonMarginBlock() {
162: return commonMarginBlock;
163: }
164:
165: /**
166: * @return the Common Border, Padding, and Background Properties.
167: */
168: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
169: return commonBorderPaddingBackground;
170: }
171:
172: /**
173: * @return the "block-progression-dimension" property.
174: */
175: public LengthRangeProperty getBlockProgressionDimension() {
176: return blockProgressionDimension;
177: }
178:
179: /** @return the display-align property. */
180: public int getDisplayAlign() {
181: return displayAlign;
182: }
183:
184: /** @return the "break-after" property. */
185: public int getBreakAfter() {
186: return breakAfter;
187: }
188:
189: /** @return the "break-before" property. */
190: public int getBreakBefore() {
191: return breakBefore;
192: }
193:
194: /** @return the "keep-with-next" property. */
195: public KeepProperty getKeepWithNext() {
196: return keepWithNext;
197: }
198:
199: /** @return the "keep-with-previous" property. */
200: public KeepProperty getKeepWithPrevious() {
201: return keepWithPrevious;
202: }
203:
204: /** @return the "keep-together" property. */
205: public KeepProperty getKeepTogether() {
206: return keepTogether;
207: }
208:
209: /**
210: * @return the "inline-progression-dimension" property.
211: */
212: public LengthRangeProperty getInlineProgressionDimension() {
213: return inlineProgressionDimension;
214: }
215:
216: /**
217: * @return the "overflow" property.
218: */
219: public int getOverflow() {
220: return overflow;
221: }
222:
223: /**
224: * @return the "reference-orientation" property.
225: */
226: public int getReferenceOrientation() {
227: return referenceOrientation.getValue();
228: }
229:
230: /**
231: * @return the "span" property.
232: */
233: public int getSpan() {
234: return this .span;
235: }
236:
237: /**
238: * @return the "writing-mode" property.
239: */
240: public int getWritingMode() {
241: return writingMode;
242: }
243:
244: /**
245: * @return the width property
246: */
247: public Length getWidth() {
248: return width;
249: }
250:
251: /**
252: * @return the height property
253: */
254: public Length getHeight() {
255: return height;
256: }
257:
258: /** @see org.apache.fop.fo.FONode#getLocalName() */
259: public String getLocalName() {
260: return "block-container";
261: }
262:
263: /**
264: * @see org.apache.fop.fo.FObj#getNameId()
265: */
266: public int getNameId() {
267: return FO_BLOCK_CONTAINER;
268: }
269: }
|