001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jsp.java;
031:
032: import com.caucho.jsp.JspParseException;
033: import com.caucho.util.CharBuffer;
034: import com.caucho.vfs.WriteStream;
035:
036: import java.io.IOException;
037: import java.util.ArrayList;
038:
039: /**
040: * Represents static text.
041: */
042: public class JspText extends JspNode {
043: private ArrayList<JspNode> _children = new ArrayList<JspNode>();
044:
045: public JspText() {
046: }
047:
048: /**
049: * Adds text to the scriptlet.
050: */
051: public JspNode addText(String text) {
052: JspNode node = new StaticText(_gen, text, this );
053:
054: _children.add(node);
055:
056: return node;
057: }
058:
059: /**
060: * Adds a child node.
061: */
062: public void addChild(JspNode node) throws JspParseException {
063: if (node.getTagName().equals("resin-c:out"))
064: _children.add(node);
065: else
066: super .addChild(node);
067: }
068:
069: /**
070: * Gets the text.
071: */
072: /*
073: public String getText()
074: {
075: throw newreturn (String) _children.get(0);
076: }
077: */
078:
079: /**
080: * sets the text.
081: */
082: /*
083: public void setText(String text)
084: {
085: addText(text);
086: }
087: */
088:
089: /**
090: * Return true if the node only has static text.
091: */
092: public boolean isStatic() {
093: for (int i = 0; i < _children.size(); i++)
094: if (!_children.get(i).isStatic())
095: return false;
096:
097: return true;
098: }
099:
100: /**
101: * Returns the static text.
102: */
103: public void getStaticText(CharBuffer cb) {
104: for (int i = 0; i < _children.size(); i++)
105: _children.get(i).getStaticText(cb);
106: }
107:
108: /**
109: * Returns true if whitespace.
110: */
111: public boolean isWhitespace() {
112: for (int i = 0; i < _children.size(); i++) {
113: JspNode child = _children.get(i);
114:
115: if (!(child instanceof StaticText))
116: return false;
117:
118: if (!((StaticText) child).isWhitespace())
119: return false;
120: }
121:
122: return true;
123: }
124:
125: /**
126: * Generates the XML text representation for the tag validation.
127: *
128: * @param os write stream to the generated XML.
129: */
130: public void printXml(WriteStream os) throws IOException {
131: os.print("<jsp:text");
132: printJspId(os);
133: os.print(">");
134:
135: for (int i = 0; i < _children.size(); i++)
136: _children.get(i).printXml(os);
137:
138: os.print("</jsp:text>");
139: }
140:
141: /**
142: * Generates the start location.
143: */
144: public void generateStartLocation(JspJavaWriter out)
145: throws IOException {
146: }
147:
148: /**
149: * Generates the code for the static text
150: *
151: * @param out the output writer for the generated java.
152: */
153: public void generate(JspJavaWriter out) throws Exception {
154: for (int i = 0; i < _children.size(); i++)
155: _children.get(i).generate(out);
156: }
157:
158: /**
159: * Generates the code for the static text
160: *
161: * @param out the output writer for the generated java.
162: */
163: public void generateStatic(JspJavaWriter out) throws Exception {
164: for (int i = 0; i < _children.size(); i++)
165: _children.get(i).generateStatic(out);
166: }
167: }
|