1 package org.apache.turbine.modules.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Hashtable;
23 import java.util.Iterator;
24 import java.util.Properties;
25 import javax.naming.InitialContext;
26 import javax.naming.NamingException;
27
28 import org.apache.commons.configuration.Configuration;
29
30 import org.apache.turbine.Turbine;
31 import org.apache.turbine.modules.Action;
32 import org.apache.turbine.util.RunData;
33
34 /***
35 * Used to initialize JNDI contexts.
36 *
37 * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
38 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
39 * @version $Id: InitContextsAction.java 534527 2007-05-02 16:10:59Z tv $
40 */
41 public class InitContextsAction
42 extends Action
43 {
44 /***
45 * This action will place the contexts defined in the
46 * TurbineResources instance (if any) into the data.contexts
47 * Hashtable.
48 *
49 * @param data The RunData object for the current request.
50 * @exception NamingException could not create InitialContext
51 */
52 public void doPerform(RunData data)
53 throws NamingException
54 {
55 Configuration conf = Turbine.getConfiguration();
56
57
58
59
60
61
62
63
64 Hashtable contextPropsList = new Hashtable();
65 for (Iterator contextKeys = conf.getKeys("context.");
66 contextKeys.hasNext();)
67 {
68 String key = (String) contextKeys.next();
69 int start = key.indexOf(".") + 1;
70 int end = key.indexOf(".", start);
71 String contextName = key.substring(start, end);
72 Properties contextProps = null;
73 if (contextPropsList.containsKey(contextName))
74 {
75 contextProps = (Properties) contextPropsList.get(contextName);
76 }
77 else
78 {
79 contextProps = new Properties();
80 }
81 contextProps.put(key.substring(end + 1),
82 conf.getString(key));
83 contextPropsList.put(contextName, contextProps);
84 }
85 for (Iterator contextPropsKeys = contextPropsList.keySet().iterator();
86 contextPropsKeys.hasNext();)
87 {
88 String key = (String) contextPropsKeys.next();
89 Properties contextProps = (Properties) contextPropsList.get(key);
90 InitialContext context = new InitialContext(contextProps);
91 data.getJNDIContexts().put(key, context);
92 }
93 }
94 }