001: /*
002: * $Header$
003: * $Revision: 6755 $
004: * $Date: 2005-05-13 12:34:44 +0000 (Fri, 13 May 2005) $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 2001 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: */
061:
062: package org.objectweb.jonas.webapp.jonasadmin;
063:
064: import java.io.IOException;
065: import java.net.URLEncoder;
066:
067: import javax.servlet.ServletException;
068: import javax.servlet.http.HttpServletRequest;
069: import javax.servlet.http.HttpServletResponse;
070: import javax.servlet.http.HttpSession;
071:
072: import org.apache.struts.action.Action;
073: import org.apache.struts.action.ActionForm;
074: import org.apache.struts.action.ActionForward;
075: import org.apache.struts.action.ActionMapping;
076: import org.objectweb.jonas.common.Log;
077: import org.objectweb.jonas.webapp.taglib.TreeControl;
078: import org.objectweb.jonas.webapp.taglib.TreeControlNode;
079: import org.objectweb.util.monolog.api.BasicLevel;
080: import org.objectweb.util.monolog.api.Logger;
081:
082: /**
083: * Test <code>Action</code> that handles events from the tree control test
084: * page.
085: *
086: * @author Craig R. McClanahan
087: * @version $Revision: 6755 $ $Date: 2005-05-13 12:34:44 +0000 (Fri, 13 May 2005) $
088: */
089:
090: public class TreeAction extends Action {
091:
092: private static Logger logger = Log
093: .getLogger(Log.JONAS_ADMIN_PREFIX);
094:
095: // --------------------------------------------------------- Public Methods
096:
097: /**
098: * Process the specified HTTP request, and create the corresponding HTTP
099: * response (or forward to another web component that will create it).
100: * Return an <code>ActionForward</code> instance describing where and how
101: * control should be forwarded, or <code>null</code> if the response has
102: * already been completed.
103: *
104: * @param mapping The ActionMapping used to select this instance
105: * @param actionForm The optional ActionForm bean for this request (if any)
106: * @param request The HTTP request we are processing
107: * @param response The HTTP response we are creating
108: *
109: * @exception IOException if an input/output error occurs
110: * @exception ServletException if a servlet exception occurs
111: */
112: public ActionForward execute(ActionMapping mapping,
113: ActionForm form, HttpServletRequest request,
114: HttpServletResponse response) throws IOException,
115: ServletException {
116:
117: String name = null;
118: HttpSession session = request.getSession();
119: WhereAreYou oWhere = (WhereAreYou) session
120: .getAttribute(WhereAreYou.SESSION_NAME);
121: // Detect if a WhereAreYou instance is present
122: if (oWhere == null) {
123: // Re-init
124: //getServlet().log("Instance WhereAreYou not found in session : re-init");
125: if (logger.isLoggable(BasicLevel.DEBUG)) {
126: logger
127: .log(BasicLevel.DEBUG,
128: "Instance WhereAreYou not found in session : re-init");
129: }
130: return (mapping.findForward("Main Index"));
131: }
132: // Get the tree
133: TreeControl control = oWhere.getTreeControl();
134: // Handle a tree expand/contract event
135: name = request.getParameter("tree");
136: if (name != null) {
137: //getServlet().log("Tree expand/contract on " + name);
138: if (logger.isLoggable(BasicLevel.DEBUG)) {
139: logger.log(BasicLevel.DEBUG, "Tree expand/contract on "
140: + name);
141: }
142: TreeControlNode node = control.findNode(name);
143: if (node != null) {
144: //getServlet().log("Found Node: " + name + "[" + node.getLabel() + "]");
145: if (logger.isLoggable(BasicLevel.DEBUG)) {
146: logger.log(BasicLevel.DEBUG, "Found Node: " + name
147: + "[" + node.getLabel() + "]");
148: }
149: node.setExpanded(!node.isExpanded());
150: // Add the anchor
151: request.setAttribute("anchorToGo", URLEncoder.encode(
152: name, "UTF-8"));
153: }
154: } else {
155: //getServlet().log("tree param is null");
156: if (logger.isLoggable(BasicLevel.DEBUG)) {
157: logger.log(BasicLevel.DEBUG, "tree param is null");
158: }
159: }
160:
161: // Handle a select item event
162: name = request.getParameter("select");
163: if (name != null) {
164: //getServlet().log("Select event on " + name);
165: if (logger.isLoggable(BasicLevel.DEBUG)) {
166: logger.log(BasicLevel.DEBUG, "Select event on " + name);
167: }
168: control.selectNode(name);
169: // Add the anchor
170: request.setAttribute("anchorToGo", URLEncoder.encode(name,
171: "UTF-8"));
172: }
173:
174: // Forward back to the test page
175: return (mapping.findForward("Tree"));
176: }
177: }
|