patrickl    01/11/26 18:46:28

  Modified:    webapps/admin/WEB-INF web.xml
               webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        SetUpTreeAction.java TreeControlTag.java
                        TreeControlTestAction.java
  Added:       webapps/admin/WEB-INF/classes/org/apache/webapp/admin
                        TomcatTreeBuilder.java
  Log:
  Initial implementation of the Tomcat tree of administration objects.
  Submitted by: Jazmin Jonson
  
  Revision  Changes    Path
  1.6       +4 -0      jakarta-tomcat-4.0/webapps/admin/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/web.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- web.xml   2001/11/21 01:10:09     1.5
  +++ web.xml   2001/11/27 02:46:28     1.6
  @@ -42,6 +42,10 @@
         <param-name>validate</param-name>
         <param-value>true</param-value>
       </init-param>
  +    <init-param>
  +      <param-name>treebuilders</param-name>
  +      <param-value>org.apache.webapp.admin.TomcatTreeBuilder</param-value>
  +    </init-param>
       <load-on-startup>2</load-on-startup>
     </servlet>
   
  
  
  
  1.2       +4 -4      
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpTreeAction.java
  
  Index: SetUpTreeAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpTreeAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetUpTreeAction.java      2001/11/21 01:10:09     1.1
  +++ SetUpTreeAction.java      2001/11/27 02:46:28     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpTreeAction.java,v
 1.1 2001/11/21 01:10:09 patrickl Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/11/21 01:10:09 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/SetUpTreeAction.java,v
 1.2 2001/11/27 02:46:28 patrickl Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/11/27 02:46:28 $
    *
    * ====================================================================
    *
  @@ -85,7 +85,7 @@
    * for tree widget
    *
    * @author Jazmin Jonson
  - * @version $Revision: 1.1 $ $Date: 2001/11/21 01:10:09 $
  + * @version $Revision: 1.2 $ $Date: 2001/11/27 02:46:28 $
    */
   
   public class SetUpTreeAction extends Action {
  @@ -126,7 +126,7 @@
           TreeControl control = new TreeControl(root);
           ApplicationServlet servlet = (ApplicationServlet)getServlet();
   
  -        // Wait for web.xml code to be hooked up
  +        // Getting init parms from web.xml
   
           String treeBuildersStr  =
               (String)servlet.getServletConfig().getInitParameter(TREEBUILDER_KEY);
  
  
  
  1.4       +17 -6     
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTag.java
  
  Index: TreeControlTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TreeControlTag.java       2001/11/18 01:40:37     1.3
  +++ TreeControlTag.java       2001/11/27 02:46:28     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTag.java,v
 1.3 2001/11/18 01:40:37 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/11/18 01:40:37 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTag.java,v
 1.4 2001/11/27 02:46:28 patrickl Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/11/27 02:46:28 $
    *
    * ====================================================================
    *
  @@ -64,6 +64,7 @@
   
   
   import java.io.IOException;
  +import java.net.URLEncoder;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.jsp.JspException;
   import javax.servlet.jsp.JspWriter;
  @@ -103,7 +104,7 @@
    * <strong>FIXME</strong> - Internationalize the exception messages!
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2001/11/18 01:40:37 $
  + * @version $Revision: 1.4 $ $Date: 2001/11/27 02:46:28 $
    */
   
   public class TreeControlTag extends TagSupport {
  @@ -372,7 +373,15 @@
           }
   
           // Render the tree state image for this node
  -        String action = replace(getAction(), "${name}", node.getName());
  +
  +        // HACK to take into account special characters like = and &
  +        // in the node name, could remove this code if encode URL
  +        // and later request.getParameter() could deal with = and &
  +        // character in parameter values. 
  +        String encodedNodeName = URLEncoder.encode(node.getName());
  +
  +        String action = replace(getAction(), "${name}", encodedNodeName);
  +
           out.print("    <td>");
           if ((action != null) && !node.isLeaf()) {
               out.print("<a href=\"");
  @@ -444,7 +453,9 @@
               else if (!node.isSelected() && (styleUnselected != null))
                   labelStyle = styleUnselected;
               if (hyperlink != null) {
  -                out.print("<a href=\"");
  +                // Note the leading space so that the text has some space
  +                // between it and any preceding images
  +                out.print(" <a href=\"");
                   out.print(hyperlink);
                   out.print("\"");
                   String target = node.getTarget();
  
  
  
  1.2       +33 -9     
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTestAction.java
  
  Index: TreeControlTestAction.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTestAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TreeControlTestAction.java        2001/11/06 20:40:13     1.1
  +++ TreeControlTestAction.java        2001/11/27 02:46:28     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTestAction.java,v
 1.1 2001/11/06 20:40:13 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/11/06 20:40:13 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TreeControlTestAction.java,v
 1.2 2001/11/27 02:46:28 patrickl Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/11/27 02:46:28 $
    *
    * ====================================================================
    *
  @@ -67,6 +67,7 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Locale;
  +import java.net.URLDecoder;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  @@ -83,7 +84,7 @@
    * page.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/11/06 20:40:13 $
  + * @version $Revision: 1.2 $ $Date: 2001/11/27 02:46:28 $
    */
   
   public class TreeControlTestAction extends Action {
  @@ -112,24 +113,47 @@
                                    HttpServletRequest request,
                                    HttpServletResponse response)
           throws IOException, ServletException {
  +            
   
  +     getServlet().log("Entered TreeControlTestAction:perform()");
           String name = null;
  +     String encodedName = null;
           HttpSession session = request.getSession();
           TreeControl control =
               (TreeControl) session.getAttribute("treeControlTest");
   
           // Handle a tree expand/contract event
  -        name = request.getParameter("tree");
  -        if (name != null) {
  +        encodedName = request.getParameter("tree");
  +
  +        if (encodedName != null) {
  +
  +        // HACK to take into account special characters like = and &
  +        // in the node name, could remove this code if encode URL
  +        // and request.getParameter() could deal with = and &
  +        // character in parameter values. 
  +            name = URLDecoder.decode(encodedName);
  +
  +
               getServlet().log("Tree expand/contract on " + name);
               TreeControlNode node = control.findNode(name);
  -            if (node != null)
  +            if (node != null){
  +             getServlet().log("Found Node: " + name);
                   node.setExpanded(!node.isExpanded());
  -        }
  +         }
  +        }else{
  +            getServlet().log("tree param is null");
  +     }
   
           // Handle a select item event
  -        name = request.getParameter("select");
  -        if (name != null) {
  +        encodedName = request.getParameter("select");
  +        if (encodedName != null) {
  +
  +           // HACK to take into account special characters like = and &
  +           // in the node name, could remove this code if encode URL
  +           // and request.getParameter() could deal with = and &
  +           // character in parameter values. 
  +            name = URLDecoder.decode(encodedName);
  +
               getServlet().log("Select event on " + name);
               control.selectNode(name);
           }
  
  
  
  1.1                  
jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java
  
  Index: TomcatTreeBuilder.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/TomcatTreeBuilder.java,v
 1.1 2001/11/27 02:46:28 patrickl Exp $
   * $Revision: 1.1 $
   * $Date: 2001/11/27 02:46:28 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.webapp.admin;
  
  import java.io.IOException;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.net.URLEncoder;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionErrors;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.QueryExp;
  import javax.management.Query;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.JMException;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanInfo;
   
  /**
   * <p> Implementation of TreeBuilder interface for Tomcat Tree Controller 
   *     to build plugin components into the tree
   *
   * @author Jazmin Jonson
   * @version 
   */
  
  
  
  public class TomcatTreeBuilder implements TreeBuilder{
  
      // This SERVER_LABEL needs to be localized
      private final static String SERVER_LABEL = "Tomcat Server";
  
      private final static String SERVER_TYPE = "Catalina:type=Server";
      private final static String SERVICE_TYPE = "Catalina:type=Service";
      private final static String ENGINE_TYPE = "Engine";
      private final static String CONNECTOR_TYPE = "Catalina:type=Connector";
      private final static String WILDCARD = ",*";
  
      private static MBeanServer mBServer = null;
  
      public void buildTree(TreeControl treeControl,
                            ApplicationServlet servlet,
                            HttpServletRequest request) {
  
          try {
              mBServer = servlet.getServer();
              TreeControlNode root = treeControl.getRoot();
              TreeControlNode server = getServer();
              root.addChild(server);
              getServices(server);
          }catch(Throwable t){
              t.printStackTrace(System.out);
          } 
      }
  
      public TreeControlNode getServer() 
          throws JMException, ServletException {
  
          Iterator serverItr = 
              mBServer.queryMBeans(new ObjectName(SERVER_TYPE + WILDCARD),
                                   null).iterator();
        String serverObjName =
              (((ObjectInstance)serverItr.next()).getObjectName()).toString();
  
          // HACK to take into account special characters like = and &
          // in the node name, could remove this code if encode URL
          // and later request.getParameter() could deal with = and &
          // character in parameter values. Must decode name in users action.
          // TreeControlTest.java in this case
   
        String encodedServerName =  URLEncoder.encode(serverObjName);
          TreeControlNode serverNode =
              new TreeControlNode(serverObjName,
                                  "folder_16_pad.gif", SERVER_LABEL,
                                  "treeControlTest.do?select=" + encodedServerName,
                                  null, true);
  
          return serverNode;
  
      }
  
  
      public void getServices(TreeControlNode serverNode) 
          throws JMException, ServletException {
  
          Iterator serviceItr = 
              mBServer.queryMBeans(new ObjectName(SERVICE_TYPE + WILDCARD) , 
                                   null).iterator();
  
          String encodedServiceName;
  
          while(serviceItr.hasNext()){
              ObjectInstance service = (ObjectInstance)serviceItr.next();
  
              String serviceName = 
                  (String)mBServer.getAttribute(service.getObjectName(),"name");
  
              // HACK to take into account special characters like = and &
              // in the node name, could remove this code if encode URL
              // and later request.getParameter() could deal with = and &
              // character in parameter values. Must decode name in users action.
              // TreeControlTest.java in this case
              encodedServiceName =  
URLEncoder.encode(service.getObjectName().toString());
  
              TreeControlNode serviceNode = 
                  new TreeControlNode(service.getObjectName().toString(),
                                      "folder_16_pad.gif", 
                                      "Service(" + serviceName + ")",
                                      "treeControlTest.do?select=" + 
encodedServiceName,
                                      null, true);
  
              serverNode.addChild(serviceNode);
            
              getConnectors(serviceNode, serviceName);
          }
      }
  
      public void getConnectors(TreeControlNode serviceNode, 
                                String serviceName)
  
          throws JMException{
  
  
          Iterator ConnectorItr = 
              (mBServer.queryMBeans(new ObjectName(CONNECTOR_TYPE + WILDCARD +
                                                   ",service=" + serviceName),
                                    null)).iterator();
  
          TreeControlNode connectorNode = null;
          String encodedConnectorName;
  
          while(ConnectorItr.hasNext()){ 
  
              ObjectInstance connectorObj = (ObjectInstance)ConnectorItr.next();
  
              String connectorName = 
                  (String)mBServer.getAttribute(connectorObj.getObjectName(),
                                                "scheme");
  
              // HACK to take into account special characters like = and &
              // in the node name, could remove this code if encode URL
              // and later request.getParameter() could deal with = and &
              // character in parameter values. Must decode name in users action.
              // TreeControlTest.java in this case
              encodedConnectorName =  
URLEncoder.encode(connectorObj.getObjectName().toString());
  
              connectorNode = 
                  new TreeControlNode(connectorObj.getObjectName().toString(),
                                      "folder_16_pad.gif", 
                                      "Connector(" + connectorName + ")",
                                      "treeControlTest.do?select=" + 
                                      encodedConnectorName,
                                      null, true);
  
              serviceNode.addChild(connectorNode);
          }
        
      } 
  
  }                       
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to