1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import java.util.Enumeration ; 26 import java.util.Iterator ; 27 28 import com.sun.enterprise.deployment.Descriptor; 29 import com.sun.enterprise.deployment.JspConfigDescriptor; 30 import com.sun.enterprise.deployment.JspGroupDescriptor; 31 import com.sun.enterprise.deployment.WebBundleDescriptor; 32 import com.sun.enterprise.deployment.WebComponentDescriptor; 33 import com.sun.enterprise.deployment.web.SecurityConstraint; 34 import com.sun.enterprise.deployment.web.ServletFilterMapping; 35 import com.sun.enterprise.deployment.web.WebResourceCollection; 36 import com.sun.enterprise.tools.verifier.Result; 37 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 38 39 47 public abstract class URLPattern extends WebTest implements WebCheck { 48 protected boolean oneFailed=false, oneWarning=false; 50 51 59 public Result check(WebBundleDescriptor descriptor) { 60 61 Result result = getInitializedResult(); 62 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 63 64 result.setStatus(Result.NOT_APPLICABLE); 65 result.addNaDetails(smh.getLocalString 66 ("tests.componentNameConstructor", 67 "For [ {0} ]", 68 new Object [] {compName.toString()})); 69 result.addNaDetails(smh.getLocalString 70 (getClass().getName() + ".notApplicable", 71 "There is no url-pattern element within the web archive [ {0} ]", 72 new Object [] {descriptor.getName()})); 73 checkWebResourceCollections(descriptor, result, compName); 74 checkServletMappings(descriptor, result, compName); 75 checkServletFilterMappings(descriptor, result, compName); 76 checkJspGroupProperties(descriptor, result, compName); 77 78 if(oneFailed) result.setStatus(Result.FAILED); 79 else if(oneWarning) result.setStatus(Result.WARNING); 80 return result; 81 } 82 83 protected abstract void checkUrlPatternAndSetResult(String urlPattern, Descriptor descriptor, Result result, ComponentNameConstructor compName); 85 86 private void checkWebResourceCollections(WebBundleDescriptor descriptor, Result result, ComponentNameConstructor compName){ 87 Enumeration e=descriptor.getSecurityConstraints(); 88 while (e.hasMoreElements()) { 89 SecurityConstraint securityConstraint = (SecurityConstraint) e.nextElement(); 90 Enumeration ee = securityConstraint.getWebResourceCollections(); 91 while (ee.hasMoreElements()) { 92 WebResourceCollection webResourceCollection = (WebResourceCollection) ee.nextElement(); 93 Enumeration eee = webResourceCollection.getUrlPatterns(); 94 while (eee.hasMoreElements()) { 95 checkUrlPatternAndSetResult((String ) eee.nextElement(), descriptor, result, compName); 96 } 97 } 98 } 99 } 100 101 private void checkServletMappings(WebBundleDescriptor descriptor, Result result, ComponentNameConstructor compName){ 102 for(Iterator iter=descriptor.getWebComponentDescriptorsSet().iterator();iter.hasNext();) 103 for(Iterator iter2=((WebComponentDescriptor)iter.next()).getUrlPatternsSet().iterator(); iter2.hasNext(); 104 checkUrlPatternAndSetResult((String )iter2.next(), descriptor, result, compName)); 105 } 106 107 private void checkServletFilterMappings(WebBundleDescriptor descriptor, Result result, ComponentNameConstructor compName){ 108 for(Iterator iter=descriptor.getServletFilterMappings().iterator();iter.hasNext();){ 109 ServletFilterMapping filterMapping=(ServletFilterMapping)iter.next(); 110 if(filterMapping.getURLPatterns().size() > 0) { 111 for(String url : filterMapping.getURLPatterns()) 112 checkUrlPatternAndSetResult(url, descriptor, result, compName); 113 } 114 } 115 } 116 117 private void checkJspGroupProperties(WebBundleDescriptor descriptor, Result result, ComponentNameConstructor compName){ 119 JspConfigDescriptor jspC=descriptor.getJspConfigDescriptor(); 120 if(jspC==null) return; 121 for(Iterator iter=jspC.getJspGroupSet().iterator();iter.hasNext();){ 122 for(Iterator iter2=((JspGroupDescriptor)iter.next()).getUrlPatternsSet().iterator(); 123 iter2.hasNext(); 124 checkUrlPatternAndSetResult((String )iter2.next(), descriptor, result, compName)); 125 } 126 } 127 } 128 | Popular Tags |