1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 26 import java.util.*; 27 import java.io.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 32 33 34 38 public class Location extends WebTest implements WebCheck { 39 40 41 49 public Result check(WebBundleDescriptor descriptor) { 50 51 Result result = getInitializedResult(); 52 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 53 54 if (descriptor.getErrorPageDescriptors().hasMoreElements()) { 55 boolean oneFailed = false; 56 boolean foundIt = false; 57 FileArchive arch=null; 60 for (Enumeration e = descriptor.getErrorPageDescriptors() ; e.hasMoreElements() ;) { 62 foundIt = false; 63 ErrorPageDescriptorImpl errorpage = (ErrorPageDescriptorImpl) e.nextElement(); 64 String location = errorpage.getLocation(); 65 String uri = null; 66 try{ 67 uri=getAbstractArchiveUri(descriptor); 70 try{ 71 arch = new FileArchive(); 72 arch.open(uri); 73 }catch(IOException ioe){throw ioe;} 74 if (location.startsWith("/")) 78 location = location.substring(1); 79 File loc = new File(arch.getArchiveUri()+File.separator+location); 85 if(loc.exists()) 86 foundIt=true; 87 loc = null; 88 }catch (Exception ex) { 92 if (!oneFailed){ 93 oneFailed = true; 94 } 95 } 96 if (foundIt) { 97 result.addGoodDetails(smh.getLocalString 98 ("tests.componentNameConstructor", 99 "For [ {0} ]", 100 new Object [] {compName.toString()})); 101 result.addGoodDetails(smh.getLocalString 102 (getClass().getName() + ".passed", 103 "Location [ {0} ] contains the location of the resource within web application [ {1} ]", 104 new Object [] {location, descriptor.getName()})); 105 } else { 106 if (!oneFailed) { 107 oneFailed = true; 108 } 109 result.addErrorDetails(smh.getLocalString 110 ("tests.componentNameConstructor", 111 "For [ {0} ]", 112 new Object [] {compName.toString()})); 113 result.addErrorDetails(smh.getLocalString 114 (getClass().getName() + ".failed", 115 "Error: Location [ {0} ] is not found within [ {1} ] or does not contain the location of the resource within web application [ {2} ]", 116 new Object [] {location, uri, descriptor.getName()})); 117 } 118 } 119 if (oneFailed) { 120 result.setStatus(Result.FAILED); 121 } else { 122 result.setStatus(Result.PASSED); 123 } 124 } else { 125 result.addNaDetails(smh.getLocalString 126 ("tests.componentNameConstructor", 127 "For [ {0} ]", 128 new Object [] {compName.toString()})); 129 result.notApplicable(smh.getLocalString 130 (getClass().getName() + ".notApplicable", 131 "There are no location elements within the web archive [ {0} ]", 132 new Object [] {descriptor.getName()})); 133 } 134 135 return result; 136 } 137 } 138 | Popular Tags |