1 package net.sf.tomp.xtcl.command;
2
3 import java.util.Enumeration;
4 import java.util.Properties;
5
6 import net.sf.tomp.xtcl.Context;
7
8 /***
9 * Puts all key=value pairs from the Properties separately to the Context.
10 *
11 * Prefix of the variable name may be specified, default '$'.
12 *
13 * @author tomp
14 */
15 public class PropertiesToContext extends VarCommand {
16
17 /*** Prefix of the variable name */
18 protected String prefix = "$";
19
20 /***
21 * sets Prefix of the variable name
22 *
23 * @param v
24 * Prefix of the variable name
25 */
26 public void setPrefix(String v) {
27 prefix = v;
28 }
29
30 /***
31 * Puts all key=value pairs from the Properties separately to the Context.
32 *
33 * @param context
34 * @return always succeeds, i.e. 0
35 * @throws Exception
36 * never
37 */
38 public int execute(Context context) throws Exception {
39 Properties props = (Properties) context.get(var);
40 Enumeration names = props.propertyNames();
41 while (names.hasMoreElements()) {
42 String name = (String) names.nextElement();
43 String value = props.getProperty(name);
44 context.put(prefix + name, value);
45 }
46 return done(context, 0);
47 }
48
49 /***
50 * @return "PROPERTIES-TO-CONTEXT " + var + " prefix=" + prefix;
51 */
52 public String toString() {
53 return "PROPERTIES-TO-CONTEXT " + var + " prefix=" + prefix;
54 }
55 }
56
57
58
59
60
61
62
63
64
65
66