View Javadoc

1   package org.apache.velocity.runtime.visitor;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.io.Writer;
23  
24  import org.apache.velocity.context.InternalContextAdapter;
25  import org.apache.velocity.runtime.parser.node.ASTAddNode;
26  import org.apache.velocity.runtime.parser.node.ASTAndNode;
27  import org.apache.velocity.runtime.parser.node.ASTAssignment;
28  import org.apache.velocity.runtime.parser.node.ASTBlock;
29  import org.apache.velocity.runtime.parser.node.ASTComment;
30  import org.apache.velocity.runtime.parser.node.ASTDirective;
31  import org.apache.velocity.runtime.parser.node.ASTDivNode;
32  import org.apache.velocity.runtime.parser.node.ASTEQNode;
33  import org.apache.velocity.runtime.parser.node.ASTElseIfStatement;
34  import org.apache.velocity.runtime.parser.node.ASTElseStatement;
35  import org.apache.velocity.runtime.parser.node.ASTEscape;
36  import org.apache.velocity.runtime.parser.node.ASTEscapedDirective;
37  import org.apache.velocity.runtime.parser.node.ASTExpression;
38  import org.apache.velocity.runtime.parser.node.ASTFalse;
39  import org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral;
40  import org.apache.velocity.runtime.parser.node.ASTGENode;
41  import org.apache.velocity.runtime.parser.node.ASTGTNode;
42  import org.apache.velocity.runtime.parser.node.ASTIdentifier;
43  import org.apache.velocity.runtime.parser.node.ASTIfStatement;
44  import org.apache.velocity.runtime.parser.node.ASTIntegerLiteral;
45  import org.apache.velocity.runtime.parser.node.ASTIntegerRange;
46  import org.apache.velocity.runtime.parser.node.ASTLENode;
47  import org.apache.velocity.runtime.parser.node.ASTLTNode;
48  import org.apache.velocity.runtime.parser.node.ASTMap;
49  import org.apache.velocity.runtime.parser.node.ASTMethod;
50  import org.apache.velocity.runtime.parser.node.ASTModNode;
51  import org.apache.velocity.runtime.parser.node.ASTMulNode;
52  import org.apache.velocity.runtime.parser.node.ASTNENode;
53  import org.apache.velocity.runtime.parser.node.ASTNotNode;
54  import org.apache.velocity.runtime.parser.node.ASTObjectArray;
55  import org.apache.velocity.runtime.parser.node.ASTOrNode;
56  import org.apache.velocity.runtime.parser.node.ASTReference;
57  import org.apache.velocity.runtime.parser.node.ASTSetDirective;
58  import org.apache.velocity.runtime.parser.node.ASTStop;
59  import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
60  import org.apache.velocity.runtime.parser.node.ASTSubtractNode;
61  import org.apache.velocity.runtime.parser.node.ASTText;
62  import org.apache.velocity.runtime.parser.node.ASTTrue;
63  import org.apache.velocity.runtime.parser.node.ASTWord;
64  import org.apache.velocity.runtime.parser.node.ASTprocess;
65  import org.apache.velocity.runtime.parser.node.ParserVisitor;
66  import org.apache.velocity.runtime.parser.node.SimpleNode;
67  
68  /**
69   * This is the base class for all visitors.
70   * For each AST node, this class will provide
71   * a bare-bones method for traversal.
72   *
73   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
74   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
75   * @version $Id: BaseVisitor.java 685685 2008-08-13 21:43:27Z nbubna $
76   */
77  public abstract class BaseVisitor implements ParserVisitor
78  {
79      /** Context used during traversal */
80      protected InternalContextAdapter context;
81  
82      /** Writer used as the output sink */
83      protected Writer writer;
84  
85      /**
86       * @param writer
87       */
88      public void setWriter( Writer writer )
89      {
90          this.writer = writer;
91      }
92  
93      /**
94       * @param context
95       */
96      public void setContext( InternalContextAdapter context)
97      {
98          this.context = context;
99      }
100 
101     /**
102      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.SimpleNode, java.lang.Object)
103      */
104     public Object visit(SimpleNode node, Object data)
105     {
106         data = node.childrenAccept(this, data);
107         return data;
108     }
109 
110     /**
111      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTprocess, java.lang.Object)
112      */
113     public Object visit(ASTprocess node, Object data)
114     {
115         data = node.childrenAccept(this, data);
116         return data;
117     }
118 
119     /**
120      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTExpression, java.lang.Object)
121      */
122     public Object visit(ASTExpression node, Object data)
123     {
124         data = node.childrenAccept(this, data);
125         return data;
126     }
127 
128     /**
129      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAssignment, java.lang.Object)
130      */
131     public Object visit(ASTAssignment node, Object data)
132     {
133         data = node.childrenAccept(this, data);
134         return data;
135     }
136 
137     /**
138      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTOrNode, java.lang.Object)
139      */
140     public Object visit(ASTOrNode node, Object data)
141     {
142         data = node.childrenAccept(this, data);
143         return data;
144     }
145 
146     /**
147      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAndNode, java.lang.Object)
148      */
149     public Object visit(ASTAndNode node, Object data)
150     {
151         data = node.childrenAccept(this, data);
152         return data;
153     }
154 
155     /**
156      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEQNode, java.lang.Object)
157      */
158     public Object visit(ASTEQNode node, Object data)
159     {
160         data = node.childrenAccept(this, data);
161         return data;
162     }
163 
164     /**
165      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNENode, java.lang.Object)
166      */
167     public Object visit(ASTNENode node, Object data)
168     {
169         data = node.childrenAccept(this, data);
170         return data;
171     }
172 
173     /**
174      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLTNode, java.lang.Object)
175      */
176     public Object visit(ASTLTNode node, Object data)
177     {
178         data = node.childrenAccept(this, data);
179         return data;
180     }
181 
182     /**
183      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGTNode, java.lang.Object)
184      */
185     public Object visit(ASTGTNode node, Object data)
186     {
187         data = node.childrenAccept(this, data);
188         return data;
189     }
190 
191     /**
192      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLENode, java.lang.Object)
193      */
194     public Object visit(ASTLENode node, Object data)
195     {
196         data = node.childrenAccept(this, data);
197         return data;
198     }
199 
200     /**
201      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGENode, java.lang.Object)
202      */
203     public Object visit(ASTGENode node, Object data)
204     {
205         data = node.childrenAccept(this, data);
206         return data;
207     }
208 
209     /**
210      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAddNode, java.lang.Object)
211      */
212     public Object visit(ASTAddNode node, Object data)
213     {
214         data = node.childrenAccept(this, data);
215         return data;
216     }
217 
218     /**
219      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSubtractNode, java.lang.Object)
220      */
221     public Object visit(ASTSubtractNode node, Object data)
222     {
223         data = node.childrenAccept(this, data);
224         return data;
225     }
226 
227     /**
228      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMulNode, java.lang.Object)
229      */
230     public Object visit(ASTMulNode node, Object data)
231     {
232         data = node.childrenAccept(this, data);
233         return data;
234     }
235 
236     /**
237      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDivNode, java.lang.Object)
238      */
239     public Object visit(ASTDivNode node, Object data)
240     {
241         data = node.childrenAccept(this, data);
242         return data;
243     }
244 
245     /**
246      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTModNode, java.lang.Object)
247      */
248     public Object visit(ASTModNode node, Object data)
249     {
250         data = node.childrenAccept(this, data);
251         return data;
252     }
253 
254     /**
255      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNotNode, java.lang.Object)
256      */
257     public Object visit(ASTNotNode node, Object data)
258     {
259         data = node.childrenAccept(this, data);
260         return data;
261     }
262 
263     /**
264      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerLiteral, java.lang.Object)
265      */
266     public Object visit(ASTIntegerLiteral node, Object data)
267     {
268         data = node.childrenAccept(this, data);
269         return data;
270     }
271 
272     /**
273      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral, java.lang.Object)
274      * @since 1.5
275      */
276     public Object visit(ASTFloatingPointLiteral node, Object data)
277     {
278         data = node.childrenAccept(this, data);
279         return data;
280     }
281 
282     /**
283      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTStringLiteral, java.lang.Object)
284      */
285     public Object visit(ASTStringLiteral node, Object data)
286     {
287         data = node.childrenAccept(this, data);
288         return data;
289     }
290 
291     /**
292      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIdentifier, java.lang.Object)
293      */
294     public Object visit(ASTIdentifier node, Object data)
295     {
296         data = node.childrenAccept(this, data);
297         return data;
298     }
299 
300     /**
301      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMethod, java.lang.Object)
302      */
303     public Object visit(ASTMethod node, Object data)
304     {
305         data = node.childrenAccept(this, data);
306         return data;
307     }
308 
309     /**
310      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTReference, java.lang.Object)
311      */
312     public Object visit(ASTReference node, Object data)
313     {
314         data = node.childrenAccept(this, data);
315         return data;
316     }
317 
318     /**
319      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTTrue, java.lang.Object)
320      */
321     public Object visit(ASTTrue node, Object data)
322     {
323         data = node.childrenAccept(this, data);
324         return data;
325     }
326 
327     /**
328      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFalse, java.lang.Object)
329      */
330     public Object visit(ASTFalse node, Object data)
331     {
332         data = node.childrenAccept(this, data);
333         return data;
334     }
335 
336     /**
337      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTBlock, java.lang.Object)
338      */
339     public Object visit(ASTBlock node, Object data)
340     {
341         data = node.childrenAccept(this, data);
342         return data;
343     }
344 
345     /**
346      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTText, java.lang.Object)
347      */
348     public Object visit(ASTText node, Object data)
349     {
350         data = node.childrenAccept(this, data);
351         return data;
352     }
353 
354     /**
355      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIfStatement, java.lang.Object)
356      */
357     public Object visit(ASTIfStatement node, Object data)
358     {
359         data = node.childrenAccept(this, data);
360         return data;
361     }
362 
363     /**
364      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseStatement, java.lang.Object)
365      */
366     public Object visit(ASTElseStatement node, Object data)
367     {
368         data = node.childrenAccept(this, data);
369         return data;
370     }
371 
372     /**
373      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseIfStatement, java.lang.Object)
374      */
375     public Object visit(ASTElseIfStatement node, Object data)
376     {
377         data = node.childrenAccept(this, data);
378         return data;
379     }
380 
381     /**
382      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTComment, java.lang.Object)
383      */
384     public Object visit(ASTComment node, Object data)
385     {
386         data = node.childrenAccept(this, data);
387         return data;
388     }
389 
390     /**
391      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTObjectArray, java.lang.Object)
392      */
393     public Object visit(ASTObjectArray node, Object data)
394     {
395         data = node.childrenAccept(this, data);
396         return data;
397     }
398 
399     /**
400      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTWord, java.lang.Object)
401      */
402     public Object visit(ASTWord node, Object data)
403     {
404         data = node.childrenAccept(this, data);
405         return data;
406     }
407 
408     /**
409      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSetDirective, java.lang.Object)
410      */
411     public Object visit(ASTSetDirective node, Object data)
412     {
413         data = node.childrenAccept(this, data);
414         return data;
415     }
416 
417     /**
418      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDirective, java.lang.Object)
419      */
420     public Object visit(ASTDirective node, Object data)
421     {
422         data = node.childrenAccept(this, data);
423         return data;
424     }
425 
426     /**
427      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscapedDirective, java.lang.Object)
428      * @since 1.5
429      */
430     public Object visit(ASTEscapedDirective node, Object data)
431     {
432         data = node.childrenAccept(this, data);
433         return data;
434     }
435 
436     /**
437      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscape, java.lang.Object)
438      * @since 1.5
439      */
440     public Object visit(ASTEscape node, Object data)
441     {
442         data = node.childrenAccept(this, data);
443         return data;
444     }
445 
446     /**
447      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMap, java.lang.Object)
448      * @since 1.5
449      */
450     public Object visit(ASTMap node, Object data)
451     {
452         data = node.childrenAccept(this, data);
453         return data;
454     }
455 
456     /**
457      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerRange, java.lang.Object)
458      * @since 1.5
459      */
460     public Object visit(ASTIntegerRange node, Object data)
461     {
462         data = node.childrenAccept(this, data);
463         return data;
464     }
465 
466     /**
467      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTStop, java.lang.Object)
468      * @since 1.5
469      */
470     public Object visit(ASTStop node, Object data)
471     {
472         data = node.childrenAccept(this, data);
473         return data;
474     }
475 }