KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > content > SetUpTreeAction


1 /*
2  * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpTreeAction.java,v 1.6 2002/01/26 20:52:58 manveen Exp $
3  * $Revision: 1.6 $
4  * $Date: 2002/01/26 20:52:58 $
5  *
6  * ====================================================================
7  *
8  * The Apache Software License, Version 1.1
9  *
10  * Copyright (c) 2001 The Apache Software Foundation. All rights
11  * reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  *
20  * 2. Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in
22  * the documentation and/or other materials provided with the
23  * distribution.
24  *
25  * 3. The end-user documentation included with the redistribution, if
26  * any, must include the following acknowlegement:
27  * "This product includes software developed by the
28  * Apache Software Foundation (http://www.apache.org/)."
29  * Alternately, this acknowlegement may appear in the software itself,
30  * if and wherever such third-party acknowlegements normally appear.
31  *
32  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
33  * Foundation" must not be used to endorse or promote products derived
34  * from this software without prior written permission. For written
35  * permission, please contact apache@apache.org.
36  *
37  * 5. Products derived from this software may not be called "Apache"
38  * nor may "Apache" appear in their names without prior written
39  * permission of the Apache Group.
40  *
41  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  * ====================================================================
54  *
55  * This software consists of voluntary contributions made by many
56  * individuals on behalf of the Apache Software Foundation. For more
57  * information on the Apache Software Foundation, please see
58  * <http://www.apache.org/>.
59  *
60  */

61
62 package org.nextime.ion.backoffice.action.content;
63
64 import java.io.IOException JavaDoc;
65 import java.util.ArrayList JavaDoc;
66 import java.util.StringTokenizer JavaDoc;
67
68 import javax.servlet.ServletException JavaDoc;
69 import javax.servlet.http.HttpServletRequest JavaDoc;
70 import javax.servlet.http.HttpServletResponse JavaDoc;
71 import javax.servlet.http.HttpSession JavaDoc;
72
73 import org.apache.struts.action.ActionForm;
74 import org.apache.struts.action.ActionForward;
75 import org.apache.struts.action.ActionMapping;
76 import org.apache.struts.action.ActionServlet;
77 import org.nextime.ion.backoffice.action.BaseAction;
78 import org.nextime.ion.backoffice.tree.TreeBuilder;
79 import org.nextime.ion.backoffice.tree.TreeControl;
80 import org.nextime.ion.backoffice.tree.TreeControlNode;
81
82 /**
83  * Test <code>Action</code> sets up tree control data structure
84  * for tree widget
85  *
86  * @author Jazmin Jonson
87  * @author Manveen Kaur
88  * @version $Revision: 1.6 $ $Date: 2002/01/26 20:52:58 $
89  */

90
91 public class SetUpTreeAction extends BaseAction {
92
93     public static final int INIT_PLUGIN_MAX = 10;
94     public static final String JavaDoc TREEBUILDER_KEY = "treebuilders";
95     public static final String JavaDoc ROOTNODENAME_KEY = "rootnodename";
96
97     // --------------------------------------------------------- Public Methods
98

99     /**
100      * Process the specified HTTP request, and create the corresponding HTTP
101      * response (or forward to another web component that will create it).
102      * Return an <code>ActionForward</code> instance describing where and how
103      * control should be forwarded, or <code>null</code> if the response has
104      * already been completed.
105      *
106      * @param mapping The ActionMapping used to select this instance
107      * @param actionForm The optional ActionForm bean for this request (if any)
108      * @param request The HTTP request we are processing
109      * @param response The HTTP response we are creating
110      *
111      * @exception IOException if an input/output error occurs
112      * @exception ServletException if a servlet exception occurs
113      */

114     public ActionForward perform(
115         ActionMapping mapping,
116         ActionForm form,
117         HttpServletRequest JavaDoc request,
118         HttpServletResponse JavaDoc response)
119         throws IOException JavaDoc, ServletException JavaDoc {
120             
121         // check if user is correctly logged
122
checkUser(request);
123
124         HttpSession JavaDoc session = request.getSession();
125         
126         // clean tree
127
if( request.getParameter("clean")!=null ) {
128             session.removeAttribute("treeControlTest");
129         }
130
131         if (session.getAttribute("treeControlTest") == null) {
132
133             ActionServlet servlet = getServlet();
134
135             // Getting init parms from web.xml
136

137             // Get the string to be displayed as root node while rendering the tree
138
String JavaDoc rootnodeName = servlet.getInitParameter("rootNodeName");
139
140             String JavaDoc treeBuildersStr =
141                 "org.nextime.ion.backoffice.tree.WcmTreeBuilder";
142
143             // Make the root node and tree control
144

145             // The root node gets rendered only if its value
146
// is set as an init-param in web.xml
147

148             TreeControlNode root =
149                 new TreeControlNode(
150                     "ROOT-NODE",
151                     "root.gif",
152                     rootnodeName,
153                     "setUpTree.x?select=ROOT-NODE",
154                     "content",
155                     true);
156
157             TreeControl control = new TreeControl(root);
158
159             if (treeBuildersStr != null) {
160                 Class JavaDoc treeBuilderImpl;
161                 TreeBuilder treeBuilderBase;
162
163                 ArrayList JavaDoc treeBuilders = new ArrayList JavaDoc(INIT_PLUGIN_MAX);
164                 int i = 0;
165                 StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(treeBuildersStr, ",");
166                 while (st.hasMoreTokens()) {
167                     treeBuilders.add(st.nextToken().trim());
168                 }
169
170                 if (treeBuilders.size() == 0)
171                     treeBuilders.add(treeBuildersStr.trim());
172
173                 for (i = 0; i < treeBuilders.size(); i++) {
174
175                     try {
176                         treeBuilderImpl =
177                             Class.forName((String JavaDoc) treeBuilders.get(i));
178                         treeBuilderBase =
179                             (TreeBuilder) treeBuilderImpl.newInstance();
180                         treeBuilderBase.buildTree(control, servlet, request);
181                     } catch (Throwable JavaDoc t) {
182                         t.printStackTrace(System.out);
183                     }
184                 }
185             }
186
187             session = request.getSession();
188             session.setAttribute("treeControlTest", control);
189
190             String JavaDoc name = request.getParameter("select");
191             if (name != null) {
192                 control.selectNode(name);
193             }
194
195         }
196
197         return (mapping.findForward("view"));
198
199     }
200 }
201
Popular Tags