KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > extensions > AbstractAFPExtensionObject


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: AbstractAFPExtensionObject.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.extensions;
21
22 // FOP
23
import org.apache.fop.apps.FOPException;
24 import org.apache.fop.fo.FONode;
25 import org.apache.fop.fo.PropertyList;
26 import org.apache.fop.fo.ValidationException;
27 import org.apache.fop.fo.extensions.ExtensionAttachment;
28 import org.xml.sax.Attributes JavaDoc;
29 import org.xml.sax.Locator JavaDoc;
30
31 /**
32  * Base class for the AFP-specific extension elements.
33  */

34 public abstract class AbstractAFPExtensionObject extends FONode {
35
36     private AFPPageSetup setupCode = null;
37
38     private String JavaDoc _name = null;
39     
40     /**
41      * @see org.apache.fop.fo.FONode#FONode(FONode)
42      * @param parent the parent formatting object
43      * @param name the name of the afp element
44      */

45     public AbstractAFPExtensionObject(FONode parent, String JavaDoc name) {
46         super(parent);
47         _name = name;
48         setupCode = new AFPPageSetup(name);
49     }
50
51     /**
52      * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
53      * here, blocks XSL FO's from having non-FO parents.
54      */

55     protected void validateChildNode(Locator JavaDoc loc, String JavaDoc nsURI, String JavaDoc localName)
56                 throws ValidationException {
57         if (FO_URI.equals(nsURI)) {
58             invalidChildError(loc, nsURI, localName);
59         }
60     }
61
62     /** @see org.apache.fop.fo.FONode */
63     protected void addCharacters(char[] data, int start, int length,
64                                  PropertyList pList, Locator JavaDoc locator) {
65     }
66
67     /** @see org.apache.fop.fo.FONode#getNamespaceURI() */
68     public String JavaDoc getNamespaceURI() {
69         return AFPElementMapping.NAMESPACE;
70     }
71
72     /**@see org.apache.fop.fo.FONode#getNormalNamespacePrefix() */
73     public String JavaDoc getNormalNamespacePrefix() {
74         return AFPElementMapping.NAMESPACE_PREFIX;
75     }
76
77     /** @see org.apache.fop.fo.FONode#processNode */
78     public void processNode(String JavaDoc elementName, Locator JavaDoc locator,
79                             Attributes JavaDoc attlist, PropertyList propertyList)
80                                 throws FOPException {
81         String JavaDoc name = attlist.getValue("name");
82         if (name != null && name.length() > 0) {
83             setupCode.setName(name);
84         } else {
85             throw new FOPException(elementName + " must have a name attribute.");
86         }
87         if (AFPElementMapping.INCLUDE_PAGE_SEGMENT.equals(elementName)) {
88             name = attlist.getValue("src");
89             if (name != null && name.length() > 0) {
90                 setupCode.setValue(name);
91             } else {
92                 throw new FOPException(elementName + " must have a src attribute.");
93             }
94         }
95         if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(elementName)) {
96             name = attlist.getValue("value");
97             if (name != null && name.length() > 0) {
98                 setupCode.setValue(name);
99             } else {
100                 throw new FOPException(elementName + " must have a value attribute.");
101             }
102         }
103     }
104
105     /** @see org.apache.fop.fo.FONode#endOfNode() */
106     protected void endOfNode() throws FOPException {
107         super.endOfNode();
108     }
109
110     /** @see org.apache.fop.fo.FONode#getExtensionAttachment() */
111     public ExtensionAttachment getExtensionAttachment() {
112         return this.setupCode;
113     }
114
115     /** @see org.apache.fop.fo.FONode#getLocalName() */
116     public String JavaDoc getLocalName() {
117         return _name;
118     }
119
120 }
121
122
Popular Tags