KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > IconNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * IconNode.java
26  *
27  * Created on August 19, 2002, 9:55 AM
28  */

29
30 package com.sun.enterprise.deployment.node;
31
32 import java.util.Map JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Locale JavaDoc;
35 import org.xml.sax.Attributes JavaDoc;
36 import org.w3c.dom.Node JavaDoc;
37 import org.w3c.dom.Element JavaDoc;
38
39 import com.sun.enterprise.deployment.xml.TagNames;
40 import com.sun.enterprise.deployment.Descriptor;
41
42 /**
43  *
44  * @author dochez
45  */

46 public class IconNode extends LocalizedNode {
47     
48     private String JavaDoc smallIcon = null;
49     private String JavaDoc largeIcon = null;
50     
51     /**
52      * @return the descriptor for this node
53      */

54     public Object JavaDoc getDescriptor() {
55         return null;
56     }
57     
58     /**
59      * receives notification of the value for a particular tag
60      *
61      * @param element the xml element
62      * @param value it's associated value
63      */

64     public void setElementValue(XMLElement element, String JavaDoc value) {
65         if (element.getQName().equals(TagNames.SMALL_ICON)) {
66             smallIcon = value;
67         } else
68         if (element.getQName().equals(TagNames.LARGE_ICON)) {
69             largeIcon = value;
70         }
71     }
72         
73     /**
74      * notification of the end of XML parsing for this node
75      */

76     public void postParsing() {
77         Object JavaDoc o = getParentNode().getDescriptor();
78         if (o!=null && o instanceof Descriptor) {
79             Descriptor descriptor = (Descriptor) o;
80             if (largeIcon!=null) {
81                 descriptor.setLocalizedLargeIconUri(lang, largeIcon);
82             }
83             if (smallIcon!=null) {
84                 descriptor.setLocalizedSmallIconUri(lang, smallIcon);
85             }
86         }
87     }
88     
89     /**
90      * writes all localized icon information
91      *
92      * @param parentNode for all icon xml fragments
93      * @param descriptor containing the icon information
94      */

95     public void writeLocalizedInfo(Node JavaDoc parentNode, Descriptor descriptor) {
96         Map JavaDoc largeIcons = descriptor.getLocalizedLargeIconUris();
97         Map JavaDoc smallIcons = descriptor.getLocalizedSmallIconUris();
98         if (largeIcons==null && smallIcons==null) {
99             return;
100         }
101         if (smallIcons!=null) {
102             for (Iterator JavaDoc smallItr = smallIcons.keySet().iterator();smallItr.hasNext();) {
103                 String JavaDoc lang = (String JavaDoc) smallItr.next();
104                 String JavaDoc smallIconUri = (String JavaDoc) smallIcons.get(lang);
105                 String JavaDoc largeIconUri = null;
106                 if (largeIcons!=null) {
107                     largeIconUri = (String JavaDoc) largeIcons.get(lang);
108                 }
109                 addIconInfo(parentNode, lang, smallIconUri, largeIconUri);
110             }
111         }
112         if (largeIcons!=null) {
113             for (Iterator JavaDoc largeItr = largeIcons.keySet().iterator();largeItr.hasNext();) {
114                 String JavaDoc lang = (String JavaDoc) largeItr.next();
115                 String JavaDoc largeIconUri = (String JavaDoc) largeIcons.get(lang);
116                 if (smallIcons!=null && smallIcons.get(lang)!=null) {
117                     // we already wrote this icon info in the previous loop
118
continue;
119                 }
120                 addIconInfo(parentNode, lang, null, largeIconUri);
121             }
122         }
123         
124     }
125     
126     /**
127      * writes xml tag and fragment for a particular icon information
128      */

129     private void addIconInfo(Node JavaDoc node, String JavaDoc lang, String JavaDoc smallIconUri, String JavaDoc largeIconUri) {
130         
131         Element JavaDoc iconNode =appendChild(node, TagNames.ICON);
132         if (lang!=Locale.ENGLISH.getLanguage()) {
133         iconNode.setAttributeNS(TagNames.XML_NAMESPACE, TagNames.XML_NAMESPACE_PREFIX + TagNames.LANG, lang);
134     }
135         appendTextChild(iconNode, TagNames.SMALL_ICON, smallIconUri);
136         appendTextChild(iconNode, TagNames.LARGE_ICON, largeIconUri);
137     }
138 }
139
Popular Tags