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