KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > SetUpTreeAction


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 JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Locale JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import javax.servlet.ServletException JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30 import javax.servlet.http.HttpSession JavaDoc;
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: 1.4 $ $Date: 2004/10/18 06:37:53 $
45  */

46
47 public class SetUpTreeAction extends Action {
48
49     public static final String JavaDoc DOMAIN_KEY = "domain";
50     public static final int INIT_PLUGIN_MAX = 10;
51     public static final String JavaDoc TREEBUILDER_KEY = "treebuilders";
52     public static final String JavaDoc 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 JavaDoc request,
74                                  HttpServletResponse JavaDoc response)
75         throws IOException JavaDoc, ServletException JavaDoc {
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 JavaDoc rootnodeName =
83             (String JavaDoc)servlet.getServletConfig().getInitParameter(ROOTNODENAME_KEY);
84         
85         String JavaDoc treeBuildersStr =
86             (String JavaDoc)servlet.getServletConfig().getInitParameter(TREEBUILDER_KEY);
87         
88         String JavaDoc domain =
89             (String JavaDoc)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 JavaDoc treeBuilderImpl;
107             TreeBuilder treeBuilderBase;
108
109             ArrayList JavaDoc treeBuilders = new ArrayList JavaDoc(INIT_PLUGIN_MAX);
110             int i = 0;
111             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(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 JavaDoc)treeBuilders.get(i));
123                     treeBuilderBase =
124                         (TreeBuilder)treeBuilderImpl.newInstance();
125                     treeBuilderBase.buildTree(control, servlet, request);
126                 }catch(Throwable JavaDoc t){
127                     t.printStackTrace(System.out);
128                 }
129             }
130         }
131
132         HttpSession JavaDoc session = request.getSession();
133         session.setAttribute("treeControlTest", control);
134
135          String JavaDoc 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 }
146
Popular Tags