1 23 24 25 package com.sun.enterprise.tools.verifier.tests; 26 27 import com.sun.enterprise.tools.verifier.Result; 28 import com.sun.enterprise.tools.verifier.SpecVersionMapper; 29 import com.sun.enterprise.tools.verifier.util.VerifierConstants; 30 import com.sun.enterprise.deployment.*; 31 import com.sun.enterprise.deployment.deploy.shared.Archive; 32 33 import java.util.Collection ; 34 import java.util.ArrayList ; 35 import java.util.Enumeration ; 36 37 42 public class IconImageTypeTest extends VerifierTest implements VerifierCheck{ 43 private Collection <String > smallIconUris = new ArrayList <String >(); 44 private Collection <String > largeIconUris = new ArrayList <String >(); 45 private Descriptor descriptor; 46 private Result result; 47 ComponentNameConstructor compName; 48 private static final String [] allowableImageTypesForJavaEEOlderThan5 = {".gif", ".jpg"}; 49 private static final String [] allowableImageTypesForJavaEE5 = {".gif", ".jpg", ".png"}; 50 public Result check(Descriptor descriptor) { 51 this.descriptor = descriptor; 52 compName = getVerifierContext().getComponentNameConstructor(); 53 result = getInitializedResult(); 54 result.setStatus(Result.PASSED); 55 addGoodDetails(result, compName); 56 result.passed(smh.getLocalString 57 (getClass().getName() + ".passed", "No errors were detected.")); 60 collectIconURIs(); 62 testIconURIType(); 63 testIconURIExistence(); 64 return result; 65 } 66 67 private void testIconURIType() { 68 String [] allowableImageTypes; 69 String JavaEESchemaVersion = getVerifierContext().getJavaEEVersion(); 70 if (JavaEESchemaVersion.compareTo(SpecVersionMapper.JavaEEVersion_5) < 0){ 71 allowableImageTypes = allowableImageTypesForJavaEEOlderThan5; 72 } else { 73 allowableImageTypes = allowableImageTypesForJavaEE5; 74 } 75 76 Collection <String > allURIs = new ArrayList <String >(smallIconUris); 77 allURIs.addAll(largeIconUris); 78 for(String uri : allURIs){ 79 boolean passed = false; 80 for(String allowableType : allowableImageTypes) { 81 if(uri.endsWith(allowableType)) { 82 passed = true; 83 break; 84 } 85 } 86 if(!passed){ 87 addErrorDetails(result, compName); 88 result.failed(smh.getLocalString 89 (getClass().getName() + ".failedImageType", 90 "Error: Unsupported image type used in icon image URI [ {0} ].", 91 new Object []{uri})); 92 } 93 } 94 } 95 96 private void testIconURIExistence() { 97 Collection <String > allURIs = new ArrayList <String >(smallIconUris); 98 allURIs.addAll(largeIconUris); 99 for(String uri : allURIs){ 100 Archive moduleArchive = getVerifierContext().getModuleArchive(); 101 boolean passed = false; 102 for(Enumeration entries = moduleArchive.entries(); entries.hasMoreElements();){ 103 if(uri.equals(entries.nextElement())) { 104 passed = true; 105 break; 106 } 107 } 108 if(!passed){ 109 addErrorDetails(result, compName); 110 result.failed(smh.getLocalString 111 (getClass().getName() + ".failedExistence", 112 "Error: icon image URI [ {0} ] is not packaged inside [ {1} ].", 113 new Object []{uri, getVerifierContext().getModuleArchive().getURI()})); 114 } 115 } 116 } 117 118 private void collectIconURIs(){ 119 if(descriptor instanceof Application) 122 collectIconURIs((Application)descriptor); 123 else if(descriptor instanceof ApplicationClientDescriptor) 124 collectIconURIs((ApplicationClientDescriptor)descriptor); 125 else if(descriptor instanceof EjbDescriptor) 126 collectIconURIs((EjbDescriptor)descriptor); 127 else if(descriptor instanceof ConnectorDescriptor) 128 collectIconURIs((ConnectorDescriptor)descriptor); 129 else if(descriptor instanceof WebBundleDescriptor) 130 collectIconURIs((WebBundleDescriptor)descriptor); 131 else if(descriptor instanceof WebServiceEndpoint) 132 collectIconURIs((WebServiceEndpoint)descriptor); 133 else if(descriptor instanceof ServiceReferenceDescriptor) 134 collectIconURIs((ServiceReferenceDescriptor)descriptor); 135 else { 136 throw new RuntimeException ("Unexpected descriptor type."); 140 } 141 } 142 143 private void collectIconURIs(Descriptor desc){ 146 String uri=desc.getSmallIconUri(); 147 if(uri!=null && uri.length()>0) smallIconUris.add(uri); 148 uri = desc.getLargeIconUri(); 149 if(uri!=null && uri.length()>0) largeIconUris.add(uri); 150 } 151 152 private void collectIconURIs(WebBundleDescriptor webBundleDescriptor) { 153 collectIconURIs((Descriptor)webBundleDescriptor); 155 for (Object o : webBundleDescriptor.getWebComponentDescriptorsSet()){ 157 collectIconURIs(WebComponentDescriptor.class.cast(o)); 158 } 159 for (Object o : webBundleDescriptor.getServletFilterDescriptors()) { 161 collectIconURIs(ServletFilterDescriptor.class.cast(o)); 162 } 163 } 164 165 private void collectIconURIs(WebServiceEndpoint webServiceEndpoint) { 166 collectIconURIs(webServiceEndpoint.getWebService().getWebServicesDescriptor()); 174 collectIconURIs(webServiceEndpoint.getWebService()); 175 176 collectIconURIs((Descriptor)webServiceEndpoint); 178 for (Object o : webServiceEndpoint.getHandlers()){ 180 collectIconURIs(WebServiceHandler.class.cast(o)); 181 } 182 } 183 184 private void collectIconURIs(EjbDescriptor desc){ 185 collectIconURIs(desc.getEjbBundleDescriptor()); 191 collectIconURIs((Descriptor)descriptor); 193 } 194 } 195 | Popular Tags |