KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002-2004 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.radeox.util.i18n.ResourceManager;
30 import org.radeox.util.Encoder;
31
32 import javax.servlet.jsp.JspException JavaDoc;
33 import javax.servlet.jsp.JspWriter JavaDoc;
34 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
35 import java.io.IOException JavaDoc;
36
37
38 /*
39  * Tag creates .
40  *
41  * @author Stephan J. Schmidt
42  * @version $Id: PathSelectorTag.java 1839 2005-11-09 18:35:41Z leo $
43  */

44
45 public class PathSelectorTag extends TagSupport JavaDoc {
46   String JavaDoc parent = null;
47   String JavaDoc selected = null;
48
49   public int doStartTag() throws JspException JavaDoc {
50     if (null != parent ) {
51       try {
52         JspWriter JavaDoc out = pageContext.getOut();
53         String JavaDoc[] elements = parent.split("/");
54         out.write("<select name=\"parent\" size=\"1\"");
55         if ("".equals(parent)) {
56           out.write(" disabled=\"disabled\"");
57         }
58         out.write(">");
59         out.write("<option value=\"\">");
60         out.write(ResourceManager.getString("i18n.messages", "snip.path.noparent"));
61         out.write("</option>");
62         String JavaDoc path = "";
63         String JavaDoc value = "";
64         for (int i = 0; i < elements.length; i++) {
65           String JavaDoc element = Encoder.escape(elements[i]);
66           if (i !=0 ) {
67             path = path + " > ";
68             value = value + "/";
69           }
70           path = path + element;
71           value = value + element;
72           out.write("<option value=\""+value+"\"");
73           if(value.equals(selected)) {
74             out.write(" selected=\"selected\"");
75           }
76           out.write(">");
77           out.write(path);
78           out.write("</option>");
79         }
80         out.write("</select>");
81       } catch (IOException JavaDoc e) {
82         Logger.warn("doStartTag in PathTag", e);
83       }
84     }
85     return super.doStartTag();
86   }
87
88   public void setParentName(String JavaDoc parent) {
89     try {
90       this.parent = (String JavaDoc) ExpressionEvaluatorManager.evaluate("parent", parent, String JavaDoc.class, this, pageContext);
91     } catch (JspException JavaDoc e) {
92       Logger.warn("unable to evaluate expression", e);
93     }
94   }
95
96   public void setSelected(String JavaDoc selected) {
97     try {
98       this.selected = (String JavaDoc) ExpressionEvaluatorManager.evaluate("selected", selected, String JavaDoc.class, this, pageContext);
99     } catch (JspException JavaDoc e) {
100       Logger.warn("unable to evaluate expression", e);
101     }
102   }
103 }
104
Popular Tags