KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ias > 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.ias;
27
28
29 import java.util.*;
30 import com.sun.enterprise.deployment.*;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.*;
33 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
34 import com.sun.enterprise.deployment.WebBundleDescriptor;
35 import com.sun.enterprise.tools.verifier.tests.web.*;
36 import com.sun.enterprise.tools.common.dd.webapp.*;
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     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
49         boolean oneFailed = false;
50         boolean notApp = false;
51
52         String JavaDoc defaultLocale;
53         String JavaDoc locale;
54         String JavaDoc charset;
55         String JavaDoc formHintField;
56         LocaleCharsetMap[] localeCharMaps;
57         //Nlsinfo nlsInfo = descriptor.getIasWebApp().getNlsinfo();
58
LocaleCharsetInfo nlsInfo = descriptor.getIasWebApp().getLocaleCharsetInfo();
59         //System.out.println(">>>>>>>>>>>>checking for res " +nlsInfo);
60
if (nlsInfo != null) {
61
62             defaultLocale=nlsInfo.getAttributeValue(MetaData.DEFAULT_LOCALE);
63             localeCharMaps= nlsInfo.getLocaleCharsetMap();
64             //System.out.println(">>>>>>>>>>>> defaultLocale " +defaultLocale);
65
if (defaultLocale!=null || defaultLocale.length() != 0) {
66                     result.passed(smh.getLocalString
67                       (getClass().getName() + ".passed",
68                        "PASSED [AS-WEB locale-charset-info] Proper "+ MetaData.DEFAULT_LOCALE+" [ {0} ] defined in the war file.",
69                        new Object JavaDoc[] {defaultLocale}));
70
71             } else{
72                     if (!oneFailed)
73                         oneFailed = true;
74                     result.failed(smh.getLocalString
75                        (getClass().getName() + ".failed",
76                         "FAILED [AS-WEB local-charset-info] Empty "+ MetaData.DEFAULT_LOCALE+" [ {0} ] is not valid.",
77                         new Object JavaDoc[] {defaultLocale}));
78            }
79
80         for (int rep=0; rep<localeCharMaps.length; rep++ ) {
81         locale = localeCharMaps[rep].getAttributeValue(MetaData.LOCALE);
82                 charset = localeCharMaps[rep].getAttributeValue(MetaData.CHARSET);
83                 //System.out.println(".>>>>>>>>>>>>>checking for locale: "+ locale+" charset : "+ charset);
84
if (locale!=null && charset!=null && locale.length() != 0 && charset.length() != 0) {
85                     result.passed(smh.getLocalString
86                       (getClass().getName() + ".passed1",
87                        "PASSED [AS-WEB locale-charset-map] attributes locale [ {0} ] and charset [ {1} ] properly defined.",
88                        new Object JavaDoc[] {locale, charset}));
89                 } else {
90                     if (!oneFailed)
91                         oneFailed = true;
92                     result.failed(smh.getLocalString
93                                       (getClass().getName() + ".failed1",
94                                       "FAILED [AS-WEB local-charset-map] attributes locale [ {0} ] and charset [ {1} ] must be of finite length.",
95                                       new Object JavaDoc[] {locale, charset}));
96                 }
97             }
98
99
100             //chk for parameter encoding pending, as NLSInfo object still dont support it.// to-do vkv#
101

102         } else {
103             //System.out.println("There are no NLS info defined within the ias-web archive");
104
notApp = true;
105         result.notApplicable(smh.getLocalString
106                  (getClass().getName() + ".notApplicable",
107                   "NOT APPLICABLE [AS-WEB sun-web-app] locale-charset-info element not defined in this web archive [ {0} ].",
108                   new Object JavaDoc[] {descriptor.getName()}));
109         }
110         if (oneFailed) {
111             result.setStatus(Result.FAILED);
112         } else if(notApp) {
113             result.setStatus(Result.NOT_APPLICABLE);
114         }else {
115             result.setStatus(Result.PASSED);
116             result.passed
117             (smh.getLocalString
118              (getClass().getName() + ".passed2",
119               "PASSED [AS-WEB sun-web-app] locale-charset-info elements are valid within the web archive [ {0} ] .",
120                             new Object JavaDoc[] {descriptor.getName()} ));
121         }
122     return result;
123     }
124 }
125
126     
Popular Tags