1 23 package com.sun.enterprise.tools.verifier.tests.app; 24 25 import java.io.*; 26 27 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile; 28 import com.sun.enterprise.deployment.Application; 29 import com.sun.enterprise.tools.verifier.*; 30 31 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 32 33 38 public class AppPublicID extends ApplicationTest implements AppCheck { 39 40 41 String acceptablePubidLiterals[] = { 42 "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN", 43 "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" }; 44 45 String acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/application_1_2.dtd", 46 "http://java.sun.com/dtd/application_1_3.dtd"}; 47 48 57 public Result check(Application descriptor) { 58 59 Result result = getInitializedResult(); 60 61 if (descriptor.getSpecVersion().compareTo("1.4") < 0){ 63 InputStream deploymentEntry=null; 64 65 String uri = null; 66 try { 67 uri = getAbstractArchiveUri(descriptor); 68 FileArchive arch = new FileArchive(); 69 arch.open(uri); 70 deploymentEntry = arch.getEntry( 71 ApplicationDeploymentDescriptorFile.DESC_PATH); 72 73 if (deploymentEntry != null) { 74 BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry)); 75 String s = in.readLine(); 76 boolean foundDOCTYPE = false, foundPubid = false, foundURL = false; 77 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 87 (smh.getLocalString 88 (getClass().getName() + ".passed", 89 "The deployment descriptor has the proper PubidLiteral: {0}", 90 new Object [] {acceptablePubidLiterals[i]})); 91 } 92 if (s.indexOf(acceptableURLs[i]) > -1) { 94 foundURL = true; 95 result.addGoodDetails 96 (smh.getLocalString 97 (getClass().getName() + ".passed1", 98 "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}", 99 new Object [] {acceptableURLs[i]})); 100 } 101 } 102 } 103 if(foundPubid && foundURL) { 104 result.setStatus(Result.PASSED); 105 break; 106 } else if(foundDOCTYPE && s.endsWith(">")) break; s = in.readLine(); 108 } 109 110 if(!foundDOCTYPE){ 111 112 result.failed 113 (smh.getLocalString 114 (getClass().getName() + ".failed1", 115 "No document type declaration found in the deployment descriptor for {0}", 116 new Object [] {descriptor.getName()})); 117 } else if(!foundPubid) { 118 119 result.failed 120 (smh.getLocalString 121 (getClass().getName() + ".failed2", 122 "The deployment descriptor for {0} does not have the expected PubidLiteral ", 123 new Object [] {descriptor.getName()})); 124 }else if (!foundURL){ 125 126 result.failed(smh.getLocalString 127 (getClass().getName() + ".failed", 128 "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", 129 new Object [] {descriptor.getName()})); 130 } 131 } 132 133 } catch (IOException e) { 134 135 result.failed(smh.getLocalString 136 (getClass().getName() + ".IOException", 137 "I/O error trying to open {0}", new Object [] {uri})); 138 } finally { 139 try { 140 if (deploymentEntry != null) 141 deploymentEntry.close(); 142 } catch (Exception x) {} 143 } 144 }else{ 145 150 result.notApplicable(smh.getLocalString 151 (getClass().getName() + ".notApplicable", 152 "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]", 153 new Object [] {descriptor.getName()})); 154 } 155 return result; 156 } 157 } 158 | Popular Tags |