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.java.LineMap;
033: import com.caucho.log.Log;
034: import com.caucho.util.L10N;
035: import com.caucho.vfs.Path;
036: import com.caucho.vfs.PersistentDependency;
037:
038: import javax.servlet.jsp.tagext.TagInfo;
039: import javax.servlet.jsp.tagext.TagLibraryInfo;
040: import java.util.ArrayList;
041: import java.util.logging.Logger;
042:
043: /**
044: * Generates JSP code. JavaGenerator, JavaScriptGenerator, and
045: * StaticGenerator specialize the JspGenerator for language-specific
046: * requirements.
047: *
048: * <p>JspParser parses the JSP file into an XML-DOM tree. JspGenerator
049: * generates code from that tree.
050: */
051: abstract public class JspGenerator {
052: static final L10N L = new L10N(JspGenerator.class);
053: static final Logger log = Log.open(JspGenerator.class);
054:
055: protected JspParser _jspParser;
056: protected JspCompiler _jspCompiler;
057: protected JspCompilerInstance _jspCompilerInstance;
058:
059: // maps lines in the generated code back to lines in
060: // the JSP file.
061: protected LineMap _lineMap;
062:
063: public void setJspCompiler(JspCompiler compiler) {
064: _jspCompiler = compiler;
065: }
066:
067: public JspCompiler getJspCompiler() {
068: return _jspCompiler;
069: }
070:
071: public void setJspCompilerInstance(JspCompilerInstance compiler) {
072: _jspCompilerInstance = compiler;
073: }
074:
075: public JspCompilerInstance getJspCompilerInstance() {
076: return _jspCompilerInstance;
077: }
078:
079: abstract protected void setParseState(ParseState parseState);
080:
081: abstract protected ParseState getParseState();
082:
083: public void setJspParser(JspParser parser) {
084: _jspParser = parser;
085: }
086:
087: public JspParser getJspParser() {
088: return _jspParser;
089: }
090:
091: public LineMap getLineMap() {
092: return _lineMap;
093: }
094:
095: public boolean isELIgnore() {
096: return getParseState().isELIgnored();
097: }
098:
099: public void addDepend(PersistentDependency depend) {
100: }
101:
102: public ArrayList<PersistentDependency> getDependList() {
103: return null;
104: }
105:
106: /**
107: * Returns true if the JSP compilation has produced a static file.
108: */
109: public boolean isStatic() {
110: return false;
111: }
112:
113: /**
114: * Returns the tags taginfo.
115: */
116: public TagInfo generateTagInfo(String className, TagLibraryInfo tag) {
117: throw new IllegalStateException();
118: }
119:
120: /**
121: * Validates the page.
122: */
123: abstract public void validate() throws Exception;
124:
125: /**
126: * Generates the JSP page.
127: */
128: abstract protected void generate(Path path, String className)
129: throws Exception;
130:
131: public String getSourceLines(Path source, int errorLine) {
132: return "";
133: }
134: }
|