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: ListItem.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.fo.FONode;
026: import org.apache.fop.fo.FObj;
027: import org.apache.fop.fo.PropertyList;
028: import org.apache.fop.fo.ValidationException;
029: import org.apache.fop.fo.properties.CommonAccessibility;
030: import org.apache.fop.fo.properties.CommonAural;
031: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
032: import org.apache.fop.fo.properties.CommonMarginBlock;
033: import org.apache.fop.fo.properties.CommonRelativePosition;
034: import org.apache.fop.fo.properties.KeepProperty;
035:
036: /**
037: * Class modelling the fo:list-item object.
038: */
039: public class ListItem extends FObj {
040: // The value of properties relevant for fo:list-item.
041: private CommonBorderPaddingBackground commonBorderPaddingBackground;
042: private CommonMarginBlock commonMarginBlock;
043: private int breakAfter;
044: private int breakBefore;
045: private KeepProperty keepTogether;
046: private KeepProperty keepWithNext;
047: private KeepProperty keepWithPrevious;
048: // Unused but valid items, commented out for performance:
049: // private CommonAccessibility commonAccessibility;
050: // private CommonAural commonAural;
051: // private CommonRelativePosition commonRelativePosition;
052: // private int intrusionDisplace;
053: // private int relativeAlign;
054: // End of property values
055:
056: private ListItemLabel label = null;
057: private ListItemBody body = null;
058:
059: /**
060: * @param parent FONode that is the parent of this object
061: */
062: public ListItem(FONode parent) {
063: super (parent);
064: }
065:
066: /**
067: * @see org.apache.fop.fo.FObj#bind(PropertyList)
068: */
069: public void bind(PropertyList pList) throws FOPException {
070: super .bind(pList);
071: commonBorderPaddingBackground = pList
072: .getBorderPaddingBackgroundProps();
073: commonMarginBlock = pList.getMarginBlockProps();
074: breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
075: breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
076: keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
077: keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
078: keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
079: }
080:
081: /**
082: * @see org.apache.fop.fo.FONode#startOfNode
083: */
084: protected void startOfNode() throws FOPException {
085: super .startOfNode();
086: getFOEventHandler().startListItem(this );
087: }
088:
089: /**
090: * Make sure content model satisfied, if so then tell the
091: * FOEventHandler that we are at the end of the flow.
092: * @see org.apache.fop.fo.FONode#endOfNode
093: */
094: protected void endOfNode() throws FOPException {
095: if (label == null || body == null) {
096: missingChildElementError("marker* (list-item-label,list-item-body)");
097: }
098: getFOEventHandler().endListItem(this );
099: }
100:
101: /**
102: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
103: * XSL Content Model: marker* (list-item-label,list-item-body)
104: */
105: protected void validateChildNode(Locator loc, String nsURI,
106: String localName) throws ValidationException {
107: if (FO_URI.equals(nsURI) && localName.equals("marker")) {
108: if (label != null) {
109: nodesOutOfOrderError(loc, "fo:marker",
110: "fo:list-item-label");
111: }
112: } else if (FO_URI.equals(nsURI)
113: && localName.equals("list-item-label")) {
114: if (label != null) {
115: tooManyNodesError(loc, "fo:list-item-label");
116: }
117: } else if (FO_URI.equals(nsURI)
118: && localName.equals("list-item-body")) {
119: if (label == null) {
120: nodesOutOfOrderError(loc, "fo:list-item-label",
121: "fo:list-item-body");
122: } else if (body != null) {
123: tooManyNodesError(loc, "fo:list-item-body");
124: }
125: } else {
126: invalidChildError(loc, nsURI, localName);
127: }
128: }
129:
130: /**
131: * @see org.apache.fop.fo.FONode#addChildNode(FONode)
132: * @todo see if can/should rely on base class for this
133: * (i.e., add to childNodes instead)
134: */
135: public void addChildNode(FONode child) {
136: int nameId = ((FObj) child).getNameId();
137:
138: if (nameId == FO_LIST_ITEM_LABEL) {
139: label = (ListItemLabel) child;
140: } else if (nameId == FO_LIST_ITEM_BODY) {
141: body = (ListItemBody) child;
142: } else if (nameId == FO_MARKER) {
143: addMarker((Marker) child);
144: }
145: }
146:
147: /**
148: * @return the Common Margin Properties-Block.
149: */
150: public CommonMarginBlock getCommonMarginBlock() {
151: return commonMarginBlock;
152: }
153:
154: /**
155: * @return the Common Border, Padding, and Background Properties.
156: */
157: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
158: return commonBorderPaddingBackground;
159: }
160:
161: /**
162: * @return the "break-after" property.
163: */
164: public int getBreakAfter() {
165: return breakAfter;
166: }
167:
168: /**
169: * @return the "break-before" property.
170: */
171: public int getBreakBefore() {
172: return breakBefore;
173: }
174:
175: /** @return the "keep-with-next" property. */
176: public KeepProperty getKeepWithNext() {
177: return keepWithNext;
178: }
179:
180: /** @return the "keep-with-previous" property. */
181: public KeepProperty getKeepWithPrevious() {
182: return keepWithPrevious;
183: }
184:
185: /** @return the "keep-together" property. */
186: public KeepProperty getKeepTogether() {
187: return keepTogether;
188: }
189:
190: /**
191: * @return the label of the list item
192: */
193: public ListItemLabel getLabel() {
194: return label;
195: }
196:
197: /**
198: * @return the body of the list item
199: */
200: public ListItemBody getBody() {
201: return body;
202: }
203:
204: /** @see org.apache.fop.fo.FONode#getLocalName() */
205: public String getLocalName() {
206: return "list-item";
207: }
208:
209: /**
210: * @see org.apache.fop.fo.FObj#getNameId()
211: */
212: public int getNameId() {
213: return FO_LIST_ITEM;
214: }
215: }
|