You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/09/08 22:03:12 UTC

cvs commit: jakarta-slide/src/wrappers/catalina/conf/slide slide.conf slide.data slide.def

remm        01/09/08 13:03:12

  Modified:    src/wrappers/catalina SlideHost.java SlideRealm.java
                        WebdavHost.java server.xml
  Added:       src/wrappers/catalina SlideLogger.java
                        SlideServerListener.java
               src/wrappers/catalina/conf slide.xml
               src/wrappers/catalina/conf/slide slide.conf slide.data
                        slide.def
  Removed:     src/wrappers/catalina Domain.xml
  Log:
  - Version 2 of the Catalina integration.
  - The Domain.xml moves to the conf folder, and is renamed to slide.xml. This
    is configurable through the "configFile" attribute of the new SlideServerListeners.
  - Uses the new non-static embedded domain.
  - Initialization of the whole domain happens in a much more logical place
    (instead of being when one of the Hosts were started) :)
  - Configuration files can now be split using the new "ref" attribute. The classic
    static Domain doesn't support it yet.
  - Catalina logger integration: the namespace has a global logger (slide_domain), and
    each namespace has its own separate logger (slide_ns_'name'), and everything is
    now put in the "logs" directory.
  - Will add the manager host next.
  
  Revision  Changes    Path
  1.4       +51 -16    jakarta-slide/src/wrappers/catalina/SlideHost.java
  
  Index: SlideHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideHost.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SlideHost.java	2001/06/14 15:15:16	1.3
  +++ SlideHost.java	2001/09/08 20:03:12	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideHost.java,v 1.3 2001/06/14 15:15:16 remm Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/06/14 15:15:16 $
  + * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideHost.java,v 1.4 2001/09/08 20:03:12 remm Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/09/08 20:03:12 $
    *
    * ====================================================================
    *
  @@ -94,16 +94,19 @@
   import org.apache.catalina.Response;
   import org.apache.catalina.core.DefaultContext;
   import org.apache.catalina.core.StandardHost;
  +import org.apache.catalina.core.ApplicationContext;
   
   import wrappers.jndi.SlideDirContext;
   
  -import org.apache.slide.common.Domain;
  +import org.apache.slide.common.EmbeddedDomain;
  +import org.apache.slide.common.NamespaceAccessToken;
  +import org.apache.slide.webdav.WebdavServlet;
   
   /**
    * Slide implementation of Host.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.3 $ $Date: 2001/06/14 15:15:16 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/08 20:03:12 $
    */
   
   public class SlideHost
  @@ -127,9 +130,31 @@
       // ----------------------------------------------------- Instance Variables
   
   
  +    /**
  +     * Slide domain.
  +     */
  +    EmbeddedDomain domain;
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  +    /**
  +     * Domain setter.
  +     */
  +    public void setDomain(EmbeddedDomain domain) {
  +        this.domain = domain;
  +    }
  +
  +
  +    /**
  +     * Domain getter.
  +     */
  +    public EmbeddedDomain getDomain() {
  +        return domain;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -143,16 +168,9 @@
        */
       public synchronized void start() throws LifecycleException {
           
  -        try {
  -            File domainConfigFile = new File("Domain.xml");
  -            Domain.init(domainConfigFile.toURL());
  -        } catch (Exception e) {
  -            e.printStackTrace();
  -        }
  +        String defaultNamespace = domain.getDefaultNamespace();
           
  -        String defaultNamespace = Domain.getDefaultNamespace();
  -        
  -        Enumeration namespaceNames = Domain.enumerateNamespaces();
  +        Enumeration namespaceNames = domain.enumerateNamespaces();
           while (namespaceNames.hasMoreElements()) {
               String name = (String) namespaceNames.nextElement();
               try {
  @@ -200,20 +218,33 @@
   
           // Install this new web application
           try {
  +
               Class clazz = Class.forName(getContextClass());
               Context context = (Context) clazz.newInstance();
               context.setPath(contextPath);
               context.setDocBase(docBase);
  -            SlideRealm slideRealm = new SlideRealm();
  +
               String namespaceName = contextPath;
               while (namespaceName.startsWith("/")) {
                   namespaceName = namespaceName.substring(1);
               }
               if (namespaceName.equals("")) {
  -                namespaceName = Domain.getDefaultNamespace();
  +                namespaceName = domain.getDefaultNamespace();
               }
  +
  +            NamespaceAccessToken accessToken = 
  +                domain.getNamespaceToken(namespaceName);
  +
  +            SlideRealm slideRealm = new SlideRealm();
  +            slideRealm.setAccessToken(accessToken);
               slideRealm.setNamespace(namespaceName);
               context.setRealm(slideRealm);
  +
  +            context.getServletContext().setAttribute
  +                (WebdavServlet.ATTRIBUTE_NAME, accessToken);
  +            ((ApplicationContext) context.getServletContext())
  +                .setAttributeReadOnly(WebdavServlet.ATTRIBUTE_NAME);
  +
               if (context instanceof Lifecycle) {
                   clazz = Class.forName(getConfigClass());
                   LifecycleListener listener =
  @@ -221,10 +252,14 @@
                   ((Lifecycle) context).addLifecycleListener(listener);
               }
               addChild(context);
  +
               SlideDirContext resources = new SlideDirContext();
  +            resources.setAccessToken(accessToken);
               resources.setNamespaceName(war.getFile());
               context.setResources(resources);
  +
   	    fireContainerEvent(INSTALL_EVENT, context);
  +
           } catch (Exception e) {
               log(sm.getString("standardHost.installError", contextPath), e);
               throw new IOException(e.toString());
  
  
  
  1.7       +40 -31    jakarta-slide/src/wrappers/catalina/SlideRealm.java
  
  Index: SlideRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideRealm.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SlideRealm.java	2001/07/06 05:02:17	1.6
  +++ SlideRealm.java	2001/09/08 20:03:12	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideRealm.java,v 1.6 2001/07/06 05:02:17 remm Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/07/06 05:02:17 $
  + * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideRealm.java,v 1.7 2001/09/08 20:03:12 remm Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/09/08 20:03:12 $
    *
    * ====================================================================
    *
  @@ -69,11 +69,13 @@
   import java.util.Hashtable;
   import java.util.Vector;
   import org.apache.catalina.Container;
  +import org.apache.catalina.LifecycleException;
   import org.apache.catalina.Logger;
   import org.apache.catalina.Realm;
   import org.apache.catalina.realm.RealmBase;
   import org.apache.catalina.util.LifecycleSupport;
   import org.apache.catalina.util.StringManager;
  +
   import org.apache.slide.common.NamespaceAccessToken;
   import org.apache.slide.common.Domain;
   import org.apache.slide.common.SlideToken;
  @@ -97,7 +99,7 @@
    * to tomcat, webdav or default.
    * 
    * @author Remy Maucherat
  - * @version $Revision: 1.6 $ $Date: 2001/07/06 05:02:17 $
  + * @version $Revision: 1.7 $ $Date: 2001/09/08 20:03:12 $
    */
   
   public final class SlideRealm
  @@ -111,7 +113,7 @@
        * Descriptive information about this Realm implementation.
        */
       private static final String info =
  -	"org.apache.catalina.realm.SlideRealm/1.1";
  +	"wrappers.catalina.SlideRealm/1.2";
   
   
       /**
  @@ -154,38 +156,18 @@
   
   
       /**
  -     * Set the Container with which this Realm has been associated.
  -     *
  -     * @param container The associated Container
  +     * Set the namespace name to which this realm will connect.
        */
  -    public void setContainer(Container container) {
  -
  -        super.setContainer(container);
  -
  -        if (namespace == null)
  -            namespace = container.getName();
  -
  -        accessToken = Domain.accessNamespace
  -            (new SecurityToken(container), namespace);
  -
  -        if (accessToken == null)
  -            throw new IllegalStateException
  -                ("Invalid Slide Realm configuration : "
  -                 + "Couldn't access namespace " + namespace);
  -
  -        contentHelper = accessToken.getContentHelper();
  -        securityHelper = accessToken.getSecurityHelper();
  -
  -        usersPath = accessToken.getNamespaceConfig().getUsersPath();
  -
  +    public void setNamespace(String namespace) {
  +        this.namespace = namespace;
       }
   
   
       /**
  -     * Set the namespace name to which this realm will connect.
  +     * Set the namespace access token used by this realm.
        */
  -    public void setNamespace(String namespace) {
  -        this.namespace = namespace;
  +    public void setAccessToken(NamespaceAccessToken accessToken) {
  +        this.accessToken = accessToken;
       }
   
   
  @@ -217,6 +199,33 @@
           } catch (SlideException e) {
               return (false);
           }
  +
  +    }
  +
  +
  +    /**
  +     * Start the realm.
  +     */
  +    public void start() throws LifecycleException {
  +
  +        super.start();
  +
  +        if (namespace == null)
  +            namespace = container.getName();
  +
  +        if (accessToken == null)
  +            accessToken = Domain.accessNamespace
  +                (new SecurityToken(container), namespace);
  +
  +        if (accessToken == null)
  +            throw new IllegalStateException
  +                ("Invalid Slide Realm configuration : "
  +                 + "Couldn't access namespace " + namespace);
  +
  +        contentHelper = accessToken.getContentHelper();
  +        securityHelper = accessToken.getSecurityHelper();
  +
  +        usersPath = accessToken.getNamespaceConfig().getUsersPath();
   
       }
   
  
  
  
  1.3       +49 -16    jakarta-slide/src/wrappers/catalina/WebdavHost.java
  
  Index: WebdavHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/wrappers/catalina/WebdavHost.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WebdavHost.java	2001/06/13 17:44:31	1.2
  +++ WebdavHost.java	2001/09/08 20:03:12	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/WebdavHost.java,v 1.2 2001/06/13 17:44:31 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/06/13 17:44:31 $
  + * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/WebdavHost.java,v 1.3 2001/09/08 20:03:12 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/09/08 20:03:12 $
    *
    * ====================================================================
    *
  @@ -94,14 +94,17 @@
   import org.apache.catalina.Response;
   import org.apache.catalina.core.DefaultContext;
   import org.apache.catalina.core.StandardHost;
  +import org.apache.catalina.core.ApplicationContext;
   
  -import org.apache.slide.common.Domain;
  +import org.apache.slide.common.EmbeddedDomain;
  +import org.apache.slide.common.NamespaceAccessToken;
  +import org.apache.slide.webdav.WebdavServlet;
   
   /**
    * Slide Webdav implementation of Host.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.2 $ $Date: 2001/06/13 17:44:31 $
  + * @version $Revision: 1.3 $ $Date: 2001/09/08 20:03:12 $
    */
   
   public class WebdavHost
  @@ -125,9 +128,31 @@
       // ----------------------------------------------------- Instance Variables
   
   
  +    /**
  +     * Slide domain.
  +     */
  +    EmbeddedDomain domain;
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  +    /**
  +     * Domain setter.
  +     */
  +    public void setDomain(EmbeddedDomain domain) {
  +        this.domain = domain;
  +    }
  +
  +
  +    /**
  +     * Domain getter.
  +     */
  +    public EmbeddedDomain getDomain() {
  +        return domain;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -141,16 +166,9 @@
        */
       public synchronized void start() throws LifecycleException {
           
  -        try {
  -            File domainConfigFile = new File("Domain.xml");
  -            Domain.init(domainConfigFile.toURL());
  -        } catch (Exception e) {
  -            e.printStackTrace();
  -        }
  +        String defaultNamespace = domain.getDefaultNamespace();
           
  -        String defaultNamespace = Domain.getDefaultNamespace();
  -        
  -        Enumeration namespaceNames = Domain.enumerateNamespaces();
  +        Enumeration namespaceNames = domain.enumerateNamespaces();
           while (namespaceNames.hasMoreElements()) {
               String name = (String) namespaceNames.nextElement();
               try {
  @@ -251,20 +269,33 @@
           
           // Install this new web application
           try {
  +
               Class clazz = Class.forName(getContextClass());
               Context context = (Context) clazz.newInstance();
               context.setPath(contextPath);
               context.setDocBase(docBase);
  -            SlideRealm slideRealm = new SlideRealm();
  +
               String namespaceName = contextPath;
               while (namespaceName.startsWith("/")) {
                   namespaceName = namespaceName.substring(1);
               }
               if (namespaceName.equals("")) {
  -                namespaceName = Domain.getDefaultNamespace();
  +                namespaceName = domain.getDefaultNamespace();
               }
  +
  +            NamespaceAccessToken accessToken = 
  +                domain.getNamespaceToken(namespaceName);
  +
  +            SlideRealm slideRealm = new SlideRealm();
  +            slideRealm.setAccessToken(accessToken);
               slideRealm.setNamespace(namespaceName);
               context.setRealm(slideRealm);
  +
  +            context.getServletContext().setAttribute
  +                (WebdavServlet.ATTRIBUTE_NAME, accessToken);
  +            ((ApplicationContext) context.getServletContext())
  +                .setAttributeReadOnly(WebdavServlet.ATTRIBUTE_NAME);
  +
               if (context instanceof Lifecycle) {
                   clazz = Class.forName(getConfigClass());
                   LifecycleListener listener =
  @@ -272,7 +303,9 @@
                   ((Lifecycle) context).addLifecycleListener(listener);
               }
               addChild(context);
  +
   	    fireContainerEvent(INSTALL_EVENT, context);
  +
           } catch (Exception e) {
               log(sm.getString("standardHost.installError", contextPath), e);
               throw new IOException(e.toString());
  
  
  
  1.2       +3 -2      jakarta-slide/src/wrappers/catalina/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/wrappers/catalina/server.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- server.xml	2001/06/13 04:39:41	1.1
  +++ server.xml	2001/09/08 20:03:12	1.2
  @@ -1,8 +1,9 @@
   <Server port="8005" shutdown="SHUTDOWN" debug="0">
   
  +  <Listener className="wrappers.catalina.SlideServerListener" />
   
     <!-- Define the Tomcat Stand-Alone Service -->
  -  <Service name="Tomcat-Standalone">
  +  <Service name="Slide-Tomcat Standalone">
   
       <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
       <Connector className="org.apache.catalina.connector.http.HttpConnector"
  @@ -31,7 +32,7 @@
   
         <!-- Define the default virtual host -->
         <Host name="localhost" debug="0" appBase="webapps" unpackWARs="false"
  -       className="wrappers.catalina.SlideHost">
  +       configPath="slide" className="wrappers.catalina.SlideHost">
   
           <Realm className="org.apache.catalina.realm.MemoryRealm" />
   
  
  
  
  1.1                  jakarta-slide/src/wrappers/catalina/SlideLogger.java
  
  Index: SlideLogger.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideLogger.java,v 1.1 2001/09/08 20:03:12 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2001/09/08 20:03:12 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 apache@apache.org.
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package wrappers.catalina;
  
  import java.util.Date;
  import java.util.Locale;
  import java.text.SimpleDateFormat;
  
  import org.apache.catalina.Logger;
  
  /**
   * Simple logger implementation.
   *
   * @author Remy Maucherat
   */
  public class SlideLogger extends org.apache.slide.util.logger.SimpleLogger
      implements org.apache.slide.util.logger.Logger {
      
      
      // ----------------------------------------------------- Instance Variables
      
      
      /**
       * Catalina logger.
       */
      protected Logger logger;
      
      
      // ------------------------------------------------------------- Properties
      
      
      /**
       * Set Catalina logger.
       */
      public void setLogger(Logger logger) {
          this.logger = logger;
      }
  
  
      /**
       * Get Catalina logger.
       */
      public Logger getLogger() {
          return logger;
      }
      
      
      // --------------------------------------------------------- Logger Methods
      
      
      /**
       * Log an object thru the specified channel and with the specified level.
       *
       * @param data The object to log.
       * @param channel The channel name used for logging.
       * @param level The level used for logging.
       */
      public void log(Object data, String channel, int level) {
  
          if (isEnabled(channel, level)) {
  
              String levelValue = "";
              if (channel.equals(DEFAULT_CHANNEL))
                  channel = "";
              else
                  channel = channel + " - ";
              if ((level >= 0) && (level < loggingLevels.length))
                  levelValue = loggingLevels[level];
  
              String message = null;
              if (dateFormat == null) {
                  message = System.currentTimeMillis() + " - "
                      + channel + levelValue + " - " + data;
              } else {
                  message = dateFormat.format(new Date()) + " - "
                      + channel + levelValue + " - " + data;
              }
              
              if (data instanceof Throwable) {
                  logger.log(message, (Throwable) data);
              } else {
                  logger.log(message);
              }
  
          }
  
      }
      
      
  }
  
  
  
  1.1                  jakarta-slide/src/wrappers/catalina/SlideServerListener.java
  
  Index: SlideServerListener.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideServerListener.java,v 1.1 2001/09/08 20:03:12 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2001/09/08 20:03:12 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 apache@apache.org.
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package wrappers.catalina;
  
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStream;
  import java.io.IOException;
  import java.util.Enumeration;
  
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  import javax.xml.parsers.FactoryConfigurationError;
  import javax.xml.parsers.ParserConfigurationException;
  
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  
  import org.apache.catalina.Container;
  import org.apache.catalina.Host;
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleEvent;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.LifecycleListener;
  import org.apache.catalina.Server;
  import org.apache.catalina.Service;
  import org.apache.catalina.logger.FileLogger;
  
  import org.apache.slide.common.Domain;
  import org.apache.slide.common.EmbeddedDomain;
  import org.apache.slide.common.Namespace;
  import org.apache.slide.common.NamespaceAccessToken;
  import org.apache.slide.util.conf.Configuration;
  import org.apache.slide.util.conf.ConfigurationElement;
  import org.apache.slide.util.conf.ConfigurationException;
  import org.apache.slide.util.conf.Populate;
  import org.apache.slide.util.logger.SimpleLogger;
  
  /**
   * Server listener responsible for setting up the Slide domain.
   *
   * @author Remy Maucherat
   * @version $Revision: 1.1 $ $Date: 2001/09/08 20:03:12 $
   */
  public class SlideServerListener
      implements LifecycleListener {
  
  
      // -------------------------------------------------------------- Constants
  
  
      public static final String DEFAULT_CONFIG_FILE_NAME = "conf/slide.xml";
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Acknowledge the occurrence of the specified event.
       *
       * @param event LifecycleEvent that has occurred
       */
      public void lifecycleEvent(LifecycleEvent event) {
  
          try {
  
              server = (Server) event.getLifecycle();
  
              // Disable static domain
              Domain.setInitialized(true);
  
              // Create a Catalina logger for the Slide domain
              FileLogger catalinaLogger = new FileLogger();
              catalinaLogger.setDirectory("logs");
              catalinaLogger.setPrefix("slide_domain.");
              catalinaLogger.setSuffix(".txt");
              catalinaLogger.setTimestamp(false);
              catalinaLogger.start();
  
              SlideLogger logger = new SlideLogger();
              logger.setLogger(catalinaLogger);
              logger.setLoggerLevel(6);
              domain.setLogger(logger);
  
              if (event.getType() == Lifecycle.START_EVENT) {
                  setHosts();
                  System.out.println("Start Slide");
                  initializeDomain();
                  domain.start();
              } else if (event.getType() == Lifecycle.STOP_EVENT) {
                  System.out.println("Stop Slide");
                  domain.stop();
              }
  
          } catch (Throwable t) {
              t.printStackTrace();
          }
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Slide domain.
       */
      EmbeddedDomain domain = new EmbeddedDomain();
  
  
      /**
       * Associated server.
       */
      Server server;
  
  
      /**
       * Container logger.
       */
      SlideLogger logger;
  
  
      /**
       * Domain configuration file.
       */
      String configFileName = DEFAULT_CONFIG_FILE_NAME;
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * Configuration file name setter.
       */
      public void setConfigFileName(String configFileName) {
          this.configFileName = configFileName;
      }
  
  
      /**
       * Configuration file name getter.
       */
      public String getConfigFileName() {
          return configFileName;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Get configuration object from a file.
       */
      protected Configuration getConfiguration(File file)
          throws IOException, SAXException, ParserConfigurationException, 
          FactoryConfigurationError {
  
          // Get XML parser
          SAXParserFactory factory = SAXParserFactory.newInstance();
          factory.setNamespaceAware(false);
          factory.setValidating(false);
          SAXParser parser = factory.newSAXParser();
  
          // Parse XML file
          FileInputStream is = new FileInputStream(file);
          Populate pop = new Populate();
          return new ConfigurationElement(pop.load(new InputSource(is),
                                                   parser.getXMLReader()));
  
      }
  
  
      /**
       * Setup domain.
       */
      protected void initializeDomain()
          throws IOException, SAXException, FactoryConfigurationError, 
          ParserConfigurationException {
  
          File domainConfigFile = new File(configFileName);
          if (!domainConfigFile.isAbsolute()) {
              domainConfigFile = new File(System.getProperty("catalina.home"), 
                                          configFileName);
          }
  
          Configuration slideConfiguration = getConfiguration(domainConfigFile);
  
          domain.setDefaultNamespace(slideConfiguration.getAttribute
                                     ("default", "slide"));
  
          Enumeration namespaceDefinitions =
              slideConfiguration.getConfigurations("namespace");
  
          while (namespaceDefinitions.hasMoreElements()) {
              loadNamespace(domainConfigFile.getParentFile(),
                            (Configuration) namespaceDefinitions.nextElement());
          }
  
      }
  
  
      /**
       * Load namespace.
       */
      protected void loadNamespace(File path, Configuration xmlFragment)
          throws IOException, SAXException, FactoryConfigurationError,
          ParserConfigurationException {
  
          String name = xmlFragment.getAttribute("name");
  
          Configuration definition = xmlFragment.getConfiguration("definition");
          Configuration configuration = 
              xmlFragment.getConfiguration("configuration");
          Configuration baseData = xmlFragment.getConfiguration("data");
  
          String defRef = definition.getAttribute("ref", "");
          if (!defRef.equals("")) {
              definition = getConfiguration(new File(path, defRef))
                  .getConfiguration("definition");
          }
          String confRef = configuration.getAttribute("ref", "");
          if (!confRef.equals("")) {
              configuration = getConfiguration(new File(path, confRef))
                  .getConfiguration("configuration");
          }
          String baseDataRef = baseData.getAttribute("ref", "");
          if (!baseDataRef.equals("")) {
              baseData = getConfiguration(new File(path, baseDataRef))
                  .getConfiguration("data");
          }
  
          // Create a Catalina logger for the Slide domain
          FileLogger catalinaLogger = new FileLogger();
          catalinaLogger.setDirectory("logs");
          catalinaLogger.setPrefix("slide_ns_" + name + ".");
          catalinaLogger.setSuffix(".txt");
          catalinaLogger.setTimestamp(false);
          try {
              catalinaLogger.start();
          } catch (LifecycleException e) {
              // Never happens
              e.printStackTrace();
          }
  
          SlideLogger nsLogger = new SlideLogger();
          nsLogger.setLogger(catalinaLogger);
          nsLogger.setLoggerLevel(6); // FIXME
  
          domain.addNamespace(name, nsLogger, definition, 
                              configuration, baseData);
  
      }
  
  
      /**
       * Associate the hosts with the embedded domain.
       */
      protected void setHosts() {
  
          Service[] services = server.findServices();
          for (int i = 0; i < services.length; i++) {
  
              Container container = services[i].getContainer();
              Container[] children = container.findChildren();
  
              for (int j = 0; j < children.length; j++) {
  
                  Host host = (Host) children[j];
  
                  if (host instanceof SlideHost) {
                      System.out.println("Set domain for Slide host");
                      ((SlideHost) host).setDomain(domain);
                  } else if (host instanceof WebdavHost) {
                      System.out.println("Set domain for Webdav host");
                      ((WebdavHost) host).setDomain(domain);
                  }/* else if (host instanceof SlideManagerHost) {
                      ((SlideManagerHost) host).setDomain(domain);
                      }*/
  
              }
  
          }
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-slide/src/wrappers/catalina/conf/slide.xml
  
  Index: slide.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <slide default="slide">
  
    <namespace name="slide">
       <definition ref="slide/slide.def" />
       <configuration ref="slide/slide.conf" />
       <data ref="slide/slide.data" />
    </namespace>
  
  </slide>
  
  
  1.1                  jakarta-slide/src/wrappers/catalina/conf/slide/slide.conf
  
  Index: slide.conf
  ===================================================================
  <?xml version="1.0"?>
  
  <namespace>
  
    <configuration>
  
      <!-- Actions mapping -->
      <default-action>/actions</default-action>
      <read-object>/actions/read</read-object>
      <create-object>/actions/write</create-object>
      <remove-object>/actions/write</remove-object>
      <grant-permission>/actions/manage</grant-permission>
      <revoke-permission>/actions/manage</revoke-permission>
      <read-permissions>/actions/manage</read-permissions>
      <lock-object>/actions/write</lock-object>
      <kill-lock>/actions/manage</kill-lock>
      <read-locks>/actions/read</read-locks>
      <read-revision-metadata>/actions/read</read-revision-metadata>
      <create-revision-metadata>/actions/write</create-revision-metadata>
      <modify-revision-metadata>/actions/write</modify-revision-metadata>
      <remove-revision-metadata>/actions/write</remove-revision-metadata>
      <read-revision-content>/actions/read</read-revision-content>
      <create-revision-content>/actions/write</create-revision-content>
      <modify-revision-content>/actions/write</modify-revision-content>
      <remove-revision-content>/actions/write</remove-revision-content>
  
      <!-- Paths configuration -->
      <userspath>/users</userspath>
      <guestpath>guest</guestpath>
      <filespath>/files</filespath>
      <parameter name="dav">true</parameter>
      <parameter name="standalone">true</parameter>
  
      <!-- Roles definition -->
      <role name="root">slideroles.basic.RootRole</role>
      <role name="user">slideroles.basic.UserRole</role>
      <role name="guest">slideroles.basic.GuestRole</role>
  
      <!-- Users management -->
      <auto-create-users>false</auto-create-users>
  
      <!-- Default properties mapping -->
      <default-property name="foo" namespace="nsfoo/" value="bar"
       role="user"/>
      <default-property name="password" namespace="slide/" value=""
       role="user"/>
  
    </configuration>
  
  </namespace>
  
  
  
  1.1                  jakarta-slide/src/wrappers/catalina/conf/slide/slide.data
  
  Index: slide.data
  ===================================================================
  <?xml version="1.0"?>
  
  <namespace>
  
    <data>
        
      <objectnode classname="org.apache.slide.structure.SubjectNode" uri="/">
          
        <permission action="/actions" subject="root"/>
        <permission action="/actions/read" subject="user"
         inheritable="false"/>
        <permission action="/actions/read" subject="nobody"
         inheritable="false"/>
          
        <!-- /users represents the unauthenticated user -->
          
        <objectnode classname="org.apache.slide.structure.SubjectNode" 
         uri="/users">
            
          <permission action="/actions" subject="~"/>
          <permission action="/actions" subject="guest"
           inheritable="true" negative="true"/>
          <permission action="/actions/read" subject="user"
           inheritable="false"/>
  
          <!-- Permission group example -->
            
          <objectnode classname="org.apache.slide.structure.GroupNode" 
            uri="/users/groupA">
             <objectnode classname="org.apache.slide.structure.LinkNode" 
                uri="/users/groupA/john" linkedUri="/users/john" />
             <objectnode classname="org.apache.slide.structure.LinkNode" 
                uri="/users/groupA/root" linkedUri="/users/root" />
             <objectnode classname="org.apache.slide.structure.SubjectNode" 
               uri="/users/groupA/singleGroupMember"  />
          </objectnode>
  
          <!-- /users/root represents the administrator -->
            
          <objectnode classname="slideroles.basic.RootRoleImpl" 
           uri="/users/root">
            <!-- Uncomment and change the password to allow login as root to
             edit the namespace -->
            <!--revision>
              <property name="password" 
               namespace="http://jakarta.apache.org/slide/">root</property>
            </revision-->
          </objectnode>
            
          <!-- /users/john represents an authenticated user -->
            
          <objectnode classname="slideroles.basic.UserRoleImpl" 
           uri="/users/john" />
            
          <!-- /users/guest represents an authenticated or unauthenticated 
               guest user -->
            
          <objectnode classname="slideroles.basic.GuestRoleImpl" 
           uri="/users/guest" />
            
        </objectnode>
          
        <objectnode classname="org.apache.slide.structure.ActionNode" 
         uri="/actions">
            
          <objectnode classname="org.apache.slide.structure.ActionNode" 
           uri="/actions/read"/>
            
          <objectnode classname="org.apache.slide.structure.ActionNode" 
           uri="/actions/write"/>
            
          <objectnode classname="org.apache.slide.structure.ActionNode" 
           uri="/actions/manage"/>
            
        </objectnode>
          
        <objectnode classname="org.apache.slide.structure.SubjectNode" 
         uri="/files">
  
          <!-- ### Give read/write/manage permission to guest ### 
               Uncomment the following line to give permission to do
               all actions on /files to guest (unauthenticated users) -->
          <!-- <permission action="/actions" subject="/users/guest"/> -->
  
          <permission action="/actions/manage" subject="/users/john"/>
          <permission action="/actions/write" subject="+/users/groupA"/>
          <permission action="/actions/read" subject="nobody"/>
            
        </objectnode>
          
      </objectnode>
        
    </data>
      
  </namespace>
  
  
  
  1.1                  jakarta-slide/src/wrappers/catalina/conf/slide/slide.def
  
  Index: slide.def
  ===================================================================
  <?xml version="1.0"?>
  
  <namespace>
  
  <!-- ### JDBC Configuration ###
       The following jdbc sample configuration uses the hsql Database Engine
       a relational database engine written in Java, for more info: 
       http://hsqldb.sourceforge.net/ 
  -->
    <definition>
      <store name="jdbc">
        <nodestore classname="slidestore.reference.JDBCDescriptorsStore">
         <parameter name="driver">org.hsqldb.jdbcDriver</parameter>
         <parameter name="url">jdbc:hsqldb:slidestructure</parameter>
         <parameter name="user">sa</parameter>
         <parameter name="password"></parameter>
        </nodestore>
        <securitystore>
          <reference store="nodestore" />
        </securitystore>
        <lockstore>
          <reference store="nodestore" />
        </lockstore>
        <revisiondescriptorsstore>
          <reference store="nodestore" />
        </revisiondescriptorsstore>
        <revisiondescriptorstore>
          <reference store="nodestore" />
        </revisiondescriptorstore>
        <contentstore classname="slidestore.reference.FileContentStore">
          <parameter name="rootpath">contentstore</parameter>
          <parameter name="version">true</parameter>
          <parameter name="resetBeforeStarting">false</parameter>
        </contentstore>
      </store>
      <scope match="/" store="jdbc" />
      <logger classname="org.apache.slide.util.logger.SimpleLogger" 
       logger-level="6" />
    </definition>
  
  </namespace>