KickJava   Java API By Example, From Geeks To Geeks.

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


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
35 import java.io.IOException JavaDoc;
36
37 /**
38  * Represents a Java scriptlet.
39  */

40 public class JspScriptlet extends JspNode {
41   private String JavaDoc _text;
42   
43   /**
44    * Adds text to the scriptlet.
45    */

46   public JspNode addText(String JavaDoc text)
47   {
48     if (_text == null)
49       _text = text;
50     else
51       _text += text;
52
53     return null;
54   }
55
56   /**
57    * Completes the scriptlet.
58    */

59   public void endElement()
60     throws JspParseException
61   {
62     if (_parseState.isScriptingInvalid())
63       throw error(L.l("Scriptlets are forbidden here. Scripting has been disabled either:\n1) disabled by the web.xml scripting-invalid\n2) disabled in a tag's descriptor\n3) forbidden in <jsp:attribute> or <jsp:body> tags."));
64   }
65   
66   /**
67    * True if the node has scripting
68    */

69   public boolean hasScripting()
70   {
71     return true;
72   }
73
74   /**
75    * Generates the XML text representation for the tag validation.
76    *
77    * @param os write stream to the generated XML.
78    */

79   public void printXml(WriteStream os)
80     throws IOException JavaDoc
81   {
82     os.print("<jsp:scriptlet");
83     printJspId(os);
84     os.print(">");
85     
86     printXmlText(os, _text);
87     os.print("</jsp:scriptlet>");
88   }
89
90   /**
91    * Generates the code for the scriptlet
92    *
93    * @param out the output writer for the generated java.
94    */

95   public void generate(JspJavaWriter out)
96     throws Exception JavaDoc
97   {
98     int length = _text.length();
99
100     for (int i = 0; i < length; i++) {
101       char ch = _text.charAt(i);
102
103       if (ch == '\r' && i + 1 < length && _text.charAt(i + 1) != '\n')
104         ch = '\n';
105       
106       out.print(ch);
107     }
108
109     // jsp/150l
110
out.setLocation(_filename, _endLine);
111     // _endLine = -1;
112

113     out.println();
114   }
115 }
116
Popular Tags