KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > java > JspParam


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.jsp.java;
30
31 import com.caucho.jsp.JspParseException;
32 import com.caucho.vfs.WriteStream;
33 import com.caucho.xml.QName;
34
35 import java.io.IOException JavaDoc;
36 import java.util.logging.Level JavaDoc;
37
38 /**
39  * Represents a Java scriptlet.
40  */

41 public class JspParam extends JspNode {
42   private static final QName NAME = new QName("name");
43   private static final QName VALUE = new QName("value");
44   
45   private String JavaDoc _name;
46   private String JavaDoc _value;
47
48   /**
49    * Adds an attribute.
50    */

51   public void addAttribute(QName name, String JavaDoc value)
52     throws JspParseException
53   {
54     if (NAME.equals(name)) {
55       _name = value;
56
57       if (hasRuntimeAttribute(value) || hasELAttribute(value))
58     throw error(L.l("'name' attribute may not have a runtime value at {0}",
59             value));
60     }
61     else if (VALUE.equals(name))
62       _value = value;
63     else
64       throw error(L.l("`{0}' is an invalid attribute in <jsp:param>",
65                       name.getName()));
66   }
67
68   /**
69    * Returns the param name.
70    */

71   public String JavaDoc getName()
72   {
73     return _name;
74   }
75
76   /**
77    * Returns the param value.
78    */

79   public String JavaDoc getValue()
80   {
81     return _value;
82   }
83   
84   /**
85    * Called when the tag closes.
86    */

87   public void endElement()
88     throws Exception JavaDoc
89   {
90     if (_name == null)
91       throw error(L.l("jsp:param requires a 'name' attribute"));
92     
93     if (_value == null)
94       throw error(L.l("jsp:param requires a 'value' attribute"));
95   }
96
97   /**
98    * Returns true if the param has scripting elements.
99    */

100   public boolean hasScripting()
101   {
102     try {
103       return hasRuntimeAttribute(getName()) || hasRuntimeAttribute(getValue());
104     } catch (Exception JavaDoc e) {
105       log.log(Level.WARNING, e.toString(), e);
106       return true;
107     }
108   }
109
110   /**
111    * Generates the XML text representation for the tag validation.
112    *
113    * @param os write stream to the generated XML.
114    */

115   public void printXml(WriteStream os)
116     throws IOException JavaDoc
117   {
118     throw new IOException JavaDoc(L.l("<jsp:param> does not have a direct xml."));
119   }
120
121   /**
122    * Generates the code for the scriptlet
123    *
124    * @param out the output writer for the generated java.
125    */

126   public void generate(JspJavaWriter out)
127     throws Exception JavaDoc
128   {
129     throw error(L.l("<jsp:param> does not generate code directly."));
130   }
131
132   /**
133    * Generates the code for the scriptlet
134    *
135    * @param out the output writer for the generated java.
136    */

137   public void generateEmpty()
138     throws Exception JavaDoc
139   {
140     throw error(L.l("<jsp:param> does not generate code directly."));
141   }
142 }
143
Popular Tags