KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jsp.java;
31
32 import com.caucho.jsp.JspParseException;
33 import com.caucho.vfs.WriteStream;
34 import com.caucho.xml.QName;
35
36 import java.io.IOException JavaDoc;
37
38 public class JstlFmtParam extends JstlNode {
39   private static final QName VALUE = new QName("value");
40   
41   private String JavaDoc _value;
42   private JspAttribute _valueAttr;
43   /**
44    * Adds an attribute.
45    */

46   public void addAttribute(QName name, String JavaDoc value)
47     throws JspParseException
48   {
49     if (VALUE.equals(name))
50       _value = value;
51     else
52       throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
53                       name.getName(), getTagName()));
54   }
55
56   /**
57    * Returns true if the tag has scripting values.
58    */

59   public boolean hasScripting()
60   {
61     return (super.hasScripting() ||
62         hasScripting(_value) || hasScripting(_valueAttr));
63   }
64
65   /**
66    * Generates the XML text representation for the tag validation.
67    *
68    * @param os write stream to the generated XML.
69    */

70   public void printXml(WriteStream os)
71     throws IOException JavaDoc
72   {
73     os.print("<fmt:param>");
74
75     printXmlText(os, _value);
76     
77     printXmlChildren(os);
78
79     os.print("</fmt:param>");
80   }
81   
82   /**
83    * Generates the code for the fmt:param tag.
84    */

85   public void generate(JspJavaWriter out)
86     throws Exception JavaDoc
87   {
88     throw error(L.l("fmt:param can't be called directly."));
89   }
90   
91   /**
92    * Generates the code to set the fmt:param tag.
93    */

94   public void generateSet(JspJavaWriter out, String JavaDoc lhs)
95     throws Exception JavaDoc
96   {
97     if (_value != null) {
98       if (! getRuntimeAttribute(_value).equals(_value)) {
99     // jsp/1c3s
100

101     out.println(lhs + " = String.valueOf(" + getRuntimeAttribute(_value) + ");");
102       }
103       else {
104     int paramIndex = _gen.addExpr(_value);
105
106     out.println(lhs + " = _caucho_expr_" + paramIndex + ".evalObject(_jsp_env);");
107       }
108     }
109     else {
110       out.println("out = pageContext.pushBody();");
111
112       generateChildren(out);
113
114       out.println(lhs + " = ((com.caucho.jsp.BodyContentImpl) out).getTrimString();");
115
116       out.println("out = pageContext.popBody();");
117     }
118   }
119 }
120
Popular Tags