KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > TreeAction


1 /*
2  * $Header: /cvsroot/jonas/jonas/src/org/objectweb/jonas/webapp/jonasadmin/TreeAction.java,v 1.5 2005/05/13 12:34:44 danesa Exp $
3  * $Revision: 1.5 $
4  * $Date: 2005/05/13 12:34:44 $
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.objectweb.jonas.webapp.jonasadmin;
63
64 import java.io.IOException JavaDoc;
65 import java.net.URLEncoder JavaDoc;
66
67 import javax.servlet.ServletException JavaDoc;
68 import javax.servlet.http.HttpServletRequest JavaDoc;
69 import javax.servlet.http.HttpServletResponse JavaDoc;
70 import javax.servlet.http.HttpSession JavaDoc;
71
72 import org.apache.struts.action.Action;
73 import org.apache.struts.action.ActionForm;
74 import org.apache.struts.action.ActionForward;
75 import org.apache.struts.action.ActionMapping;
76 import org.objectweb.jonas.common.Log;
77 import org.objectweb.jonas.webapp.taglib.TreeControl;
78 import org.objectweb.jonas.webapp.taglib.TreeControlNode;
79 import org.objectweb.util.monolog.api.BasicLevel;
80 import org.objectweb.util.monolog.api.Logger;
81
82 /**
83  * Test <code>Action</code> that handles events from the tree control test
84  * page.
85  *
86  * @author Craig R. McClanahan
87  * @version $Revision: 1.5 $ $Date: 2005/05/13 12:34:44 $
88  */

89
90 public class TreeAction extends Action {
91
92     private static Logger logger = Log.getLogger(Log.JONAS_ADMIN_PREFIX);
93
94 // --------------------------------------------------------- Public Methods
95

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

111     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request
112         , HttpServletResponse JavaDoc response)
113         throws IOException JavaDoc, ServletException JavaDoc {
114
115         String JavaDoc name = null;
116         HttpSession JavaDoc session = request.getSession();
117         WhereAreYou oWhere = (WhereAreYou) session.getAttribute(WhereAreYou.SESSION_NAME);
118         // Detect if a WhereAreYou instance is present
119
if (oWhere == null) {
120             // Re-init
121
//getServlet().log("Instance WhereAreYou not found in session : re-init");
122
if (logger.isLoggable(BasicLevel.DEBUG)) {
123                 logger.log(BasicLevel.DEBUG, "Instance WhereAreYou not found in session : re-init");
124             }
125             return (mapping.findForward("Main Index"));
126         }
127         // Get the tree
128
TreeControl control = oWhere.getTreeControl();
129         // Handle a tree expand/contract event
130
name = request.getParameter("tree");
131         if (name != null) {
132             //getServlet().log("Tree expand/contract on " + name);
133
if (logger.isLoggable(BasicLevel.DEBUG)) {
134                 logger.log(BasicLevel.DEBUG, "Tree expand/contract on " + name);
135             }
136             TreeControlNode node = control.findNode(name);
137             if (node != null) {
138                 //getServlet().log("Found Node: " + name + "[" + node.getLabel() + "]");
139
if (logger.isLoggable(BasicLevel.DEBUG)) {
140                     logger.log(BasicLevel.DEBUG, "Found Node: " + name + "[" + node.getLabel() + "]");
141                 }
142                 node.setExpanded(!node.isExpanded());
143                 // Add the anchor
144
request.setAttribute("anchorToGo", URLEncoder.encode(name, "UTF-8"));
145             }
146         }
147         else {
148             //getServlet().log("tree param is null");
149
if (logger.isLoggable(BasicLevel.DEBUG)) {
150                 logger.log(BasicLevel.DEBUG, "tree param is null");
151             }
152         }
153
154         // Handle a select item event
155
name = request.getParameter("select");
156         if (name != null) {
157             //getServlet().log("Select event on " + name);
158
if (logger.isLoggable(BasicLevel.DEBUG)) {
159                 logger.log(BasicLevel.DEBUG, "Select event on " + name);
160             }
161             control.selectNode(name);
162             // Add the anchor
163
request.setAttribute("anchorToGo", URLEncoder.encode(name, "UTF-8"));
164         }
165
166         // Forward back to the test page
167
return (mapping.findForward("Tree"));
168     }
169 }
170
Popular Tags