KickJava   Java API By Example, From Geeks To Geeks.

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


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 declaration.
39  */

40 public class JspDeclaration extends JspNode {
41   private String JavaDoc _text;
42   
43   /**
44    * Adds text to the directive.
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("Script declarations 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     _gen.addDeclaration(this);
66   }
67
68   /**
69    * Returns true for a scripting element.
70    */

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

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

97   public void generateDeclaration(JspJavaWriter out)
98     throws IOException JavaDoc
99   {
100     int length = _text.length();
101
102     out.setLocation(getFilename(), getStartLine());
103
104     for (int i = 0; i < length; i++) {
105       char ch = _text.charAt(i);
106
107       if (ch == '\r' && i + 1 < length && _text.charAt(i + 1) != '\n')
108         ch = '\n';
109       
110       if (ch == '\n')
111     out.println();
112       else
113         out.print(ch);
114     }
115
116     out.setLocation(_filename, _endLine);
117     
118     out.println();
119   }
120
121   /**
122    * No general code.
123    *
124    * @param out the output writer for the generated java.
125    */

126   public void generate(JspJavaWriter out)
127     throws Exception JavaDoc
128   {
129   }
130 }
131
Popular Tags