KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > web > LocaleCharsetInfoNode


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 package com.sun.enterprise.deployment.node.runtime.web;
25
26 import org.xml.sax.Attributes JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29
30 import com.sun.enterprise.deployment.node.XMLElement;
31 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
32 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor;
33 import com.sun.enterprise.deployment.runtime.web.LocaleCharsetInfo;
34
35 /**
36 * node for locale-charset-info tag
37 *
38 * @author Jerome Dochez
39 */

40 public class LocaleCharsetInfoNode extends WebRuntimeNode {
41     
42     /**
43      * Initialize the child handlers
44      */

45     public LocaleCharsetInfoNode() {
46     
47         registerElementHandler(new XMLElement(RuntimeTagNames.LOCALE_CHARSET_MAP),
48                                LocaleCharsetMapNode.class, "addLocaleCharsetMap");
49     }
50     
51     public void startElement(XMLElement element, Attributes JavaDoc attributes) {
52     if (element.getQName().equals(RuntimeTagNames.LOCALE_CHARSET_INFO)) {
53             LocaleCharsetInfo info = (LocaleCharsetInfo) getDescriptor();
54             for (int i=0; i<attributes.getLength();i++) {
55                 if (RuntimeTagNames.DEFAULT_LOCALE.equals(
56                     attributes.getQName(i))) {
57                     info.setAttributeValue(LocaleCharsetInfo.DEFAULT_LOCALE,
58                         attributes.getValue(i));
59                 }
60             }
61         } else if (element.getQName().equals(
62             RuntimeTagNames.PARAMETER_ENCODING)) {
63         LocaleCharsetInfo info = (LocaleCharsetInfo) getDescriptor();
64             info.setParameterEncoding(true);
65             for (int i=0; i<attributes.getLength();i++) {
66                 if (RuntimeTagNames.DEFAULT_CHARSET.equals(
67                     attributes.getQName(i))) {
68                     info.setAttributeValue(LocaleCharsetInfo.PARAMETER_ENCODING,
69                         LocaleCharsetInfo.DEFAULT_CHARSET,
70                         attributes.getValue(i));
71                 }
72                 if (RuntimeTagNames.FORM_HINT_FIELD.equals(
73                     attributes.getQName(i))) {
74                     info.setAttributeValue(LocaleCharsetInfo.PARAMETER_ENCODING,
75                         LocaleCharsetInfo.FORM_HINT_FIELD,
76                         attributes.getValue(i));
77                 }
78             }
79     } else super.startElement(element, attributes);
80     }
81     
82     /**
83      * write the descriptor class to a DOM tree and return it
84      *
85      * @param parent node for the DOM tree
86      * @param node name for the descriptor
87      * @param the descriptor to write
88      * @return the DOM tree top node
89      */

90     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, LocaleCharsetInfo descriptor) {
91     
92     Element JavaDoc locale = (Element JavaDoc) super.writeDescriptor(parent, nodeName, descriptor);
93     
94     // locale-charset-map+
95
if (descriptor.sizeLocaleCharsetMap()>0) {
96         LocaleCharsetMapNode lcmn = new LocaleCharsetMapNode();
97         for (int i=0;i<descriptor.sizeLocaleCharsetMap();i++) {
98         lcmn.writeDescriptor(locale, RuntimeTagNames.LOCALE_CHARSET_MAP, descriptor.getLocaleCharsetMap(i));
99         }
100     }
101     
102     // <!ELEMENT parameter-encoding EMPTY>
103
//<!ATTLIST parameter-encoding form-hint-field CDATA #IMPLIED
104
// default-charset CDATA #IMPLIED>
105
if (descriptor.isParameterEncoding()) {
106         Element JavaDoc parameter = (Element JavaDoc) appendChild(locale, RuntimeTagNames.PARAMETER_ENCODING);
107         
108         if (descriptor.getAttributeValue(LocaleCharsetInfo.PARAMETER_ENCODING, LocaleCharsetInfo.FORM_HINT_FIELD)!=null) {
109             setAttribute(parameter, RuntimeTagNames.FORM_HINT_FIELD,
110             (String JavaDoc) descriptor.getAttributeValue(LocaleCharsetInfo.PARAMETER_ENCODING, LocaleCharsetInfo.FORM_HINT_FIELD));
111         }
112         
113         
114         if (descriptor.getAttributeValue(LocaleCharsetInfo.PARAMETER_ENCODING, LocaleCharsetInfo.DEFAULT_CHARSET)!=null) {
115             setAttribute(parameter, RuntimeTagNames.DEFAULT_CHARSET,
116             (String JavaDoc) descriptor.getAttributeValue(LocaleCharsetInfo.PARAMETER_ENCODING, LocaleCharsetInfo.DEFAULT_CHARSET));
117         }
118     }
119     
120     // default_locale
121
if (descriptor.getAttributeValue(LocaleCharsetInfo.DEFAULT_LOCALE) != null) {
122         setAttribute(locale, RuntimeTagNames.DEFAULT_LOCALE,
123             (String JavaDoc) descriptor.getAttributeValue(LocaleCharsetInfo.DEFAULT_LOCALE));
124         }
125     return locale;
126     }
127
128 }
129
Popular Tags