KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > tags > IsImageTag


1 /*
2  * $Id$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitriy Belov <bel@jresearch.org>
23  * .
24  * * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 28.08.2004
27  *
28  */

29 package org.jresearch.gossip.tags;
30
31 import javax.servlet.jsp.JspException JavaDoc;
32 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
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 /**
41  * @author Dmitry Belov
42  *
43  */

44 public class IsImageTag extends TagSupport JavaDoc {
45
46     private String JavaDoc var;
47
48     private String JavaDoc contentType;
49
50     /**
51      * Logger instance.
52      */

53     private Logger log;
54
55     /**
56      * Default c'tor.
57      */

58     public IsImageTag() {
59         super();
60         try {
61             log = JGossipLog.getInstance().getAppLogger();
62         } catch (SystemException e) { /* Ignore Exception! */
63         }
64     }
65
66     /**
67      * @return Returns the var.
68      */

69     public String JavaDoc getVar() {
70         return var;
71     }
72
73     /**
74      * @param var
75      * The var to set.
76      */

77     public void setVar(String JavaDoc var) {
78         this.var = var;
79     }
80
81     /**
82      * @return Returns the contentType.
83      */

84     public String JavaDoc getContentType() {
85         return contentType;
86     }
87
88     /**
89      * @param contentType
90      * The contentType to set.
91      */

92     public void setContentType(String JavaDoc value) {
93         this.contentType = value;
94     }
95
96     private void eval() throws JspException JavaDoc {
97         contentType = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
98                 "contentType", contentType, String JavaDoc.class, this, pageContext);
99     }
100
101     /*
102      * (non-Javadoc)
103      *
104      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
105      */

106     public int doStartTag() throws JspException JavaDoc {
107         eval();
108         Boolean JavaDoc 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 JavaDoc isSupportedMIMEType(String JavaDoc mime) {
118         return new Boolean JavaDoc(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