KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > rt > CoreParamTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jstl.rt;
30
31 import com.caucho.jstl.NameValueTag;
32 import com.caucho.util.L10N;
33
34 import javax.servlet.jsp.JspException JavaDoc;
35 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
36 import javax.servlet.jsp.tagext.Tag JavaDoc;
37
38 /**
39  * Looks up an i18n message from a bundle and prints it.
40  */

41 public class CoreParamTag extends BodyTagSupport JavaDoc {
42   private static L10N L = new L10N(CoreParamTag.class);
43   
44   private String JavaDoc _name;
45   private String JavaDoc _value;
46
47   /**
48    * Sets the name
49    *
50    * @param name the JSP-EL expression for the name.
51    */

52   public void setName(String JavaDoc name)
53   {
54     _name = name;
55   }
56
57   /**
58    * Sets the value
59    *
60    * @param value the JSP-EL expression for the value.
61    */

62   public void setValue(String JavaDoc value)
63   {
64     _value = value;
65   }
66
67   /**
68    * Process the tag.
69    */

70   public int doStartTag()
71     throws JspException JavaDoc
72   {
73     if (_name == null)
74       return SKIP_BODY;
75     
76     if (_value == null)
77       return EVAL_BODY_BUFFERED;
78     
79     Tag parent = getParent();
80     for (; parent != null; parent = parent.getParent()) {
81       if (parent instanceof NameValueTag) {
82     NameValueTag tag = (NameValueTag) parent;
83
84     if (_value == null)
85       tag.addParam(_name, "");
86     else
87       tag.addParam(_name, _value);
88     
89     return SKIP_BODY;
90       }
91     }
92       
93     throw new JspException JavaDoc(L.l("c:param requires c:url or c:import parent."));
94   }
95
96   /**
97    * Process the tag.
98    */

99   public int doEndTag()
100     throws JspException JavaDoc
101   {
102     if (_value != null)
103       return EVAL_PAGE;
104       
105     String JavaDoc value;
106
107     if (bodyContent != null)
108       value = bodyContent.getString().trim();
109     else
110       value = "";
111     
112     Object JavaDoc parent = getParent();
113     if (! (parent instanceof NameValueTag))
114       throw new JspException JavaDoc(L.l("c:param requires c:url or c:import parent."));
115
116     NameValueTag tag = (NameValueTag) parent;
117
118     tag.addParam(_name, value);
119     
120     return EVAL_PAGE;
121   }
122 }
123
Popular Tags