001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.apache.jasper.compiler;
043:
044: import org.apache.jasper.JasperException;
045:
046: import org.xml.sax.Attributes;
047: import java.util.*;
048:
049: // Note: this needs to live in the org.apache.jasper.compiler package.
050: class NodeConverterVisitor extends Node.Visitor {
051: // walk the nodes, convert them, then new Nodes(List).
052: // (tomorrow)
053: org.netbeans.modules.web.jsps.parserapi.Node parentNode;
054: List convertedNodeList = null;
055:
056: public NodeConverterVisitor(
057: org.netbeans.modules.web.jsps.parserapi.Node parentNode) {
058: this .parentNode = parentNode;
059: }
060:
061: public static org.netbeans.modules.web.jsps.parserapi.Node.Nodes convertNodes(
062: Node.Nodes jasperNodes) throws JasperException {
063: return convertNodes(jasperNodes, null);
064: }
065:
066: public static org.netbeans.modules.web.jsps.parserapi.Node.Nodes convertNodes(
067: Node.Nodes jasperNodes,
068: org.netbeans.modules.web.jsps.parserapi.Node parentNode)
069: throws JasperException {
070: NodeConverterVisitor serra = new NodeConverterVisitor(
071: parentNode);
072: return serra.convertNodesList(jasperNodes);
073: }
074:
075: protected org.netbeans.modules.web.jsps.parserapi.Node.Nodes convertNodesList(
076: Node.Nodes jasperNodes) throws JasperException {
077: convertedNodeList = new Vector();
078: int numChildNodes = jasperNodes.size();
079: jasperNodes.visit(this );
080: org.netbeans.modules.web.jsps.parserapi.Node.Nodes nbNodes = new org.netbeans.modules.web.jsps.parserapi.Node.Nodes(
081: convertedNodeList);
082: return nbNodes;
083: }
084:
085: public void convertBody(Node jn,
086: org.netbeans.modules.web.jsps.parserapi.Node parentNode)
087: throws JasperException {
088: Node.Nodes jnodes = jn.getBody();
089: if (jnodes == null)
090: return;
091:
092: org.netbeans.modules.web.jsps.parserapi.Node.Nodes cnodes = NodeConverterVisitor
093: .convertNodes(jnodes, parentNode);
094:
095: parentNode.setBody(cnodes);
096: }
097:
098: public org.netbeans.modules.web.jsps.parserapi.Mark convertMark(
099: Mark m) {
100: if (m == null) {
101: return null;
102: } else {
103: return new org.netbeans.modules.web.jsps.parserapi.Mark(m
104: .getFile(), m.getLineNumber(), m.getColumnNumber());
105: }
106: }
107:
108: public void visit(Node.PageDirective n) {
109: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.PageDirective(
110: n.getAttributes(), convertMark(n.getStart()),
111: parentNode);
112: convertedNodeList.add(cn);
113: }
114:
115: public void visit(Node.TaglibDirective n) {
116: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.TaglibDirective(
117: n.getAttributes(), convertMark(n.getStart()),
118: parentNode);
119: convertedNodeList.add(cn);
120: }
121:
122: public void visit(Node.AttributeDirective n) throws JasperException {
123: org.netbeans.modules.web.jsps.parserapi.Node.AttributeDirective cn = new org.netbeans.modules.web.jsps.parserapi.Node.AttributeDirective(
124: n.getAttributes(), convertMark(n.getStart()),
125: parentNode);
126: convertBody(n, cn);
127: convertedNodeList.add(cn);
128: }
129:
130: public void visit(Node.VariableDirective n) throws JasperException {
131: org.netbeans.modules.web.jsps.parserapi.Node.VariableDirective cn = new org.netbeans.modules.web.jsps.parserapi.Node.VariableDirective(
132: n.getAttributes(), convertMark(n.getStart()),
133: parentNode);
134: convertBody(n, cn);
135: convertedNodeList.add(cn);
136: }
137:
138: public void visit(Node.IncludeDirective n) throws JasperException {
139: org.netbeans.modules.web.jsps.parserapi.Node.IncludeDirective cn = new org.netbeans.modules.web.jsps.parserapi.Node.IncludeDirective(
140: n.getAttributes(), convertMark(n.getStart()),
141: parentNode);
142: convertBody(n, cn);
143: convertedNodeList.add(cn);
144: }
145:
146: public void visit(Node.Comment n) {
147: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.Comment(
148: n.getText(), convertMark(n.getStart()), parentNode);
149: convertedNodeList.add(cn);
150: }
151:
152: public void visit(Node.Declaration n) {
153: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.Declaration(
154: n.getText(), convertMark(n.getStart()), parentNode);
155: convertedNodeList.add(cn);
156: }
157:
158: public void visit(Node.Expression n) {
159: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.Expression(
160: n.getText(), convertMark(n.getStart()), parentNode);
161: convertedNodeList.add(cn);
162: }
163:
164: public void visit(Node.Scriptlet n) {
165: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.Scriptlet(
166: n.getText(), convertMark(n.getStart()), parentNode);
167: convertedNodeList.add(cn);
168: }
169:
170: public void visit(Node.IncludeAction n) throws JasperException {
171: org.netbeans.modules.web.jsps.parserapi.Node.IncludeAction cn = new org.netbeans.modules.web.jsps.parserapi.Node.IncludeAction(
172: n.getAttributes(), convertMark(n.getStart()),
173: parentNode);
174: convertBody(n, cn);
175: convertedNodeList.add(cn);
176: }
177:
178: public void visit(Node.DoBodyAction n) throws JasperException {
179: org.netbeans.modules.web.jsps.parserapi.Node.DoBodyAction cn = new org.netbeans.modules.web.jsps.parserapi.Node.DoBodyAction(
180: n.getAttributes(), convertMark(n.getStart()),
181: parentNode);
182: convertBody(n, cn);
183: convertedNodeList.add(cn);
184: }
185:
186: public void visit(Node.ForwardAction n) throws JasperException {
187: org.netbeans.modules.web.jsps.parserapi.Node.ForwardAction cn = new org.netbeans.modules.web.jsps.parserapi.Node.ForwardAction(
188: n.getAttributes(), convertMark(n.getStart()),
189: parentNode);
190: convertBody(n, cn);
191: convertedNodeList.add(cn);
192: }
193:
194: public void visit(Node.GetProperty n) {
195: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.GetProperty(
196: n.getAttributes(), convertMark(n.getStart()),
197: parentNode);
198: convertedNodeList.add(cn);
199: }
200:
201: public void visit(Node.SetProperty n) throws JasperException {
202: org.netbeans.modules.web.jsps.parserapi.Node.SetProperty cn = new org.netbeans.modules.web.jsps.parserapi.Node.SetProperty(
203: n.getAttributes(), convertMark(n.getStart()),
204: parentNode);
205: convertBody(n, cn);
206: convertedNodeList.add(cn);
207: }
208:
209: public void visit(Node.UseBean n) throws JasperException {
210: org.netbeans.modules.web.jsps.parserapi.Node.UseBean cn = new org.netbeans.modules.web.jsps.parserapi.Node.UseBean(
211: n.getAttributes(), convertMark(n.getStart()),
212: parentNode);
213: convertBody(n, cn);
214: convertedNodeList.add(cn);
215: }
216:
217: public void visit(Node.PlugIn n) throws JasperException {
218: org.netbeans.modules.web.jsps.parserapi.Node.PlugIn cn = new org.netbeans.modules.web.jsps.parserapi.Node.PlugIn(
219: n.getAttributes(), convertMark(n.getStart()),
220: parentNode);
221: convertBody(n, cn);
222: convertedNodeList.add(cn);
223: }
224:
225: public void visit(Node.ParamsAction n) throws JasperException {
226: org.netbeans.modules.web.jsps.parserapi.Node.ParamsAction cn = new org.netbeans.modules.web.jsps.parserapi.Node.ParamsAction(
227: convertMark(n.getStart()), parentNode);
228: convertBody(n, cn);
229: convertedNodeList.add(cn);
230: }
231:
232: public void visit(Node.ParamAction n) throws JasperException {
233: org.netbeans.modules.web.jsps.parserapi.Node.ParamAction cn = new org.netbeans.modules.web.jsps.parserapi.Node.ParamAction(
234: n.getAttributes(), convertMark(n.getStart()),
235: parentNode);
236: convertBody(n, cn);
237: convertedNodeList.add(cn);
238: }
239:
240: public void visit(Node.InvokeAction n) {
241: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.InvokeAction(
242: n.getAttributes(), convertMark(n.getStart()),
243: parentNode);
244: convertedNodeList.add(cn);
245: }
246:
247: public void visit(Node.NamedAttribute n) throws JasperException {
248: org.netbeans.modules.web.jsps.parserapi.Node.NamedAttribute cn = new org.netbeans.modules.web.jsps.parserapi.Node.NamedAttribute(
249: n.getAttributes(), convertMark(n.getStart()),
250: parentNode);
251: convertBody(n, cn);
252: convertedNodeList.add(cn);
253: }
254:
255: public void visit(Node.JspBody n) throws JasperException {
256: org.netbeans.modules.web.jsps.parserapi.Node.JspBody cn = new org.netbeans.modules.web.jsps.parserapi.Node.JspBody(
257: convertMark(n.getStart()), parentNode);
258: convertBody(n, cn);
259: convertedNodeList.add(cn);
260: }
261:
262: public void visit(Node.ELExpression n) {
263: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.ELExpression(
264: n.getText(), convertMark(n.getStart()), parentNode);
265: convertedNodeList.add(cn);
266: }
267:
268: public void visit(Node.CustomTag n) throws JasperException {
269: org.netbeans.modules.web.jsps.parserapi.Node.CustomTag cn = null;
270: if (n.getTagFileInfo() == null) {
271: // no tag file
272: cn = new org.netbeans.modules.web.jsps.parserapi.Node.CustomTag(
273: n.getQName(), n.getPrefix(), n.getLocalName(), n
274: .getURI(), n.getAttributes(), convertMark(n
275: .getStart()), parentNode, n.getTagInfo(), n
276: .getTagHandlerClass());
277: } else {
278: // we do have a tag file
279: cn = new org.netbeans.modules.web.jsps.parserapi.Node.CustomTag(
280: n.getQName(), n.getPrefix(), n.getLocalName(), n
281: .getURI(), n.getAttributes(), convertMark(n
282: .getStart()), parentNode, n
283: .getTagFileInfo());
284: }
285: convertBody(n, cn);
286: convertedNodeList.add(cn);
287: }
288:
289: public void visit(Node.UninterpretedTag n) throws JasperException {
290: Attributes nonTaglibXmlnsAttrs = null; // ??
291: Attributes taglibAttrs = null; // ??
292: org.netbeans.modules.web.jsps.parserapi.Node.UninterpretedTag cn = new org.netbeans.modules.web.jsps.parserapi.Node.UninterpretedTag(
293: n.getQName(), n.getLocalName(), n.getAttributes(),
294: nonTaglibXmlnsAttrs, taglibAttrs, convertMark(n
295: .getStart()), parentNode);
296: convertBody(n, cn);
297: convertedNodeList.add(cn);
298: }
299:
300: public void visit(Node.TemplateText n) {
301: org.netbeans.modules.web.jsps.parserapi.Node cn = new org.netbeans.modules.web.jsps.parserapi.Node.TemplateText(
302: n.getText(), convertMark(n.getStart()), parentNode);
303: convertedNodeList.add(cn);
304: }
305:
306: }
|