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;
031:
032: import com.caucho.jsp.cfg.JspPropertyGroup;
033: import com.caucho.jsp.java.JspNode;
034: import com.caucho.vfs.Path;
035: import com.caucho.xml.QName;
036:
037: /**
038: * Generates the nodes for JSP code.
039: */
040: abstract public class JspBuilder {
041: // The current source
042: protected Path _sourcePath;
043:
044: // The current filename
045: protected String _filename;
046:
047: // The current line
048: protected int _line;
049:
050: // The parse state
051: protected ParseState _parseState;
052:
053: // The parser
054: protected JspParser _jspParser;
055:
056: // The compiler configuration
057: protected JspCompiler _jspCompiler;
058:
059: // The jsp property
060: private JspPropertyGroup _jspPropertyGroup;
061:
062: // The tag manager
063: protected ParseTagManager _tagManager;
064:
065: /**
066: * Returns the generator.
067: */
068: abstract public JspGenerator getGenerator();
069:
070: /**
071: * Returns the top node.
072: */
073: abstract public JspNode getRootNode();
074:
075: /**
076: * Sets the parse state.
077: */
078: public void setParseState(ParseState parseState) {
079: _parseState = parseState;
080: }
081:
082: /**
083: * Returns the parse state.
084: */
085: public ParseState getParseState() {
086: return _parseState;
087: }
088:
089: /**
090: * Sets the page config?
091: */
092: public void setPageConfig(JspPageConfig pageConfig) {
093: }
094:
095: /**
096: * Sets the compiler
097: */
098: public void setJspCompiler(JspCompiler compiler) {
099: _jspCompiler = compiler;
100: }
101:
102: /**
103: * Returns the parse state.
104: */
105: public JspCompiler getJspCompiler() {
106: return _jspCompiler;
107: }
108:
109: /**
110: * Sets the parser
111: */
112: public void setJspParser(JspParser parser) {
113: _jspParser = parser;
114: }
115:
116: /**
117: * Returns the parse state.
118: */
119: public JspParser getJspParser() {
120: return _jspParser;
121: }
122:
123: /**
124: * Sets the tag manager
125: */
126: public void setTagManager(ParseTagManager manager) {
127: _tagManager = manager;
128: }
129:
130: /**
131: * Returns the tag manager
132: */
133: public ParseTagManager getTagManager() {
134: return _tagManager;
135: }
136:
137: /**
138: * Sets the jsp-property-group
139: */
140: public void setJspPropertyGroup(JspPropertyGroup jsp) {
141: _jspPropertyGroup = jsp;
142: }
143:
144: /**
145: * Gets the jsp-property-group
146: */
147: public JspPropertyGroup getJspPropertyGroup() {
148: return _jspPropertyGroup;
149: }
150:
151: /**
152: * Returns true if fast-jstl is enabled.
153: */
154: public boolean isFastJstl() {
155: JspPropertyGroup jsp = getJspPropertyGroup();
156:
157: if (jsp == null)
158: return true;
159: else
160: return jsp.isFastJstl();
161: }
162:
163: /**
164: * Returns true if fast-jsf is enabled.
165: */
166: public boolean isFastJsf() {
167: JspPropertyGroup jsp = getJspPropertyGroup();
168:
169: if (jsp == null)
170: return true;
171: else
172: return jsp.isFastJsf();
173: }
174:
175: /**
176: * Returns true if require source is enabled.
177: */
178: public boolean getRequireSource() {
179: JspPropertyGroup jsp = getJspPropertyGroup();
180:
181: if (jsp == null)
182: return false;
183: else
184: return jsp.getRequireSource();
185: }
186:
187: /**
188: * Set for prototype builder.
189: */
190: public void setPrototype(boolean isPrototype) {
191: }
192:
193: /**
194: * Sets the source line number.
195: */
196: public void setLocation(Path sourcePath, String filename, int line) {
197: _sourcePath = sourcePath;
198: _filename = filename;
199: _line = line;
200: }
201:
202: /**
203: * Starts the document
204: */
205: abstract public void startDocument() throws JspParseException;
206:
207: /**
208: * Starts the document
209: */
210: abstract public void endDocument() throws JspParseException;
211:
212: /**
213: * Starts an element.
214: *
215: * @param qname the name of the element to start
216: */
217: abstract public void startElement(QName qname)
218: throws JspParseException;
219:
220: /**
221: * Starts a prefix mapping.
222: *
223: * @param prefix the xml prefix
224: * @param uri the namespace uri
225: */
226: abstract public void startPrefixMapping(String prefix, String uri)
227: throws JspParseException;
228:
229: /**
230: * Adds an attribute to the element.
231: *
232: * @param name the attribute name
233: * @param value the attribute value
234: */
235: abstract public void attribute(QName name, String value)
236: throws JspParseException;
237:
238: /**
239: * Called after the attributes end.
240: */
241: abstract public void endAttributes() throws JspParseException;
242:
243: /**
244: * Ends an element.
245: *
246: * @param name the name of the element to end
247: */
248: abstract public void endElement(String name)
249: throws JspParseException;
250:
251: /**
252: * Adds text.
253: *
254: * @param text the text to add
255: */
256: abstract public void text(String text) throws JspParseException;
257:
258: /**
259: * Adds text.
260: *
261: * @param text the text to add
262: */
263: public void text(String text, String filename, int startLine,
264: int endLine) throws JspParseException {
265: text(text);
266: }
267:
268: public void addNamespace(String prefix, String uri) {
269: // getParseState().pushNamespace(prefix, uri);
270: getCurrentNode().addNamespace(prefix, uri);
271: }
272:
273: /**
274: * Returns the current node.
275: */
276: abstract public JspNode getCurrentNode();
277: }
|