Source code: org/apache/webapp/admin/SetUpTreeAction.java
1 /*
2 * Copyright 2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 package org.apache.webapp.admin;
19
20
21 import java.io.IOException;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Locale;
25 import java.util.StringTokenizer;
26 import java.util.ArrayList;
27 import javax.servlet.ServletException;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 import javax.servlet.http.HttpSession;
31 import org.apache.struts.action.Action;
32 import org.apache.struts.action.ActionErrors;
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36
37
38 /**
39 * Test <code>Action</code> sets up tree control data structure
40 * for tree widget
41 *
42 * @author Jazmin Jonson
43 * @author Manveen Kaur
44 * @version $Revision: 303390 $ $Date: 2004-10-18 02:37:56 -0400 (Mon, 18 Oct 2004) $
45 */
46
47 public class SetUpTreeAction extends Action {
48
49 public static final String DOMAIN_KEY = "domain";
50 public static final int INIT_PLUGIN_MAX = 10;
51 public static final String TREEBUILDER_KEY = "treebuilders";
52 public static final String ROOTNODENAME_KEY = "rootnodename";
53
54 // --------------------------------------------------------- Public Methods
55
56 /**
57 * Process the specified HTTP request, and create the corresponding HTTP
58 * response (or forward to another web component that will create it).
59 * Return an <code>ActionForward</code> instance describing where and how
60 * control should be forwarded, or <code>null</code> if the response has
61 * already been completed.
62 *
63 * @param mapping The ActionMapping used to select this instance
64 * @param actionForm The optional ActionForm bean for this request (if any)
65 * @param request The HTTP request we are processing
66 * @param response The HTTP response we are creating
67 *
68 * @exception IOException if an input/output error occurs
69 * @exception ServletException if a servlet exception occurs
70 */
71 public ActionForward execute(ActionMapping mapping,
72 ActionForm form,
73 HttpServletRequest request,
74 HttpServletResponse response)
75 throws IOException, ServletException {
76
77 ApplicationServlet servlet = (ApplicationServlet)getServlet();
78
79 // Getting init parms from web.xml
80
81 // Get the string to be displayed as root node while rendering the tree
82 String rootnodeName =
83 (String)servlet.getServletConfig().getInitParameter(ROOTNODENAME_KEY);
84
85 String treeBuildersStr =
86 (String)servlet.getServletConfig().getInitParameter(TREEBUILDER_KEY);
87
88 String domain =
89 (String)servlet.getServletConfig().getInitParameter(DOMAIN_KEY);
90
91
92 // Make the root node and tree control
93
94 // The root node gets rendered only if its value
95 // is set as an init-param in web.xml
96
97 TreeControlNode root =
98 new TreeControlNode("ROOT-NODE",
99 null, rootnodeName,
100 "setUpTree.do?select=ROOT-NODE",
101 "content", true, domain);
102
103 TreeControl control = new TreeControl(root);
104
105 if(treeBuildersStr != null) {
106 Class treeBuilderImpl;
107 TreeBuilder treeBuilderBase;
108
109 ArrayList treeBuilders = new ArrayList(INIT_PLUGIN_MAX);
110 int i = 0;
111 StringTokenizer st = new StringTokenizer(treeBuildersStr, ",");
112 while (st.hasMoreTokens()) {
113 treeBuilders.add(st.nextToken().trim());
114 }
115
116 if(treeBuilders.size() == 0)
117 treeBuilders.add(treeBuildersStr.trim());
118
119 for(i = 0; i < treeBuilders.size(); i++) {
120
121 try{
122 treeBuilderImpl = Class.forName((String)treeBuilders.get(i));
123 treeBuilderBase =
124 (TreeBuilder)treeBuilderImpl.newInstance();
125 treeBuilderBase.buildTree(control, servlet, request);
126 }catch(Throwable t){
127 t.printStackTrace(System.out);
128 }
129 }
130 }
131
132 HttpSession session = request.getSession();
133 session.setAttribute("treeControlTest", control);
134
135 String name = request.getParameter("select");
136 if (name != null) {
137 control.selectNode(name);
138 // Forward back to the Blank page
139 return (mapping.findForward("Blank"));
140 }
141
142 return (mapping.findForward("Tree Control Test"));
143
144 }
145 }