KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.CharBuffer;
34 import com.caucho.vfs.WriteStream;
35
36 import java.io.IOException JavaDoc;
37 import java.util.ArrayList JavaDoc;
38
39 /**
40  * Represents static text.
41  */

42 public class JspText extends JspNode {
43   private ArrayList JavaDoc<JspNode> _children = new ArrayList JavaDoc<JspNode>();
44   
45   public JspText()
46   {
47   }
48
49   /**
50    * Adds text to the scriptlet.
51    */

52   public JspNode addText(String JavaDoc text)
53   {
54     JspNode node = new StaticText(_gen, text, this);
55     
56     _children.add(node);
57
58     return node;
59   }
60
61   /**
62    * Adds a child node.
63    */

64   public void addChild(JspNode node)
65     throws JspParseException
66   {
67     if (node.getTagName().equals("resin-c:out"))
68       _children.add(node);
69     else
70       super.addChild(node);
71   }
72
73   /**
74    * Gets the text.
75    */

76   /*
77   public String getText()
78   {
79     throw newreturn (String) _children.get(0);
80   }
81   */

82
83   /**
84    * sets the text.
85    */

86   /*
87   public void setText(String text)
88   {
89     addText(text);
90   }
91   */

92   
93   /**
94    * Return true if the node only has static text.
95    */

96   public boolean isStatic()
97   {
98     for (int i = 0; i < _children.size(); i++)
99       if (! _children.get(i).isStatic())
100     return false;
101
102     
103     return true;
104   }
105
106   /**
107    * Returns the static text.
108    */

109   public void getStaticText(CharBuffer cb)
110   {
111     for (int i = 0; i < _children.size(); i++)
112       _children.get(i).getStaticText(cb);
113   }
114
115   /**
116    * Returns true if whitespace.
117    */

118   public boolean isWhitespace()
119   {
120     for (int i = 0; i < _children.size(); i++) {
121       JspNode child = _children.get(i);
122       
123       if (! (child instanceof StaticText))
124     return false;
125
126       if (! ((StaticText) child).isWhitespace())
127     return false;
128     }
129
130     return true;
131   }
132
133   /**
134    * Generates the XML text representation for the tag validation.
135    *
136    * @param os write stream to the generated XML.
137    */

138   public void printXml(WriteStream os)
139     throws IOException JavaDoc
140   {
141     os.print("<jsp:text");
142     printJspId(os);
143     os.print(">");
144
145     for (int i = 0; i < _children.size(); i++)
146       _children.get(i).printXml(os);
147
148     os.print("</jsp:text>");
149   }
150
151   /**
152    * Generates the start location.
153    */

154   public void generateStartLocation(JspJavaWriter out)
155     throws IOException JavaDoc
156   {
157   }
158
159   /**
160    * Generates the code for the static text
161    *
162    * @param out the output writer for the generated java.
163    */

164   public void generate(JspJavaWriter out)
165     throws Exception JavaDoc
166   {
167     for (int i = 0; i < _children.size(); i++)
168       _children.get(i).generate(out);
169   }
170
171   /**
172    * Generates the code for the static text
173    *
174    * @param out the output writer for the generated java.
175    */

176   public void generateStatic(JspJavaWriter out)
177     throws Exception JavaDoc
178   {
179     for (int i = 0; i < _children.size(); i++)
180       _children.get(i).generateStatic(out);
181   }
182 }
183
Popular Tags