KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jstl > el > XmlParamTag


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.el;
30
31 import com.caucho.el.Expr;
32 import com.caucho.jsp.PageContextImpl;
33 import com.caucho.jstl.NameValueTag;
34 import com.caucho.util.L10N;
35
36 import javax.el.ELContext;
37 import javax.el.ELException;
38 import javax.servlet.jsp.JspException JavaDoc;
39 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
40
41 /**
42  * Looks up an i18n message from a bundle and prints it.
43  */

44 public class XmlParamTag extends BodyTagSupport JavaDoc {
45   private static L10N L = new L10N(XmlParamTag.class);
46   
47   private Expr _nameExpr;
48   private Expr _valueExpr;
49
50   /**
51    * Sets the name
52    *
53    * @param name the JSP-EL expression for the name.
54    */

55   public void setName(Expr name)
56   {
57     _nameExpr = name;
58   }
59
60   /**
61    * Sets the value
62    *
63    * @param value the JSP-EL expression for the value.
64    */

65   public void setValue(Expr value)
66   {
67     _valueExpr = value;
68   }
69
70   /**
71    * Process the tag.
72    */

73   public int doStartTag()
74     throws JspException JavaDoc
75   {
76     try {
77       if (_valueExpr == null)
78     return EVAL_BODY_BUFFERED;
79
80       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
81       ELContext env = pageContext.getELContext();
82     
83       String JavaDoc name = _nameExpr.evalString(env);
84       String JavaDoc value = _valueExpr.evalString(env);
85
86       Object JavaDoc parent = getParent();
87       if (! (parent instanceof NameValueTag))
88     throw new JspException JavaDoc(L.l("x:param requires x:transform."));
89
90       NameValueTag tag = (NameValueTag) parent;
91
92       tag.addParam(name, value);
93     
94       return SKIP_BODY;
95     } catch (ELException e) {
96       throw new JspException JavaDoc(e);
97     }
98   }
99
100   /**
101    * Process the tag.
102    */

103   public int doEndTag()
104     throws JspException JavaDoc
105   {
106     try {
107       if (_valueExpr != null)
108     return EVAL_PAGE;
109       
110       String JavaDoc value;
111
112       if (this.bodyContent != null)
113     value = this.bodyContent.getString().trim();
114       else
115     value = "";
116     
117       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
118     
119       String JavaDoc name = _nameExpr.evalString(pageContext.getELContext());
120
121       Object JavaDoc parent = getParent();
122       if (! (parent instanceof NameValueTag))
123     throw new JspException JavaDoc(L.l("c:param requires c:url or c:import parent."));
124
125       NameValueTag tag = (NameValueTag) parent;
126
127       tag.addParam(name, value);
128     
129       return EVAL_PAGE;
130     } catch (ELException e) {
131       throw new JspException JavaDoc(e);
132     }
133   }
134 }
135
Popular Tags