1 23 package com.sun.enterprise.tools.verifier.tests.web.elements; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 26 import java.util.*; 27 import java.util.logging.Level ; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.tests.web.WebCheck; 30 import com.sun.enterprise.tools.verifier.*; 31 import com.sun.enterprise.tools.verifier.tests.*; 32 33 34 37 public class MimeTypeElement extends WebTest implements WebCheck, MimeTypes { 38 39 46 public Result check(WebBundleDescriptor descriptor) { 47 48 Result result = getInitializedResult(); 49 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 50 51 if (descriptor.getMimeMappings().hasMoreElements()) { 52 boolean oneFailed = false; 53 boolean foundIt = false; 54 for (Enumeration e = descriptor.getMimeMappings() ; e.hasMoreElements() ;) { 56 foundIt = false; 57 MimeMappingDescriptor mimemapping = (MimeMappingDescriptor)e.nextElement(); 58 String mimeType = mimemapping.getMimeType(); 59 logger.log(Level.FINE, "servlet mimeType: " + mimeType); 60 int pos = mimeType.indexOf("/"); 61 64 if (mimeType.substring(pos+1).startsWith("X-") || mimeType.substring(pos+1).startsWith("x-")) { 65 foundIt = true; 66 } else if (mimeType.startsWith("X-")) { 67 foundIt = true; 68 } else if (mimeType.substring(0,pos).equals("text")) { 69 if (Arrays.asList(text).contains(mimeType.substring(pos+1,mimeType.length()))) { 70 foundIt = true; 71 } 72 } else if (mimeType.substring(0,pos).equals("multipart")) { 73 if (Arrays.asList(multipart).contains(mimeType.substring(pos+1,mimeType.length()))) { 74 foundIt = true; 75 } 76 } else if (mimeType.substring(0,pos).equals("message")) { 77 if (Arrays.asList(message).contains(mimeType.substring(pos+1,mimeType.length()))) { 78 foundIt = true; 79 } 80 } else if (mimeType.substring(0,pos).equals("application")) { 81 if (Arrays.asList(application).contains(mimeType.substring(pos+1,mimeType.length()))) { 82 foundIt = true; 83 } 84 } else if (mimeType.substring(0,pos).equals("image")) { 85 if (Arrays.asList(image).contains(mimeType.substring(pos+1,mimeType.length()))) { 86 foundIt = true; 87 } 88 } else if (mimeType.substring(0,pos).equals("audio")) { 89 if (Arrays.asList(audio).contains(mimeType.substring(pos+1,mimeType.length()))) { 90 foundIt = true; 91 } 92 } else if (mimeType.substring(0,pos).equals("video")) { 93 if (Arrays.asList(video).contains(mimeType.substring(pos+1,mimeType.length()))) { 94 foundIt = true; 95 } 96 } else if (mimeType.substring(0,pos).equals("model")) { 97 if (Arrays.asList(model).contains(mimeType.substring(pos+1,mimeType.length()))) { 98 foundIt = true; 99 } 100 } 101 102 if (foundIt) { 103 result.addGoodDetails(smh.getLocalString 104 ("tests.componentNameConstructor", 105 "For [ {0} ]", 106 new Object [] {compName.toString()})); 107 result.addGoodDetails(smh.getLocalString 108 (getClass().getName() + ".passed", 109 "Servlet mime-type [ {0} ] defined for this web application [ {1} ]", 110 new Object [] {mimeType, descriptor.getName()})); 111 } else { 112 if (!oneFailed) { 113 oneFailed = true; 114 } 115 result.addErrorDetails(smh.getLocalString 116 ("tests.componentNameConstructor", 117 "For [ {0} ]", 118 new Object [] {compName.toString()})); 119 result.addErrorDetails(smh.getLocalString 120 (getClass().getName() + ".failed", 121 "Error: Servlet mime-type [ {0} ] not defined for this web application [ {1} ]", 122 new Object [] {mimeType, descriptor.getName()})); 123 } 124 } 125 if (oneFailed) { 126 result.setStatus(Result.FAILED); 127 } else { 128 result.setStatus(Result.PASSED); 129 } 130 } else { 131 result.addNaDetails(smh.getLocalString 132 ("tests.componentNameConstructor", 133 "For [ {0} ]", 134 new Object [] {compName.toString()})); 135 result.notApplicable(smh.getLocalString 136 (getClass().getName() + ".notApplicable", 137 "There are no mimemappings within the web archive [ {0} ]", 138 new Object [] {descriptor.getName()})); 139 } 140 return result; 141 } 142 } 143 | Popular Tags |