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.grant.DefaultPropsHandler;
23 import org.apache.commons.jelly.JellyContext;
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 return value.toString();
69 }
70 }
71
72 /*** Retrieve all ant properties.
73 *
74 * @return A <code>Hashtable</code> of all properties.
75 */
76 public Hashtable getProperties() {
77 Hashtable h = new Hashtable();
78 for (Iterator i = this.context.getVariableNames(); i.hasNext(); ) {
79 String name = (String) i.next();
80 Object value = this.context.getVariable(name);
81 if (name != null && value != null && value.toString() != null) {
82 h.put(name, value.toString());
83 }
84 }
85 return h;
86 }
87
88 }