KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > compiler > NodeConverterVisitor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.jasper.compiler;
21
22 import org.apache.jasper.JasperException;
23
24 import org.xml.sax.Attributes JavaDoc;
25 import java.util.*;
26
27
28 // Note: this needs to live in the org.apache.jasper.compiler package.
29
class NodeConverterVisitor extends Node.Visitor {
30         // walk the nodes, convert them, then new Nodes(List).
31
// (tomorrow)
32
org.netbeans.modules.web.jsps.parserapi.Node parentNode;
33     List convertedNodeList = null;
34     public NodeConverterVisitor(org.netbeans.modules.web.jsps.parserapi.Node parentNode) {
35     this.parentNode = parentNode;
36     }
37     public static org.netbeans.modules.web.jsps.parserapi.Node.Nodes
38     convertNodes(Node.Nodes jasperNodes) throws JasperException {
39     return convertNodes(jasperNodes, null);
40     }
41
42     public static org.netbeans.modules.web.jsps.parserapi.Node.Nodes
43               convertNodes(Node.Nodes jasperNodes,
44                    org.netbeans.modules.web.jsps.parserapi.Node parentNode) throws JasperException {
45     NodeConverterVisitor serra = new NodeConverterVisitor(parentNode);
46     return serra.convertNodesList(jasperNodes);
47     }
48     
49     protected org.netbeans.modules.web.jsps.parserapi.Node.Nodes
50            convertNodesList(Node.Nodes jasperNodes) throws JasperException {
51     convertedNodeList = new Vector();
52         int numChildNodes = jasperNodes.size();
53         jasperNodes.visit(this);
54         org.netbeans.modules.web.jsps.parserapi.Node.Nodes nbNodes =
55             new org.netbeans.modules.web.jsps.parserapi.Node.Nodes(convertedNodeList);
56          return nbNodes;
57     }
58     
59     public void convertBody(Node jn, org.netbeans.modules.web.jsps.parserapi.Node parentNode)
60     throws JasperException {
61     Node.Nodes jnodes = jn.getBody();
62     if (jnodes == null)
63         return;
64
65     org.netbeans.modules.web.jsps.parserapi.Node.Nodes cnodes =
66         NodeConverterVisitor.convertNodes(jnodes, parentNode);
67     
68     parentNode.setBody(cnodes);
69     }
70
71     
72     public org.netbeans.modules.web.jsps.parserapi.Mark convertMark(Mark m) {
73         if (m == null) {
74             return null;
75         }
76         else {
77             return new org.netbeans.modules.web.jsps.parserapi.Mark(m.getFile(),
78                                 m.getLineNumber(),
79                                 m.getColumnNumber());
80         }
81     }
82
83     public void visit(Node.PageDirective n) {
84     org.netbeans.modules.web.jsps.parserapi.Node cn =
85         new org.netbeans.modules.web.jsps.parserapi.Node.PageDirective(n.getAttributes(),
86                                           convertMark(n.getStart()),
87                                           parentNode);
88     convertedNodeList.add(cn);
89     }
90     
91     public void visit(Node.TaglibDirective n) {
92     org.netbeans.modules.web.jsps.parserapi.Node cn =
93         new org.netbeans.modules.web.jsps.parserapi.Node.TaglibDirective(n.getAttributes(),
94                                         convertMark(n.getStart()),
95                                         parentNode);
96     convertedNodeList.add(cn);
97     }
98     
99     public void visit(Node.AttributeDirective n) throws JasperException {
100     org.netbeans.modules.web.jsps.parserapi.Node.AttributeDirective cn =
101         new org.netbeans.modules.web.jsps.parserapi.Node.AttributeDirective(n.getAttributes(),
102                                           convertMark(n.getStart()),
103                                           parentNode);
104     convertBody(n, cn);
105     convertedNodeList.add(cn);
106     }
107
108     public void visit(Node.VariableDirective n) throws JasperException {
109     org.netbeans.modules.web.jsps.parserapi.Node.VariableDirective cn =
110         new org.netbeans.modules.web.jsps.parserapi.Node.VariableDirective(n.getAttributes(),
111                                           convertMark(n.getStart()),
112                                           parentNode);
113     convertBody(n, cn);
114     convertedNodeList.add(cn);
115     }
116
117     public void visit(Node.IncludeDirective n) throws JasperException {
118     org.netbeans.modules.web.jsps.parserapi.Node.IncludeDirective cn =
119         new org.netbeans.modules.web.jsps.parserapi.Node.IncludeDirective(n.getAttributes(),
120                                           convertMark(n.getStart()),
121                                           parentNode);
122     convertBody(n, cn);
123     convertedNodeList.add(cn);
124     }
125     
126     public void visit(Node.Comment n) {
127     org.netbeans.modules.web.jsps.parserapi.Node cn =
128         new org.netbeans.modules.web.jsps.parserapi.Node.Comment(n.getText(),
129                                     convertMark(n.getStart()),
130                                     parentNode);
131     convertedNodeList.add(cn);
132     }
133     
134     public void visit(Node.Declaration n) {
135     org.netbeans.modules.web.jsps.parserapi.Node cn =
136         new org.netbeans.modules.web.jsps.parserapi.Node.Declaration(n.getText(),
137                                         convertMark(n.getStart()),
138                                         parentNode);
139     convertedNodeList.add(cn);
140     }
141     
142     public void visit(Node.Expression n) {
143     org.netbeans.modules.web.jsps.parserapi.Node cn =
144         new org.netbeans.modules.web.jsps.parserapi.Node.Expression(n.getText(),
145                                        convertMark(n.getStart()),
146                                        parentNode);
147     convertedNodeList.add(cn);
148     }
149     
150     public void visit(Node.Scriptlet n) {
151     org.netbeans.modules.web.jsps.parserapi.Node cn =
152         new org.netbeans.modules.web.jsps.parserapi.Node.Scriptlet(n.getText(),
153                                       convertMark(n.getStart()),
154                                       parentNode);
155     convertedNodeList.add(cn);
156     }
157     
158     public void visit(Node.IncludeAction n) throws JasperException {
159     org.netbeans.modules.web.jsps.parserapi.Node.IncludeAction cn =
160         new org.netbeans.modules.web.jsps.parserapi.Node.IncludeAction(n.getAttributes(),
161                                        convertMark(n.getStart()),
162                                        parentNode);
163     convertBody(n, cn);
164     convertedNodeList.add(cn);
165     }
166     
167     public void visit(Node.DoBodyAction n) throws JasperException {
168     org.netbeans.modules.web.jsps.parserapi.Node.DoBodyAction cn =
169         new org.netbeans.modules.web.jsps.parserapi.Node.DoBodyAction(n.getAttributes(),
170                                        convertMark(n.getStart()),
171                                        parentNode);
172     convertBody(n, cn);
173     convertedNodeList.add(cn);
174     }
175     
176     
177     public void visit(Node.ForwardAction n) throws JasperException {
178     org.netbeans.modules.web.jsps.parserapi.Node.ForwardAction cn =
179         new org.netbeans.modules.web.jsps.parserapi.Node.ForwardAction(n.getAttributes(),
180                                        convertMark(n.getStart()),
181                                        parentNode);
182     convertBody(n, cn);
183     convertedNodeList.add(cn);
184     }
185     
186     public void visit(Node.GetProperty n) {
187     org.netbeans.modules.web.jsps.parserapi.Node cn =
188         new org.netbeans.modules.web.jsps.parserapi.Node.GetProperty(n.getAttributes(),
189                                         convertMark(n.getStart()),
190                                         parentNode);
191     convertedNodeList.add(cn);
192     }
193     
194     public void visit(Node.SetProperty n) throws JasperException {
195     org.netbeans.modules.web.jsps.parserapi.Node.SetProperty cn =
196         new org.netbeans.modules.web.jsps.parserapi.Node.SetProperty(n.getAttributes(),
197                                      convertMark(n.getStart()),
198                                      parentNode);
199     convertBody(n, cn);
200     convertedNodeList.add(cn);
201     }
202     
203     public void visit(Node.UseBean n) throws JasperException {
204     org.netbeans.modules.web.jsps.parserapi.Node.UseBean cn =
205         new org.netbeans.modules.web.jsps.parserapi.Node.UseBean(n.getAttributes(),
206                                      convertMark(n.getStart()),
207                                      parentNode);
208     convertBody(n, cn);
209     convertedNodeList.add(cn);
210     }
211     
212     public void visit(Node.PlugIn n) throws JasperException {
213     org.netbeans.modules.web.jsps.parserapi.Node.PlugIn cn =
214         new org.netbeans.modules.web.jsps.parserapi.Node.PlugIn(n.getAttributes(),
215                                     convertMark(n.getStart()),
216                                     parentNode);
217     convertBody(n, cn);
218     convertedNodeList.add(cn);
219     }
220     
221     public void visit(Node.ParamsAction n) throws JasperException {
222     org.netbeans.modules.web.jsps.parserapi.Node.ParamsAction cn =
223         new org.netbeans.modules.web.jsps.parserapi.Node.ParamsAction(convertMark(n.getStart()),
224                                       parentNode);
225     convertBody(n, cn);
226     convertedNodeList.add(cn);
227     }
228     
229     public void visit(Node.ParamAction n) throws JasperException {
230     org.netbeans.modules.web.jsps.parserapi.Node.ParamAction cn =
231         new org.netbeans.modules.web.jsps.parserapi.Node.ParamAction(n.getAttributes(),
232                                      convertMark(n.getStart()),
233                                      parentNode);
234     convertBody(n, cn);
235     convertedNodeList.add(cn);
236     }
237     
238     public void visit(Node.InvokeAction n) {
239     org.netbeans.modules.web.jsps.parserapi.Node cn =
240         new org.netbeans.modules.web.jsps.parserapi.Node.InvokeAction(n.getAttributes(),
241                                       convertMark(n.getStart()),
242                                       parentNode);
243     convertedNodeList.add(cn);
244     }
245     
246     public void visit(Node.NamedAttribute n) throws JasperException {
247     org.netbeans.modules.web.jsps.parserapi.Node.NamedAttribute cn =
248         new org.netbeans.modules.web.jsps.parserapi.Node.NamedAttribute(n.getAttributes(),
249                                         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 =
257         new org.netbeans.modules.web.jsps.parserapi.Node.JspBody(convertMark(n.getStart()),
258                                      parentNode);
259     convertBody(n, cn);
260     convertedNodeList.add(cn);
261     }
262     
263     public void visit(Node.ELExpression n) {
264     org.netbeans.modules.web.jsps.parserapi.Node cn =
265         new org.netbeans.modules.web.jsps.parserapi.Node.ELExpression(n.getText(),
266                                          convertMark(n.getStart()),
267                                          parentNode);
268     convertedNodeList.add(cn);
269     }
270     
271     public void visit(Node.CustomTag n) throws JasperException {
272     org.netbeans.modules.web.jsps.parserapi.Node.CustomTag cn = null;
273         if (n.getTagFileInfo() == null) {
274             // no tag file
275
cn = new org.netbeans.modules.web.jsps.parserapi.Node.CustomTag(n.getQName(),
276                                                                             n.getPrefix(),
277                                                                             n.getLocalName(),
278                                                                             n.getURI(),
279                                                                             n.getAttributes(),
280                                                                             convertMark(n.getStart()),
281                                                                             parentNode,
282                                                                             n.getTagInfo(),
283                                                                             n.getTagHandlerClass()
284             );
285         }
286         else {
287             // we do have a tag file
288
cn = new org.netbeans.modules.web.jsps.parserapi.Node.CustomTag(n.getQName(),
289                                                                             n.getPrefix(),
290                                                                             n.getLocalName(),
291                                                                             n.getURI(),
292                                                                             n.getAttributes(),
293                                                                             convertMark(n.getStart()),
294                                                                             parentNode,
295                                                                             n.getTagFileInfo()
296             );
297         }
298     convertBody(n, cn);
299     convertedNodeList.add(cn);
300     }
301     
302     public void visit(Node.UninterpretedTag n) throws JasperException {
303     Attributes JavaDoc nonTaglibXmlnsAttrs = null; // ??
304
Attributes JavaDoc taglibAttrs = null; // ??
305
org.netbeans.modules.web.jsps.parserapi.Node.UninterpretedTag cn =
306         new org.netbeans.modules.web.jsps.parserapi.Node.UninterpretedTag(n.getQName(),
307                                           n.getLocalName(),
308                                           n.getAttributes(),
309                                           nonTaglibXmlnsAttrs,
310                                           taglibAttrs,
311                                           convertMark(n.getStart()),
312                                           parentNode);
313     convertBody(n, cn);
314     convertedNodeList.add(cn);
315     }
316     
317     public void visit(Node.TemplateText n) {
318     org.netbeans.modules.web.jsps.parserapi.Node cn =
319         new org.netbeans.modules.web.jsps.parserapi.Node.TemplateText(n.getText(),
320                                       convertMark(n.getStart()),
321                                       parentNode);
322     convertedNodeList.add(cn);
323     }
324     
325     
326 }
327
328
Popular Tags