01: package org.apache.velocity.runtime.visitor;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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.util.Map;
23:
24: import org.apache.velocity.runtime.parser.node.ASTReference;
25:
26: /**
27: * This class is a visitor used by the VM proxy to change the
28: * literal representation of a reference in a VM. The reason is
29: * to preserve the 'render literal if null' behavior w/o making
30: * the VMProxy stuff more complicated than it is already.
31: *
32: * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
33: * @version $Id: VMReferenceMungeVisitor.java 463298 2006-10-12 16:10:32Z henning $
34: */
35: public class VMReferenceMungeVisitor extends BaseVisitor {
36: /**
37: * Map containing VM arg to instance-use reference
38: * Passed in with CTOR
39: */
40: private Map argmap = null;
41:
42: /**
43: * CTOR - takes a map of args to reference
44: * @param map
45: */
46: public VMReferenceMungeVisitor(Map map) {
47: argmap = map;
48: }
49:
50: /**
51: * Visitor method - if the literal is right, will
52: * set the literal in the ASTReference node
53: *
54: * @param node ASTReference to work on
55: * @param data Object to pass down from caller
56: * @return A visitor object result.
57: */
58: public Object visit(ASTReference node, Object data) {
59: /*
60: * see if there is an override value for this
61: * reference
62: */
63: String override = (String) argmap.get(node.literal().substring(
64: 1));
65:
66: /*
67: * if so, set in the node
68: */
69: if (override != null) {
70: node.setLiteral(override);
71: }
72:
73: /*
74: * feed the children...
75: */
76: data = node.childrenAccept(this, data);
77:
78: return data;
79: }
80: }
|