1 23 package com.sun.enterprise.tools.verifier.tests.appclient; 24 25 import java.io.*; 26 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.deployment.io.DescriptorConstants; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 32 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 33 34 41 public class AppClientPublicID extends AppClientTest implements AppClientCheck { 42 43 String acceptablePubidLiterals[] = { 44 "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN", 45 "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN" }; 46 47 String acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/application-client_1_2.dtd", 48 "http://java.sun.com/dtd/application-client_1_3.dtd"}; 49 50 51 61 public Result check(ApplicationClientDescriptor descriptor) { 62 Result result = getInitializedResult(); 63 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 64 65 if (descriptor.getSpecVersion().compareTo("1.4") < 0){ 67 InputStream deploymentEntry=null; 68 BufferedReader in = null; 69 String uri = null; 70 try { 71 uri = getAbstractArchiveUri(descriptor); 72 FileArchive arch = new FileArchive(); 73 arch.open(uri); 74 deploymentEntry = arch.getEntry( 75 DescriptorConstants.APP_CLIENT_DD_ENTRY); 76 77 if (deploymentEntry != null) { 78 in = new BufferedReader(new InputStreamReader(deploymentEntry)); 79 String s = in.readLine(); 80 boolean foundDOCTYPE = false, foundPubid = false, foundURL = false; 81 82 while(s != null) { 83 if(s.indexOf("DOCTYPE") > -1) 85 foundDOCTYPE = true; 86 if(foundDOCTYPE){ 87 for (int i=0;i<acceptablePubidLiterals.length;i++) { 88 if (s.indexOf(acceptablePubidLiterals[i]) > -1) { 89 foundPubid = true; 90 result.addGoodDetails(smh.getLocalString 91 ("tests.componentNameConstructor", 92 "For [ {0} ]", 93 new Object [] {compName.toString()})); 94 result.addGoodDetails 95 (smh.getLocalString 96 (getClass().getName() + ".passed", 97 "The deployment descriptor has the proper PubidLiteral: {0}", 98 new Object [] {acceptablePubidLiterals[i]})); 99 } 100 if (s.indexOf(acceptableURLs[i]) > -1) { 102 foundURL = true; 103 result.addGoodDetails(smh.getLocalString 104 ("tests.componentNameConstructor", 105 "For [ {0} ]", 106 new Object [] {compName.toString()})); 107 result.addGoodDetails 108 (smh.getLocalString 109 (getClass().getName() + ".passed1", 110 "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}", 111 new Object [] {acceptableURLs[i]})); 112 } 113 } 114 } 115 116 if(foundPubid && foundURL) { 117 result.setStatus(Result.PASSED); 118 break; 119 } else if(foundDOCTYPE && s.endsWith(">")) break; s = in.readLine(); 121 } 122 123 if(!foundDOCTYPE){ 124 result.addErrorDetails(smh.getLocalString 125 ("tests.componentNameConstructor", 126 "For [ {0} ]", 127 new Object [] {compName.toString()})); 128 result.failed 129 (smh.getLocalString 130 (getClass().getName() + ".failed1", 131 "No document type declaration found in the deployment descriptor for {0}", 132 new Object [] {descriptor.getName()})); 133 } else if(!foundPubid) { 134 result.addErrorDetails(smh.getLocalString 135 ("tests.componentNameConstructor", 136 "For [ {0} ]", 137 new Object [] {compName.toString()})); 138 result.failed 139 (smh.getLocalString 140 (getClass().getName() + ".failed2", 141 "The deployment descriptor for {0} does not have an expected PubidLiteral ", 142 new Object [] {descriptor.getName()})); 143 }else if (!foundURL){ 144 result.addErrorDetails(smh.getLocalString 145 ("tests.componentNameConstructor", 146 "For [ {0} ]", 147 new Object [] {compName.toString()})); 148 result.failed(smh.getLocalString 149 (getClass().getName() + ".failed", 150 "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", 151 new Object [] {descriptor.getName()})); 152 } 153 } 154 155 } catch (IOException e) { 156 result.addErrorDetails(smh.getLocalString 157 ("tests.componentNameConstructor", 158 "For [ {0} ]", 159 new Object [] {compName.toString()})); 160 result.failed(smh.getLocalString 161 (getClass().getName() + ".IOException", 162 "I/O error trying to open {0}", new Object [] {uri})); 163 } finally { 164 try { 165 if(in != null) 166 in.close(); 167 if (deploymentEntry != null) 168 deploymentEntry.close(); 169 } catch (Exception x) {} 170 } 171 }else{ 172 result.addNaDetails(smh.getLocalString 174 ("tests.componentNameConstructor", 175 "For [ {0} ]", 176 new Object [] {compName.toString()})); 177 result.notApplicable(smh.getLocalString 178 (getClass().getName() + ".notApplicable", 179 "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]", 180 new Object [] {descriptor.getName()})); 181 } 182 return result; 183 } 184 } 185 | Popular Tags |