KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > FObj


1 /*
2  * $Id: FObj.java,v 1.20.2.9 2003/04/11 00:24:37 pietsch Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.fo;
52
53 // FOP
54
import org.apache.fop.layout.Area;
55 import org.apache.fop.apps.FOPException;
56 import org.apache.fop.datatypes.IDReferences;
57
58 // Java
59
import java.util.HashSet JavaDoc;
60
61 /**
62  * base class for representation of formatting objects and their processing
63  */

64 public abstract class FObj extends FONode {
65
66     public abstract static class Maker {
67         public abstract FObj make(FObj parent, PropertyList propertyList,
68                                   String JavaDoc systemId, int line, int column)
69             throws FOPException;
70     }
71
72     // protected PropertyList properties;
73
public PropertyList properties;
74     protected PropertyManager propMgr;
75     protected String JavaDoc systemId;
76     protected int line;
77     protected int column;
78
79     // markers
80
private HashSet JavaDoc markerClassNames;
81
82     protected FObj(FObj parent, PropertyList propertyList,
83                    String JavaDoc systemId, int line, int column) {
84         super(parent);
85         this.properties = propertyList; // TO BE REMOVED!!!
86
propertyList.setFObj(this);
87         this.propMgr = makePropertyManager(propertyList);
88         this.systemId = systemId;
89         this.line = line;
90         this.column = column;
91         setWritingMode();
92     }
93
94     protected PropertyManager makePropertyManager(PropertyList propertyList) {
95         return new PropertyManager(propertyList);
96     }
97
98     /**
99      * adds characters (does nothing here)
100      * @param data text
101      * @param start start position
102      * @param length length of the text
103      */

104     protected void addCharacters(char data[], int start, int length) {
105         // ignore
106
}
107
108     /**
109      * generates the area or areas for this formatting object
110      * and adds these to the area. This method should always be
111      * overridden by all sub classes
112      *
113      * @param area
114      */

115     public int layout(Area area) throws FOPException {
116         // should always be overridden
117
return Status.OK;
118     }
119
120     /**
121      * returns the name of the formatting object
122      * @return the name of this formatting objects
123      */

124     public abstract String JavaDoc getName();
125
126     /**
127      *
128      */

129 // protected void start() {
130
// // do nothing by default
131
// }
132

133     /**
134      *
135      */

136     protected void end() {
137         // do nothing by default
138
}
139
140     /**
141      * lets outside sources access the property list
142      * first used by PageNumberCitation to find the "id" property
143      * @param name - the name of the desired property to obtain
144      * @return the property
145      */

146     public Property getProperty(String JavaDoc name) {
147         return (properties.get(name));
148     }
149
150
151     /**
152      * Return the "content width" of the areas generated by this FO.
153      * This is used by percent-based properties to get the dimension of
154      * the containing block.
155      * If an FO has a property with a percentage value, that value
156      * is usually calculated on the basis of the corresponding dimension
157      * of the area which contains areas generated by the FO.
158      * NOTE: subclasses of FObj should implement this to return a reasonable
159      * value!
160      */

161     public int getContentWidth() {
162         return 0;
163     }
164
165     /**
166      * removes property id
167      * @param idReferences the id to remove
168      */

169     public void removeID(IDReferences idReferences) {
170         if (((FObj)this).properties.get("id") == null
171                 || ((FObj)this).properties.get("id").getString() == null)
172             return;
173         idReferences.removeID(((FObj)this).properties.get("id").getString());
174         int numChildren = this.children.size();
175         for (int i = 0; i < numChildren; i++) {
176             FONode child = (FONode)children.get(i);
177             if ((child instanceof FObj)) {
178                 ((FObj)child).removeID(idReferences);
179             }
180         }
181     }
182
183     public boolean generatesReferenceAreas() {
184         return false;
185     }
186
187     /**
188      * Set writing mode for this FO.
189      * Find nearest ancestor, including self, which generates
190      * reference areas and use the value of its writing-mode property.
191      * If no such ancestor is found, use the value on the root FO.
192      */

193     protected void setWritingMode() {
194         FObj p;
195         FObj parent;
196         for (p = this;
197                 !p.generatesReferenceAreas() && (parent = p.getParent()) != null;
198                 p = parent);
199         this.properties.setWritingMode(p.getProperty("writing-mode").getEnum());
200     }
201
202
203      public void addMarker(String JavaDoc markerClassName) throws FOPException {
204 // String mcname = marker.getMarkerClassName();
205
if (children != null) {
206              for (int i = 0; i < children.size(); i++) {
207                  FONode child = (FONode)children.get(i);
208                  if (!child.mayPrecedeMarker()) {
209                    throw new FOPException("A fo:marker must be an initial child of '"
210                                           + getName()+"'", systemId, line, column);
211                  }
212              }
213          }
214          if (markerClassNames==null) {
215              markerClassNames = new HashSet JavaDoc();
216              markerClassNames.add(markerClassName);
217          } else if (!markerClassNames.contains(markerClassName) ) {
218              markerClassNames.add(markerClassName);
219          } else {
220              throw new FOPException("marker-class-name '"
221                                     + markerClassName
222                                     + "' already exists for this parent",
223                                     systemId, line, column);
224          }
225      }
226
227 // public boolean hasMarkers() {
228
// return markers!=null;
229
// }
230

231 // public ArrayList getMarkers() {
232
// if (markers==null) {
233
// log.debug("GetMarkers failed (no markers). Should not happen.");
234
// return null;
235
// } else {
236
// return new ArrayList(markers.values());
237
// }
238
// }
239
}
240
241
Popular Tags