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: Inline.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.fo.CharIterator;
027: import org.apache.fop.fo.FONode;
028: import org.apache.fop.fo.OneCharIterator;
029: import org.apache.fop.fo.PropertyList;
030: import org.apache.fop.fo.ValidationException;
031: import org.apache.fop.fo.properties.CommonRelativePosition;
032: import org.apache.fop.fo.properties.KeepProperty;
033: import org.apache.fop.fo.properties.LengthRangeProperty;
034:
035: /**
036: * Class modelling the fo:inline formatting object.
037: */
038: public class Inline extends InlineLevel {
039: // The value of properties relevant for fo:inline.
040: // See also superclass InlineLevel
041: private Length alignmentAdjust;
042: private int alignmentBaseline;
043: private Length baselineShift;
044: private int dominantBaseline;
045: // Unused but valid items, commented out for performance:
046: // private CommonRelativePosition commonRelativePosition;
047: // private LengthRangeProperty blockProgressionDimension;
048: // private Length height;
049: // private LengthRangeProperty inlineProgressionDimension;
050: // private KeepProperty keepTogether;
051: // private KeepProperty keepWithNext;
052: // private KeepProperty keepWithPrevious;
053: // private Length width;
054: // private int wrapOption;
055: // End of property values
056: // used for FO validation
057: private boolean blockOrInlineItemFound = false;
058: private boolean canHaveBlockLevelChildren = true;
059:
060: /**
061: * @param parent FONode that is the parent of this object
062: */
063: public Inline(FONode parent) {
064: super (parent);
065: }
066:
067: /**
068: * @see org.apache.fop.fo.FObj#bind(PropertyList)
069: */
070: public void bind(PropertyList pList) throws FOPException {
071: super .bind(pList);
072: alignmentAdjust = pList.get(PR_ALIGNMENT_ADJUST).getLength();
073: alignmentBaseline = pList.get(PR_ALIGNMENT_BASELINE).getEnum();
074: baselineShift = pList.get(PR_BASELINE_SHIFT).getLength();
075: dominantBaseline = pList.get(PR_DOMINANT_BASELINE).getEnum();
076: }
077:
078: /**
079: * @see org.apache.fop.fo.FONode#startOfNode
080: */
081: protected void startOfNode() throws FOPException {
082: super .startOfNode();
083:
084: /* Check to see if this node can have block-level children.
085: * See validateChildNode() below.
086: */
087: int lvlLeader = findAncestor(FO_LEADER);
088: int lvlFootnote = findAncestor(FO_FOOTNOTE);
089: int lvlInCntr = findAncestor(FO_INLINE_CONTAINER);
090:
091: if (lvlLeader > 0) {
092: if (lvlInCntr < 0
093: || (lvlInCntr > 0 && lvlInCntr > lvlLeader)) {
094: canHaveBlockLevelChildren = false;
095: }
096: } else if (lvlFootnote > 0) {
097: if (lvlInCntr < 0 || lvlInCntr > lvlFootnote) {
098: canHaveBlockLevelChildren = false;
099: }
100: }
101:
102: getFOEventHandler().startInline(this );
103: }
104:
105: /**
106: * @see org.apache.fop.fo.FONode#endOfNode
107: */
108: protected void endOfNode() throws FOPException {
109: super .endOfNode();
110: getFOEventHandler().endInline(this );
111: }
112:
113: /**
114: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
115: * XSL Content Model: marker* (#PCDATA|%inline;|%block;)*
116: * Additionally: " An fo:inline that is a descendant of an fo:leader
117: * or fo:footnote may not have block-level children, unless it has a
118: * nearer ancestor that is an fo:inline-container." (paraphrased)
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 (blockOrInlineItemFound) {
124: nodesOutOfOrderError(loc, "fo:marker",
125: "(#PCDATA|%inline;|%block;)");
126: }
127: } else if (!isBlockOrInlineItem(nsURI, localName)) {
128: invalidChildError(loc, nsURI, localName);
129: } else if (!canHaveBlockLevelChildren
130: && isBlockItem(nsURI, localName)) {
131: String ruleViolated = " An fo:inline that is a descendant of an fo:leader"
132: + " or fo:footnote may not have block-level children,"
133: + " unless it has a nearer ancestor that is an"
134: + " fo:inline-container.";
135: invalidChildError(loc, nsURI, localName, ruleViolated);
136: } else {
137: blockOrInlineItemFound = true;
138: }
139: }
140:
141: /**
142: * @return the "alignment-adjust" property
143: */
144: public Length getAlignmentAdjust() {
145: return alignmentAdjust;
146: }
147:
148: /**
149: * @return the "alignment-baseline" property
150: */
151: public int getAlignmentBaseline() {
152: return alignmentBaseline;
153: }
154:
155: /**
156: * @return the "baseline-shift" property
157: */
158: public Length getBaselineShift() {
159: return baselineShift;
160: }
161:
162: /**
163: * @return the "dominant-baseline" property
164: */
165: public int getDominantBaseline() {
166: return dominantBaseline;
167: }
168:
169: /** @see org.apache.fop.fo.FONode#getLocalName() */
170: public String getLocalName() {
171: return "inline";
172: }
173:
174: /**
175: * @see org.apache.fop.fo.FObj#getNameId()
176: */
177: public int getNameId() {
178: return FO_INLINE;
179: }
180: }
|