KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > pagination > Declarations


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: Declarations.java 474225 2006-11-13 10:08:19Z jeremias $ */
19
20 package org.apache.fop.fo.pagination;
21
22 // Java
23
import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.xml.sax.Locator JavaDoc;
27
28 import org.apache.fop.apps.FOPException;
29 import org.apache.fop.fo.FONode;
30 import org.apache.fop.fo.FObj;
31 import org.apache.fop.fo.PropertyList;
32 import org.apache.fop.fo.ValidationException;
33
34 /**
35  * Declarations formatting object.
36  * A declarations formatting object holds a set of color-profiles
37  * and optionally additional non-XSL namespace elements.
38  * The color-profiles are held in a hashmap for use with color-profile
39  * references.
40  */

41 public class Declarations extends FObj {
42
43     private Map JavaDoc colorProfiles = null;
44
45     /**
46      * @param parent FONode that is the parent of this object
47      */

48     public Declarations(FONode parent) {
49         super(parent);
50         ((Root) parent).setDeclarations(this);
51     }
52
53     /**
54      * @see org.apache.fop.fo.FObj#bind(PropertyList)
55      */

56     public void bind(PropertyList pList) throws FOPException {
57         // No properties defined for fo:declarations
58
}
59
60     /**
61      * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
62      * XSL 1.0: (color-profile)+ (and non-XSL NS nodes)
63      * FOP/XSL 1.1: (color-profile)* (and non-XSL NS nodes)
64      */

65     protected void validateChildNode(Locator JavaDoc loc, String JavaDoc nsURI, String JavaDoc localName)
66                 throws ValidationException {
67         if (FO_URI.equals(nsURI)) {
68             if (!localName.equals("color-profile")) {
69                 invalidChildError(loc, nsURI, localName);
70             }
71         } // anything outside of XSL namespace is OK.
72
}
73
74     /**
75      * At the end of this element sort out the children into
76      * a hashmap of color profiles and a list of extension attachments.
77      * @see org.apache.fop.fo.FONode#endOfNode()
78      */

79     protected void endOfNode() throws FOPException {
80         if (childNodes != null) {
81             for (Iterator JavaDoc iter = childNodes.iterator(); iter.hasNext();) {
82                 FONode node = (FONode)iter.next();
83                 if (node.getName().equals("fo:color-profile")) {
84                     ColorProfile cp = (ColorProfile)node;
85                     if (!"".equals(cp.getColorProfileName())) {
86                         addColorProfile(cp);
87                     } else {
88                         getLogger().warn("color-profile-name required for color profile");
89                     }
90                 } else {
91                     getLogger().debug("Ignoring element " + node.getName()
92                             + " inside fo:declarations.");
93                 }
94             }
95         }
96         childNodes = null;
97     }
98
99     private void addColorProfile(ColorProfile cp) {
100         if (colorProfiles == null) {
101             colorProfiles = new java.util.HashMap JavaDoc();
102         }
103         if (colorProfiles.get(cp.getColorProfileName()) != null) {
104             // duplicate names
105
getLogger().warn("Duplicate fo:color-profile profile name: "
106                     + cp.getColorProfileName());
107         }
108         colorProfiles.put(cp.getColorProfileName(), cp);
109     }
110
111     /**
112      * @see org.apache.fop.fo.FObj#getName()
113      */

114     public String JavaDoc getLocalName() {
115         return "declarations";
116     }
117     
118     /**
119      * @see org.apache.fop.fo.FObj#getNameId()
120      */

121     public int getNameId() {
122         return FO_DECLARATIONS;
123     }
124     
125     /**
126      * Return ColorProfile with given name.
127      *
128      * @param cpName Name of ColorProfile, i.e. the value of the color-profile-name attribute of
129      * the fo:color-profile element
130      * @return The org.apache.fop.fo.pagination.ColorProfile object associated with this
131      * color-profile-name or null
132      */

133     public ColorProfile getColorProfile(String JavaDoc cpName) {
134         ColorProfile profile = null;
135         if (this.colorProfiles != null) {
136             profile = (ColorProfile)this.colorProfiles.get(cpName);
137         }
138         return profile;
139     }
140     
141     
142 }
143
Popular Tags