View Javadoc

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   * The contents of this file are subject to the Mozilla Public License Version
59   * 1.1 (the "License"); you may not use this file except in compliance with the
60   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
61   * Software distributed under the License is distributed on an "AS IS" basis,
62   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
63   * the specific language governing rights and limitations under the License. The
64   * Original Code is: all this file. The Initial Developer of the Original Code
65   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
66   */