KickJava   Java API By Example, From Geeks To Geeks.

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


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
37 public class JstlCoreCatch extends JstlNode {
38   private static final QName VAR = new QName("var");
39   
40   private String JavaDoc _var;
41   
42   /**
43    * Adds an attribute.
44    */

45   public void addAttribute(QName name, String JavaDoc value)
46     throws JspParseException
47   {
48     if (VAR.equals(name))
49       _var = value;
50     else
51       throw error(L.l("`{0}' is an unknown attribute for <{1}>.",
52                       name, getTagName()));
53   }
54
55   /**
56    * Generates the XML text representation for the tag validation.
57    *
58    * @param os write stream to the generated XML.
59    */

60   public void printXml(WriteStream os)
61     throws IOException JavaDoc
62   {
63     os.print("<c:catch");
64
65     if (_var != null)
66       os.print(" var=\"" + xmlText(_var) + "\"");
67
68     os.print(">");
69
70     printXmlChildren(os);
71
72     os.print("</c:catch>");
73   }
74   
75   /**
76    * Generates the code for the c:catch tag.
77    */

78   public void generate(JspJavaWriter out)
79     throws Exception JavaDoc
80   {
81     String JavaDoc temp = "_jsp_out" + _gen.uniqueId();
82
83     out.println("javax.servlet.jsp.JspWriter " + temp + " = out;");
84     out.println("try {");
85     out.pushDepth();
86
87     generateChildren(out);
88
89     if (_var != null)
90       out.println("pageContext.removeAttribute(\"" + _var + "\");");
91       
92     out.popDepth();
93     out.println("} catch (Throwable _jsp_exn) {");
94     
95     out.println(" out = pageContext.setWriter(" + temp + ");");
96     
97     if (_var != null)
98       out.println(" pageContext.setAttribute(\"" + _var + "\", _jsp_exn);");
99
100     out.println("}");
101   }
102 }
103
Popular Tags