KickJava   Java API By Example, From Geeks To Geeks.

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


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.jsp.PageContextImpl;
32 import com.caucho.log.Log;
33 import com.caucho.xpath.Env;
34 import com.caucho.xpath.XPath;
35 import com.caucho.xpath.XPathException;
36
37 import org.w3c.dom.Node JavaDoc;
38
39 import javax.servlet.jsp.JspException JavaDoc;
40 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
41 import java.util.logging.Level JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43
44 public class XmlSetTag extends TagSupport JavaDoc {
45   private static final Logger JavaDoc log = Log.open(XmlSetTag.class);
46   private com.caucho.xpath.Expr _select;
47   
48   private String JavaDoc _var;
49   private String JavaDoc _scope;
50
51   /**
52    * Sets the JSP-EL expression value.
53    */

54   public void setSelect(com.caucho.xpath.Expr select)
55   {
56     _select = select;
57   }
58
59   /**
60    * Sets the variable to be saved.
61    */

62   public void setVar(String JavaDoc var)
63   {
64     _var = var;
65   }
66
67   /**
68    * Sets the scope of the variable to be saved.
69    */

70   public void setScope(String JavaDoc scope)
71   {
72     _scope = scope;
73   }
74
75   /**
76    * Process the tag.
77    */

78   public int doStartTag()
79     throws JspException JavaDoc
80   {
81     try {
82       PageContextImpl pageContext = (PageContextImpl) this.pageContext;
83       
84       Object JavaDoc value = evalObject(pageContext, _select);
85
86       CoreSetTag.setValue(pageContext, _var, _scope, value);
87     } catch (Exception JavaDoc e) {
88       log.log(Level.FINE, e.toString(), e);
89     }
90
91     return SKIP_BODY;
92   }
93
94   /**
95    * Returns the value as an object.
96    */

97   public static Object JavaDoc evalObject(PageContextImpl pageContext,
98                   com.caucho.xpath.Expr select)
99     throws XPathException
100   {
101     Env env = XPath.createEnv();
102     env.setVarEnv(pageContext.getVarEnv());
103       
104     Node JavaDoc node = pageContext.getNodeEnv();
105       
106     Object JavaDoc value = select.evalObject(node, env);
107
108     env.free();
109
110     return value;
111   }
112 }
113
Popular Tags