KickJava   Java API By Example, From Geeks To Geeks.

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


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.xml.QName;
33
34 abstract public class JstlNode extends JspContainerNode {
35   /**
36    * Adds an attribute.
37    */

38   public void addAttribute(QName name, String JavaDoc value)
39     throws JspParseException
40   {
41     throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
42                     name.getName(), getTagName()));
43   }
44   
45   /**
46    * Generates the code to set a non-null value.
47    *
48    * @param out the writer to the *.java file
49    * @param var the EL name
50    * @param scope the scope name
51    * @param value the value
52    */

53   protected void generateSetNotNull(JspJavaWriter out, String JavaDoc var,
54                                     String JavaDoc scope, String JavaDoc value)
55     throws Exception JavaDoc
56   {
57     if (var == null) {
58     }
59     else if (scope == null || scope.equals("page")) {
60       out.println("pageContext.setAttribute(\"" + var + "\", " + value + ");");
61     }
62     else if (scope.equals("request")) {
63       out.println("pageContext.getRequest().setAttribute(\"" + var + "\", " + value + ");");
64     }
65     else if (scope.equals("session")) {
66       out.println("pageContext.getSession().setAttribute(\"" + var + "\", " + value + ");");
67     }
68     else if (scope.equals("application")) {
69       out.println("pageContext.getServletContext().setAttribute(\"" + var + "\", " + value + ");");
70     }
71     else
72       throw error(L.l("invalid scope `{0}'", scope));
73   }
74
75   protected void generateSetOrRemove(JspJavaWriter out,
76                                      String JavaDoc var, String JavaDoc scope,
77                                      String JavaDoc value)
78     throws Exception JavaDoc
79   {
80     if (var == null) {
81     }
82     else if (scope == null) {
83       out.println("pageContext.defaultSetOrRemove(\"" + var + "\", " + value + ");");
84     }
85     else if (scope.equals("page")) {
86       out.println("pageContext.pageSetOrRemove(\"" + var + "\", " + value + ");");
87     }
88     else if (scope.equals("request")) {
89       out.println("pageContext.requestSetOrRemove(\"" + var + "\", " + value + ");");
90     }
91     else if (scope.equals("session")) {
92       out.println("pageContext.sessionSetOrRemove(\"" + var + "\", " + value + ");");
93     }
94     else if (scope.equals("application")) {
95       out.println("pageContext.applicationSetOrRemove(\"" + var + "\", " + value + ");");
96     }
97     else
98       throw error(L.l("invalid scope `{0}'", scope));
99   }
100 }
101
Popular Tags