1 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 41 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 formHintField; 54 try{ 56 LocaleCharsetInfo nlsInfo = (descriptor.getSunDescriptor()).getLocaleCharsetInfo(); 57 if (nlsInfo != null){ 58 Locale[] locales = Locale.getAvailableLocales(); 60 String 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 [] {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 [] {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 [] {defaultLocale})); 90 } 91 } 92 LocaleCharsetMap[] localeCharMaps=nlsInfo.getLocaleCharsetMap(); 94 for (int rep=0; rep<localeCharMaps.length; rep++ ) { 95 boolean charMapLocFlag=false; 97 String 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 [] {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 [] {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 [] {locale})); 125 } 126 } 127 String 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 [] {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 [] {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 [] {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 [] {charset})); 159 } 160 } 161 } 163 164 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 [] {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 [] {descriptor.getName()} )); 191 } 192 }catch(Exception 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 |