KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > runtime > ASLocaleCharsetInfo


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
26 package com.sun.enterprise.tools.verifier.tests.web.runtime;
27
28
29 import com.sun.enterprise.deployment.*;
30 import com.sun.enterprise.tools.verifier.*;
31 import com.sun.enterprise.tools.verifier.tests.*;
32 import com.sun.enterprise.deployment.WebBundleDescriptor;
33 import com.sun.enterprise.tools.verifier.tests.web.*;
34 import com.sun.enterprise.deployment.runtime.web.*;
35 import java.util.*;
36 import java.nio.charset.*;
37
38 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
39
/* Changed the result messages to reflect consistency between the result messages generated
40  * for the EJB test cases for SunONE specific deployment descriptors*/

41 //</addition>
42

43 public class ASLocaleCharsetInfo extends WebTest implements WebCheck {
44
45
46     public Result check(WebBundleDescriptor descriptor) {
47     Result result = getInitializedResult();
48     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
49         boolean oneFailed = false;
50     boolean oneWarning = false;
51     boolean notApp = false;
52
53         String JavaDoc formHintField;
54         //Nlsinfo nlsInfo = descriptor.getIasWebApp().getNlsinfo();
55
try{
56         LocaleCharsetInfo nlsInfo = (descriptor.getSunDescriptor()).getLocaleCharsetInfo();
57         if (nlsInfo != null){
58         //Test 1: check validity of default-locale
59
Locale[] locales = Locale.getAvailableLocales();
60             String JavaDoc defaultLocale=nlsInfo.getAttributeValue(LocaleCharsetInfo.DEFAULT_LOCALE);
61         if(defaultLocale == null || defaultLocale.length() == 0){
62                     oneFailed = true;
63                     addErrorDetails(result, compName);
64                         result.failed(smh.getLocalString
65                                         (getClass().getName() + ".failed",
66                                         "FAILED [AS-WEB local-charset-info] Empty "+ defaultLocale +" [ {0} ] is not valid.",
67                                         new Object JavaDoc[] {defaultLocale}));
68         }else{
69         boolean delocFlag=false;
70                 for(int index=0;index < locales.length;index++){
71                     if(defaultLocale.equalsIgnoreCase(locales[index].toString())){
72                         delocFlag =true;
73             break;
74                      }
75                 }
76         if(delocFlag){
77                     addGoodDetails(result, compName);
78                     result.passed(smh.getLocalString
79                     (getClass().getName() + ".passed",
80                                 "PASSED [AS-WEB locale-charset-info] Properly "+ defaultLocale +" [ {0} ] defined in the war file.",
81                                 new Object JavaDoc[] {defaultLocale}));
82
83         }else{
84             oneWarning = true;
85                         addWarningDetails(result, compName);
86                         result.warning(smh.getLocalString
87                                         (getClass().getName() + ".warning",
88                                         "WARNING [AS-WEB local-charset-info] attribute default_locale [ {0} ] is not valid.",
89                                         new Object JavaDoc[] {defaultLocale}));
90                 }
91            }
92        //Test 2: check validity of charset
93
LocaleCharsetMap[] localeCharMaps=nlsInfo.getLocaleCharsetMap();
94        for (int rep=0; rep<localeCharMaps.length; rep++ ) {
95         //Test 2.1: check validity of each locale
96
boolean charMapLocFlag=false;
97                 String JavaDoc locale = localeCharMaps[rep].getAttributeValue(LocaleCharsetMap.LOCALE);
98                 if (locale == null || locale.length() == 0){
99                                         oneFailed = true;
100                                         addErrorDetails(result, compName);
101                                         result.failed(smh.getLocalString
102                                                 (getClass().getName() + ".failed1",
103                                                 "FAILED [AS-WEB local-charset-map] attribute locale [ {0} ] must be of finite length.",
104                                                 new Object JavaDoc[] {locale}));
105         }else{
106             for(int index=0;index < locales.length;index++){
107                 if(locale.equalsIgnoreCase(locales[index].toString())){
108                     charMapLocFlag=true;
109                     break;
110                 }
111                     }
112             if(!charMapLocFlag) {
113                                         oneWarning = true;
114                                         addWarningDetails(result, compName);
115                                         result.warning(smh.getLocalString
116                                                 (getClass().getName() + ".warning1",
117                                                 "WARNING [AS-WEB local-charset-map] attribute locale [ {0} ] is not valid.",
118                                                 new Object JavaDoc[] {locale}));
119                         }else{
120                                 addGoodDetails(result, compName);
121                                 result.passed(smh.getLocalString
122                         (getClass().getName() + ".passed1",
123                         "PASSED [AS-WEB locale-charset-map] attribute locale [ {0} ] properly defined.",
124                         new Object JavaDoc[] {locale}));
125             }
126                 }
127         //Test 2.2: check validity of each charset
128
String JavaDoc charset = localeCharMaps[rep].getAttributeValue(LocaleCharsetMap.CHARSET);
129         if( charset == null || charset.length()==0) {
130                     oneFailed = true;
131                             addErrorDetails(result, compName);
132                                         result.failed(smh.getLocalString
133                                                 (getClass().getName() + ".failed3",
134                                                 "FAILED [AS-WEB local-charset-map] attribute charset [ {0} ] must be of standard format.",
135                                                 new Object JavaDoc[] {charset}));
136         }else{
137             try{
138                     Charset cs=Charset.forName(charset);
139                                 addGoodDetails(result, compName);
140                                 result.passed(smh.getLocalString
141                         (getClass().getName() + ".passed2",
142                         "PASSED [AS-WEB locale-charset-map] attributes charset [ {0} ] properly defined.",
143                         new Object JavaDoc[] {charset}));
144             }catch(UnsupportedCharsetException ex){
145                                         oneWarning = true;
146                                         addWarningDetails(result, compName);
147                                         result.warning(smh.getLocalString
148                                                 (getClass().getName() + ".warning2",
149                                                 "WARNING [AS-WEB local-charset-map] attribute charset [ {0} ] is not valid.",
150                                                 new Object JavaDoc[] {charset}));
151             }
152             catch(IllegalCharsetNameException ex){
153                     oneFailed = true;
154                                         addErrorDetails(result, compName);
155                                         result.failed(smh.getLocalString
156                                                 (getClass().getName() + ".failed3",
157                                                 "FAILED [AS-WEB local-charset-map] attribute charset [ {0} ] must be of standard format.",
158                                                 new Object JavaDoc[] {charset}));
159             }
160         }
161             }//for
162

163
164             //chk for parameter encoding pending, as NLSInfo object still dont support it.// to-do vkv#
165

166         } else {
167             notApp = true;
168             addNaDetails(result, compName);
169             result.notApplicable(smh.getLocalString
170                      (getClass().getName() + ".notApplicable",
171                       "NOT APPLICABLE [AS-WEB sun-web-app] locale-charset-info element not defined in this web archive [ {0} ].",
172                       new Object JavaDoc[] {descriptor.getName()}));
173         }
174         if (oneFailed) {
175             result.setStatus(Result.FAILED);
176         } else
177          if (oneWarning){
178                         result.setStatus(Result.WARNING);
179                         }
180           else
181         if(notApp) {
182             result.setStatus(Result.NOT_APPLICABLE);
183         }else {
184             result.setStatus(Result.PASSED);
185             addGoodDetails(result, compName);
186             result.passed
187             (smh.getLocalString
188              (getClass().getName() + ".passed3",
189               "PASSED [AS-WEB sun-web-app] locale-charset-info elements are valid within the web archive [ {0} ] .",
190                             new Object JavaDoc[] {descriptor.getName()} ));
191         }
192        }catch(Exception JavaDoc ex){
193             oneFailed = true;
194             addErrorDetails(result, compName);
195             result.failed(smh.getLocalString
196                 (getClass().getName() + ".failed2",
197                     "FAILED [AS-WEB sun-web-app] could not create the local-charset-info object"));
198        }
199     return result;
200     }
201 }
202
203     
204
Popular Tags