1 package org.apache.commons.jelly.tags.ant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Hashtable;
20 import java.util.Iterator;
21
22 import org.apache.commons.jelly.JellyContext;
23 import org.apache.commons.jelly.expression.Expression;
24
25 /*** Implementation of a Commons Grant <code>propsHandler</code>
26 * to resolve through Jelly's context.
27 *
28 * @author <a href="mailto:bob@eng.werken.com">Bob McWhirter</a>
29 * @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
30 */
31 public class JellyPropsHandler extends DefaultPropsHandler {
32
33 /*** The JellyContext. */
34 private JellyContext context;
35
36 /*** Simple constructor with the context to be used.
37 *
38 * @param context The context to be used.
39 */
40 public JellyPropsHandler(JellyContext context) {
41 this.context = context;
42 }
43
44 /*** Set an ant property.
45 *
46 * @param name The property name.
47 * @param value The property value.
48 */
49 public void setProperty(String name, String value) {
50 this.context.setVariable(name, value);
51 }
52
53 /*** Retrieve an ant property.
54 *
55 * @param name The property name.
56 *
57 * @return The property value.
58 */
59 public String getProperty(String name) {
60 if (name == null) {
61 return null;
62 }
63 Object value = this.context.getVariable(name);
64 if (value == null) {
65 return null;
66 }
67 else {
68 if ( value instanceof Expression )
69 {
70 return ( ( Expression ) value ).evaluateAsString( context );
71 }
72 else
73 {
74 return value.toString();
75 }
76 }
77 }
78
79 /*** Retrieve all ant properties.
80 *
81 * @return A <code>Hashtable</code> of all properties.
82 */
83 public Hashtable getProperties() {
84 Hashtable h = new Hashtable();
85 for (Iterator i = this.context.getVariableNames(); i.hasNext(); ) {
86 String name = (String) i.next();
87 String value = getProperty( name );
88 if (value != null) {
89 h.put(name, value);
90 }
91 }
92 return h;
93 }
94
95 }