1 25 29 package org.jresearch.gossip.tags; 30 31 import javax.servlet.jsp.JspException ; 32 import javax.servlet.jsp.tagext.TagSupport ; 33 34 import org.apache.log.Logger; 35 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 36 import org.jresearch.gossip.IConst; 37 import org.jresearch.gossip.exception.SystemException; 38 import org.jresearch.gossip.log.avalon.JGossipLog; 39 40 44 public class IsImageTag extends TagSupport { 45 46 private String var; 47 48 private String contentType; 49 50 53 private Logger log; 54 55 58 public IsImageTag() { 59 super(); 60 try { 61 log = JGossipLog.getInstance().getAppLogger(); 62 } catch (SystemException e) { 63 } 64 } 65 66 69 public String getVar() { 70 return var; 71 } 72 73 77 public void setVar(String var) { 78 this.var = var; 79 } 80 81 84 public String getContentType() { 85 return contentType; 86 } 87 88 92 public void setContentType(String value) { 93 this.contentType = value; 94 } 95 96 private void eval() throws JspException { 97 contentType = (String ) ExpressionEvaluatorManager.evaluate( 98 "contentType", contentType, String .class, this, pageContext); 99 } 100 101 106 public int doStartTag() throws JspException { 107 eval(); 108 Boolean isImage = isSupportedMIMEType(contentType); 109 if (this.var != null) 110 pageContext.setAttribute(var, isImage); 111 if (isImage.booleanValue()) { 112 return EVAL_BODY_INCLUDE; 113 } 114 return SKIP_BODY; 115 } 116 117 private Boolean isSupportedMIMEType(String mime) { 118 return new Boolean (IConst.JSP.JPG_CONTENT_TYPE.equals(mime) 119 || IConst.JSP.GIF_CONTENT_TYPE.equals(mime) 120 || IConst.JSP.PNG_CONTENT_TYPE.equals(mime)); 121 } 122 } | Popular Tags |