SetUpTreeAction.java

00001 /*
00002  * $Header: /cvsroot/jonas/jonas/src/org/objectweb/jonas/webapp/jonasadmin/SetUpTreeAction.java,v 1.2 2004/09/15 12:19:50 benoitf Exp $
00003  * $Revision: 1.2 $
00004  * $Date: 2004/09/15 12:19:50 $
00005  *
00006  * ====================================================================
00007  *
00008  * The Apache Software License, Version 1.1
00009  *
00010  * Copyright (c) 2001 The Apache Software Foundation.  All rights
00011  * reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions
00015  * are met:
00016  *
00017  * 1. Redistributions of source code must retain the above copyright
00018  *    notice, this list of conditions and the following disclaimer.
00019  *
00020  * 2. Redistributions in binary form must reproduce the above copyright
00021  *    notice, this list of conditions and the following disclaimer in
00022  *    the documentation and/or other materials provided with the
00023  *    distribution.
00024  *
00025  * 3. The end-user documentation included with the redistribution, if
00026  *    any, must include the following acknowlegement:
00027  *       "This product includes software developed by the
00028  *        Apache Software Foundation (http://www.apache.org/)."
00029  *    Alternately, this acknowlegement may appear in the software itself,
00030  *    if and wherever such third-party acknowlegements normally appear.
00031  *
00032  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
00033  *    Foundation" must not be used to endorse or promote products derived
00034  *    from this software without prior written permission. For written
00035  *    permission, please contact apache@apache.org.
00036  *
00037  * 5. Products derived from this software may not be called "Apache"
00038  *    nor may "Apache" appear in their names without prior written
00039  *    permission of the Apache Group.
00040  *
00041  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00042  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00043  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00044  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00045  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00046  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00047  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00048  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00049  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00050  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00051  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00052  * SUCH DAMAGE.
00053  * ====================================================================
00054  *
00055  * This software consists of voluntary contributions made by many
00056  * individuals on behalf of the Apache Software Foundation.  For more
00057  * information on the Apache Software Foundation, please see
00058  * <http://www.apache.org/>.
00059  *
00060  */
00061 
00062 package org.objectweb.jonas.webapp.jonasadmin;
00063 
00064 import java.io.IOException;
00065 import java.util.ArrayList;
00066 import java.util.StringTokenizer;
00067 
00068 import javax.servlet.ServletException;
00069 import javax.servlet.http.HttpServletRequest;
00070 import javax.servlet.http.HttpServletResponse;
00071 import javax.servlet.http.HttpSession;
00072 
00073 import org.apache.struts.action.Action;
00074 import org.apache.struts.action.ActionForm;
00075 import org.apache.struts.action.ActionForward;
00076 import org.apache.struts.action.ActionMapping;
00077 import org.apache.struts.action.ActionServlet;
00078 import org.objectweb.jonas.webapp.taglib.TreeBuilder;
00079 import org.objectweb.jonas.webapp.taglib.TreeControl;
00080 import org.objectweb.jonas.webapp.taglib.TreeControlNode;
00081 
00092 public class SetUpTreeAction extends Action {
00093 
00094     public static final int INIT_PLUGIN_MAX = 10;
00095     public static final String TREEBUILDER_KEY = "treebuilders";
00096     public static final String ROOTNODENAME_KEY = "rootnodename";
00097 
00098 // --------------------------------------------------------- Public Methods
00099 
00115     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request
00116         , HttpServletResponse response)
00117         throws IOException, ServletException {
00118 
00119         //ApplicationServlet servlet = (ApplicationServlet) getServlet();
00120         ActionServlet servlet = (ActionServlet) getServlet();
00121 
00122         // Getting init parms from web.xml
00123 
00124         // Get the string to be displayed as root node while rendering the tree
00125         String rootnodeName = (String) servlet.getServletConfig().getInitParameter(ROOTNODENAME_KEY);
00126 
00127         String treeBuildersStr = (String) servlet.getServletConfig().getInitParameter(
00128             TREEBUILDER_KEY);
00129 
00130         // Make the root node and tree control
00131 
00132         // The root node gets rendered only if its value
00133         // is set as an init-param in web.xml
00134 
00135         TreeControlNode root = new TreeControlNode("ROOT-NODE", null, rootnodeName
00136             , "setUpTree.do?select=ROOT-NODE", "content", true);
00137 
00138         TreeControl control = new TreeControl(root);
00139 
00140         if (treeBuildersStr != null) {
00141             Class treeBuilderImpl;
00142             TreeBuilder treeBuilderBase;
00143 
00144             ArrayList treeBuilders = new ArrayList(INIT_PLUGIN_MAX);
00145             int i = 0;
00146             StringTokenizer st = new StringTokenizer(treeBuildersStr, ",");
00147             while (st.hasMoreTokens()) {
00148                 treeBuilders.add(st.nextToken().trim());
00149             }
00150 
00151             if (treeBuilders.size() == 0) {
00152                 treeBuilders.add(treeBuildersStr.trim());
00153             }
00154             for (i = 0; i < treeBuilders.size(); i++) {
00155                 try {
00156                     treeBuilderImpl = Class.forName((String) treeBuilders.get(i));
00157                     treeBuilderBase = (TreeBuilder) treeBuilderImpl.newInstance();
00158                     treeBuilderBase.buildTree(control, servlet, request);
00159                 }
00160                 catch (Throwable t) {
00161                     t.printStackTrace(System.out);
00162                 }
00163             }
00164         }
00165 
00166         HttpSession session = request.getSession();
00167         session.setAttribute("treeControl", control);
00168 
00169         WhereAreYou oWhere = (WhereAreYou) session.getAttribute(WhereAreYou.SESSION_NAME);
00170         oWhere.setTreeControl(control);
00171 
00172         String name = request.getParameter("select");
00173         if (name != null) {
00174             control.selectNode(name);
00175             // Forward back to the Blank page
00176             return (mapping.findForward("Blank"));
00177         }
00178 
00179         return (mapping.findForward("Tree"));
00180 
00181     }
00182 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1