1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import java.io.*; 26 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile; 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 35 40 public class WebPublicID extends WebTest implements WebCheck { 41 42 43 52 public Result check(WebBundleDescriptor descriptor) { 53 54 Result result = getInitializedResult(); 55 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 56 String acceptablePubidLiterals[] = { 57 "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" , 58 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" }; 59 60 String acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd", 61 "http://java.sun.com/dtd/web-app_2_3.dtd"}; 62 63 64 if (descriptor.getSpecVersion().compareTo("2.4") < 0){ 66 67 InputStream deploymentEntry=null; 68 try { 69 String uri = getAbstractArchiveUri(descriptor); 70 FileArchive arch = new FileArchive(); 71 arch.open(uri); 72 deploymentEntry = arch.getEntry( 73 WebDeploymentDescriptorFile.DESC_PATH); 74 if (deploymentEntry != null) { 75 BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry)); 76 String s = in.readLine(); 77 boolean foundDOCTYPE = false, foundPubid = false, foundURL = false; 78 while (s != null) { 79 if (s.indexOf("DOCTYPE") > -1) 81 foundDOCTYPE = true; 82 if (foundDOCTYPE) { 83 for (int i=0;i<acceptablePubidLiterals.length;i++) { 84 if (s.indexOf(acceptablePubidLiterals[i]) > -1) { 85 foundPubid = true; 86 result.addGoodDetails(smh.getLocalString 87 ("tests.componentNameConstructor", 88 "For [ {0} ]", 89 new Object [] {compName.toString()})); 90 result.addGoodDetails 91 (smh.getLocalString 92 (getClass().getName() + ".passed", 93 "The deployment descriptor has the proper PubidLiteral: {0}", 94 new Object [] {acceptablePubidLiterals[i]})); 95 } 96 if (s.indexOf(acceptableURLs[i]) > -1) { 97 foundURL = true; 98 result.addGoodDetails(smh.getLocalString 99 ("tests.componentNameConstructor", 100 "For [ {0} ]", 101 new Object [] {compName.toString()})); 102 result.addGoodDetails 103 (smh.getLocalString 104 (getClass().getName() + ".passed1", 105 "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}", 106 new Object [] {acceptableURLs[i]})); 107 } 108 } 109 } 110 if (foundPubid && foundURL) { 111 result.setStatus(Result.PASSED); 112 break; 113 } else if(foundDOCTYPE && s.endsWith(">")) break; s = in.readLine(); 115 } 116 117 if (!foundDOCTYPE){ 118 result.addErrorDetails(smh.getLocalString 119 ("tests.componentNameConstructor", 120 "For [ {0} ]", 121 new Object [] {compName.toString()})); 122 result.failed 123 (smh.getLocalString 124 (getClass().getName() + ".failed1", 125 "No document type declaration found in the deployment descriptor for {0}", 126 new Object [] {descriptor.getName()})); 127 } else if (!foundPubid) { 128 result.addErrorDetails(smh.getLocalString 129 ("tests.componentNameConstructor", 130 "For [ {0} ]", 131 new Object [] {compName.toString()})); 132 result.failed 133 (smh.getLocalString 134 (getClass().getName() + ".failed2", 135 "The deployment descriptor for {0} does not have an expected PubidLiteral ", 136 new Object [] {descriptor.getName()})); 137 }else if (!foundURL) { 138 result.addErrorDetails(smh.getLocalString 139 ("tests.componentNameConstructor", 140 "For [ {0} ]", 141 new Object [] {compName.toString()})); 142 result.failed(smh.getLocalString 143 (getClass().getName() + ".failed", 144 "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", 145 new Object [] {descriptor.getName()})); 146 } 147 } 148 149 } catch (IOException e) { 150 result.addErrorDetails(smh.getLocalString 151 ("tests.componentNameConstructor", 152 "For [ {0} ]", 153 new Object [] {compName.toString()})); 154 result.failed(smh.getLocalString 155 (getClass().getName() + ".IOException", 156 "I/O error trying to open {0}", new Object [] {getAbstractArchiveUri(descriptor)})); 157 } finally { 158 try { 159 if (deploymentEntry != null) 160 deploymentEntry.close(); 161 } catch (Exception x) {} 162 } 163 }else{ 164 result.addNaDetails(smh.getLocalString 166 ("tests.componentNameConstructor", 167 "For [ {0} ]", 168 new Object [] {compName.toString()})); 169 result.notApplicable(smh.getLocalString 170 (getClass().getName() + ".notApplicable", 171 "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]", 172 new Object [] {descriptor.getName()})); 173 } 174 return result; 175 } 176 } 177 | Popular Tags |