KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LocalizedNode.java
26  *
27  * Created on August 16, 2002, 4:01 PM
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.w3c.dom.Element JavaDoc;
36 import org.xml.sax.Attributes JavaDoc;
37 import org.w3c.dom.Node JavaDoc;
38
39 import com.sun.enterprise.deployment.xml.TagNames;
40
41 /**
42  * This class is responsible for handling the xml lang attribute of
43  * an xml element
44  *
45  * @author Jerome Dochez
46  */

47 public class LocalizedNode extends DeploymentDescriptorNode {
48     
49     protected String JavaDoc lang = null;
50     protected String JavaDoc localizedValue = null;
51     
52     /**
53      * @return the descriptor for this node
54      */

55     public Object JavaDoc getDescriptor() {
56         return getParentNode().getDescriptor();
57     }
58     
59     /**
60      * notification of element start with attributes.
61      */

62     public void startElement(XMLElement element, Attributes JavaDoc attributes) {
63         if (attributes.getLength()>0) {
64             for (int i=0;i<attributes.getLength();i++) {
65                 if (attributes.getLocalName(i).equals(TagNames.LANG)) {
66                     lang = attributes.getValue(i);
67                 }
68             }
69         }
70     }
71     
72     /**
73      * receives notification of the value for a particular tag
74      *
75      * @param element the xml element
76      * @param value it's associated value
77      */

78     public void setElementValue(XMLElement element, String JavaDoc value) {
79         if (element.equals(getXMLRootTag())) {
80             localizedValue=value;
81         } else
82             super.setElementValue(element, value);
83     }
84     
85     /**
86      * writes all the localized map element usign the tagname with
87      * the lang attribute to a DOM node
88      */

89     public void writeLocalizedMap(Node JavaDoc parentNode, String JavaDoc tagName, Map JavaDoc localizedMap) {
90         if (localizedMap!=null) {
91             for (Iterator JavaDoc itr = localizedMap.keySet().iterator();itr.hasNext();) {
92                 String JavaDoc lang = (String JavaDoc) itr.next();
93                 Element JavaDoc aLocalizedNode = (Element JavaDoc) appendTextChild(parentNode, tagName, (String JavaDoc) localizedMap.get(lang));
94                 if (aLocalizedNode!=null && lang!=Locale.getDefault().getLanguage()) {
95             aLocalizedNode.setAttributeNS(TagNames.XML_NAMESPACE, TagNames.XML_NAMESPACE_PREFIX + TagNames.LANG, lang);
96          }
97             }
98         }
99     }
100     
101 }
102
Popular Tags