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.ASTStringLiteral;
59  import org.apache.velocity.runtime.parser.node.ASTSubtractNode;
60  import org.apache.velocity.runtime.parser.node.ASTText;
61  import org.apache.velocity.runtime.parser.node.ASTTrue;
62  import org.apache.velocity.runtime.parser.node.ASTWord;
63  import org.apache.velocity.runtime.parser.node.ASTprocess;
64  import org.apache.velocity.runtime.parser.node.ParserVisitor;
65  import org.apache.velocity.runtime.parser.node.SimpleNode;
66  
67  /**
68   * This is the base class for all visitors.
69   * For each AST node, this class will provide
70   * a bare-bones method for traversal.
71   *
72   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
73   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
74   * @version $Id: BaseVisitor.java 747106 2009-02-23 19:25:14Z nbubna $
75   */
76  public abstract class BaseVisitor implements ParserVisitor
77  {
78      /** Context used during traversal */
79      protected InternalContextAdapter context;
80  
81      /** Writer used as the output sink */
82      protected Writer writer;
83  
84      /**
85       * @param writer
86       */
87      public void setWriter( Writer writer )
88      {
89          this.writer = writer;
90      }
91  
92      /**
93       * @param context
94       */
95      public void setContext( InternalContextAdapter context)
96      {
97          this.context = context;
98      }
99  
100     /**
101      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.SimpleNode, java.lang.Object)
102      */
103     public Object visit(SimpleNode node, Object data)
104     {
105         data = node.childrenAccept(this, data);
106         return data;
107     }
108 
109     /**
110      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTprocess, java.lang.Object)
111      */
112     public Object visit(ASTprocess node, Object data)
113     {
114         data = node.childrenAccept(this, data);
115         return data;
116     }
117 
118     /**
119      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTExpression, java.lang.Object)
120      */
121     public Object visit(ASTExpression node, Object data)
122     {
123         data = node.childrenAccept(this, data);
124         return data;
125     }
126 
127     /**
128      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAssignment, java.lang.Object)
129      */
130     public Object visit(ASTAssignment node, Object data)
131     {
132         data = node.childrenAccept(this, data);
133         return data;
134     }
135 
136     /**
137      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTOrNode, java.lang.Object)
138      */
139     public Object visit(ASTOrNode node, Object data)
140     {
141         data = node.childrenAccept(this, data);
142         return data;
143     }
144 
145     /**
146      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAndNode, java.lang.Object)
147      */
148     public Object visit(ASTAndNode node, Object data)
149     {
150         data = node.childrenAccept(this, data);
151         return data;
152     }
153 
154     /**
155      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEQNode, java.lang.Object)
156      */
157     public Object visit(ASTEQNode node, Object data)
158     {
159         data = node.childrenAccept(this, data);
160         return data;
161     }
162 
163     /**
164      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNENode, java.lang.Object)
165      */
166     public Object visit(ASTNENode node, Object data)
167     {
168         data = node.childrenAccept(this, data);
169         return data;
170     }
171 
172     /**
173      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLTNode, java.lang.Object)
174      */
175     public Object visit(ASTLTNode node, Object data)
176     {
177         data = node.childrenAccept(this, data);
178         return data;
179     }
180 
181     /**
182      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGTNode, java.lang.Object)
183      */
184     public Object visit(ASTGTNode node, Object data)
185     {
186         data = node.childrenAccept(this, data);
187         return data;
188     }
189 
190     /**
191      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLENode, java.lang.Object)
192      */
193     public Object visit(ASTLENode node, Object data)
194     {
195         data = node.childrenAccept(this, data);
196         return data;
197     }
198 
199     /**
200      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGENode, java.lang.Object)
201      */
202     public Object visit(ASTGENode node, Object data)
203     {
204         data = node.childrenAccept(this, data);
205         return data;
206     }
207 
208     /**
209      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAddNode, java.lang.Object)
210      */
211     public Object visit(ASTAddNode node, Object data)
212     {
213         data = node.childrenAccept(this, data);
214         return data;
215     }
216 
217     /**
218      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSubtractNode, java.lang.Object)
219      */
220     public Object visit(ASTSubtractNode node, Object data)
221     {
222         data = node.childrenAccept(this, data);
223         return data;
224     }
225 
226     /**
227      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMulNode, java.lang.Object)
228      */
229     public Object visit(ASTMulNode node, Object data)
230     {
231         data = node.childrenAccept(this, data);
232         return data;
233     }
234 
235     /**
236      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDivNode, java.lang.Object)
237      */
238     public Object visit(ASTDivNode node, Object data)
239     {
240         data = node.childrenAccept(this, data);
241         return data;
242     }
243 
244     /**
245      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTModNode, java.lang.Object)
246      */
247     public Object visit(ASTModNode node, Object data)
248     {
249         data = node.childrenAccept(this, data);
250         return data;
251     }
252 
253     /**
254      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNotNode, java.lang.Object)
255      */
256     public Object visit(ASTNotNode node, Object data)
257     {
258         data = node.childrenAccept(this, data);
259         return data;
260     }
261 
262     /**
263      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerLiteral, java.lang.Object)
264      */
265     public Object visit(ASTIntegerLiteral node, Object data)
266     {
267         data = node.childrenAccept(this, data);
268         return data;
269     }
270 
271     /**
272      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral, java.lang.Object)
273      * @since 1.5
274      */
275     public Object visit(ASTFloatingPointLiteral node, Object data)
276     {
277         data = node.childrenAccept(this, data);
278         return data;
279     }
280 
281     /**
282      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTStringLiteral, java.lang.Object)
283      */
284     public Object visit(ASTStringLiteral node, Object data)
285     {
286         data = node.childrenAccept(this, data);
287         return data;
288     }
289 
290     /**
291      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIdentifier, java.lang.Object)
292      */
293     public Object visit(ASTIdentifier node, Object data)
294     {
295         data = node.childrenAccept(this, data);
296         return data;
297     }
298 
299     /**
300      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMethod, java.lang.Object)
301      */
302     public Object visit(ASTMethod node, Object data)
303     {
304         data = node.childrenAccept(this, data);
305         return data;
306     }
307 
308     /**
309      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTReference, java.lang.Object)
310      */
311     public Object visit(ASTReference node, Object data)
312     {
313         data = node.childrenAccept(this, data);
314         return data;
315     }
316 
317     /**
318      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTTrue, java.lang.Object)
319      */
320     public Object visit(ASTTrue node, Object data)
321     {
322         data = node.childrenAccept(this, data);
323         return data;
324     }
325 
326     /**
327      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFalse, java.lang.Object)
328      */
329     public Object visit(ASTFalse node, Object data)
330     {
331         data = node.childrenAccept(this, data);
332         return data;
333     }
334 
335     /**
336      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTBlock, java.lang.Object)
337      */
338     public Object visit(ASTBlock node, Object data)
339     {
340         data = node.childrenAccept(this, data);
341         return data;
342     }
343 
344     /**
345      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTText, java.lang.Object)
346      */
347     public Object visit(ASTText node, Object data)
348     {
349         data = node.childrenAccept(this, data);
350         return data;
351     }
352 
353     /**
354      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIfStatement, java.lang.Object)
355      */
356     public Object visit(ASTIfStatement node, Object data)
357     {
358         data = node.childrenAccept(this, data);
359         return data;
360     }
361 
362     /**
363      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseStatement, java.lang.Object)
364      */
365     public Object visit(ASTElseStatement node, Object data)
366     {
367         data = node.childrenAccept(this, data);
368         return data;
369     }
370 
371     /**
372      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseIfStatement, java.lang.Object)
373      */
374     public Object visit(ASTElseIfStatement node, Object data)
375     {
376         data = node.childrenAccept(this, data);
377         return data;
378     }
379 
380     /**
381      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTComment, java.lang.Object)
382      */
383     public Object visit(ASTComment node, Object data)
384     {
385         data = node.childrenAccept(this, data);
386         return data;
387     }
388 
389     /**
390      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTObjectArray, java.lang.Object)
391      */
392     public Object visit(ASTObjectArray node, Object data)
393     {
394         data = node.childrenAccept(this, data);
395         return data;
396     }
397 
398     /**
399      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTWord, java.lang.Object)
400      */
401     public Object visit(ASTWord node, Object data)
402     {
403         data = node.childrenAccept(this, data);
404         return data;
405     }
406 
407     /**
408      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSetDirective, java.lang.Object)
409      */
410     public Object visit(ASTSetDirective node, Object data)
411     {
412         data = node.childrenAccept(this, data);
413         return data;
414     }
415 
416     /**
417      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDirective, java.lang.Object)
418      */
419     public Object visit(ASTDirective node, Object data)
420     {
421         data = node.childrenAccept(this, data);
422         return data;
423     }
424 
425     /**
426      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscapedDirective, java.lang.Object)
427      * @since 1.5
428      */
429     public Object visit(ASTEscapedDirective node, Object data)
430     {
431         data = node.childrenAccept(this, data);
432         return data;
433     }
434 
435     /**
436      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscape, java.lang.Object)
437      * @since 1.5
438      */
439     public Object visit(ASTEscape node, Object data)
440     {
441         data = node.childrenAccept(this, data);
442         return data;
443     }
444 
445     /**
446      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMap, java.lang.Object)
447      * @since 1.5
448      */
449     public Object visit(ASTMap node, Object data)
450     {
451         data = node.childrenAccept(this, data);
452         return data;
453     }
454 
455     /**
456      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerRange, java.lang.Object)
457      * @since 1.5
458      */
459     public Object visit(ASTIntegerRange node, Object data)
460     {
461         data = node.childrenAccept(this, data);
462         return data;
463     }
464 }