KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > jsp > ImageTag


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

25 package org.snipsnap.jsp;
26
27 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
28 import org.radeox.util.logging.Logger;
29 import org.snipsnap.snip.SnipLink;
30
31 import javax.servlet.jsp.JspException JavaDoc;
32 import javax.servlet.jsp.JspWriter JavaDoc;
33 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 public class ImageTag extends TagSupport JavaDoc {
37   private String JavaDoc ext = null;
38   private String JavaDoc name = null;
39   private String JavaDoc alt = null;
40   private String JavaDoc root = null;
41
42   public int doStartTag() throws JspException JavaDoc {
43     try {
44       name = (String JavaDoc) ExpressionEvaluatorManager.evaluate("name", name, String JavaDoc.class, this, pageContext);
45       if (alt != null) {
46         alt = (String JavaDoc) ExpressionEvaluatorManager.evaluate("alt", alt, String JavaDoc.class, this, pageContext);
47       }
48       if (ext != null) {
49         ext = (String JavaDoc) ExpressionEvaluatorManager.evaluate("ext", ext, String JavaDoc.class, this, pageContext);
50       }
51     } catch (JspException JavaDoc e) {
52       Logger.warn("unable to evaluate expression", e);
53     }
54
55     JspWriter JavaDoc out = pageContext.getOut();
56     try {
57       if(null == root) {
58
59       SnipLink.appendImage(out, name, alt, ext);
60       } else {
61         SnipLink.appendImageWithRoot(out, SnipLink.getSpaceRoot()+"/" + root, name, alt, ext, null);
62       }
63     } catch (IOException JavaDoc e) {
64       Logger.warn("ImageTag: error writing image tag for " + name);
65     }
66     return SKIP_BODY;
67   }
68
69   public void setExt(String JavaDoc ext) {
70     this.ext = ext;
71   }
72
73   public void setName(String JavaDoc name) {
74     this.name = name;
75   }
76
77   public void setAlt(String JavaDoc alt) {
78     this.alt = alt;
79   }
80
81   public void setRoot(String JavaDoc root) {
82     this.root = root;
83   }
84 }
85
Popular Tags