FileDocCategorySizeDatePackage
MimeTypeElement.javaAPI DocGlassfish v2 API6481Fri May 04 22:34:14 BST 2007com.sun.enterprise.tools.verifier.tests.web.elements

MimeTypeElement

public class MimeTypeElement extends com.sun.enterprise.tools.verifier.tests.web.WebTest implements com.sun.enterprise.tools.verifier.tests.web.WebCheck, MimeTypes
Servlet mime-type element contains a defined mime type. i.e. "text/plain"

Fields Summary
Constructors Summary
Methods Summary
public Resultcheck(WebBundleDescriptor descriptor)
Servlet mime-type element contains a defined mime type. i.e. "text/plain"

param
descriptor the Web deployment descriptor
return
Result the results for this assertion


	Result result = getInitializedResult();
	ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();

	if (descriptor.getMimeMappings().hasMoreElements()) {
	    boolean oneFailed = false;
	    boolean foundIt = false;
	    // get the mimeType's in this .war
	    for (Enumeration e = descriptor.getMimeMappings() ; e.hasMoreElements() ;) {
		foundIt = false;
		MimeMappingDescriptor mimemapping = (MimeMappingDescriptor)e.nextElement();
		String mimeType = mimemapping.getMimeType();
		logger.log(Level.FINE, "servlet mimeType: " + mimeType);
		int pos = mimeType.indexOf("/");
		// user defined
		// see http://www-dos.uniinc.msk.ru/tech1/1995/mime/m_tech.htm#Type

		if (mimeType.substring(pos+1).startsWith("X-") || mimeType.substring(pos+1).startsWith("x-")) {
		    foundIt = true;
		} else if (mimeType.startsWith("X-")) {
                    foundIt = true;
                } else if (mimeType.substring(0,pos).equals("text")) {
		    if (Arrays.asList(text).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("multipart")) {
		    if (Arrays.asList(multipart).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("message")) {
		    if (Arrays.asList(message).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("application")) {
		    if (Arrays.asList(application).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("image")) {
		    if (Arrays.asList(image).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("audio")) {
		    if (Arrays.asList(audio).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("video")) {
		    if (Arrays.asList(video).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		} else if (mimeType.substring(0,pos).equals("model")) {
		    if (Arrays.asList(model).contains(mimeType.substring(pos+1,mimeType.length()))) {
			foundIt = true;
		    } 
		}
   
		if (foundIt) {
		    result.addGoodDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
		    result.addGoodDetails(smh.getLocalString
					  (getClass().getName() + ".passed",
					   "Servlet mime-type [ {0} ] defined for this web application [ {1} ]",
					   new Object[] {mimeType, descriptor.getName()}));
		} else {
		    if (!oneFailed) {
			oneFailed = true;
		    }
		    result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
		    result.addErrorDetails(smh.getLocalString
					   (getClass().getName() + ".failed",
					    "Error: Servlet mime-type [ {0} ] not defined for this web application [ {1} ]",
					    new Object[] {mimeType, descriptor.getName()}));
		}
	    }
	    if (oneFailed) {
		result.setStatus(Result.FAILED);
	    } else {
		result.setStatus(Result.PASSED);
	    }
	} else {
	    result.addNaDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
	    result.notApplicable(smh.getLocalString
				 (getClass().getName() + ".notApplicable",
				  "There are no mimemappings within the web archive [ {0} ]",
				  new Object[] {descriptor.getName()}));
	}
	return result;