gianugo     02/04/03 23:51:51

  Added:       java/scratchpad/src/org/apache/xindice/webdav WebDav.java
                        webdav.roles
  Log:
  Initial new Avalonized WebDav implementation checkin. Warning: this is just 
skeleton code, it does not do anything useful yet.
  
  Revision  Changes    Path
  1.1                  
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/WebDav.java
  
  Index: WebDav.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.xindice.webdav;
  
  import java.io.InputStream;
  import java.io.IOException;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.avalon.excalibur.component.DefaultRoleManager;
  import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
  import org.apache.avalon.excalibur.component.ExcaliburComponentSelector;
  
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentSelector;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.LogEnabled;
  
  import org.apache.log.Logger;
  import org.apache.log.Hierarchy;
  
  import org.apache.xindice.webdav.methods.DAVMethod;
  
  /** 
   *  This is the entry point for the Xindice WebDAV implementation.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a>
   * @version $Id: WebDav.java,v 1.1 2002/04/04 07:51:51 gianugo Exp $
   */
  
  public class WebDav 
          extends HttpServlet
          implements Component,
                     Composable,
                     Configurable,
                     Initializable,
                     Contextualizable {
  
    /** The application Context */                 
    private Context context;
  
    /** The Configuration file */
    private Configuration config;
  
    /** The ComponentManager */
    private ExcaliburComponentManager manager;
  
    /** The Log channel */
    private Logger logger;
  
    /** Empty constructor, as per Avalon specs */ 
    public WebDav() { }
  
  
    /** Contextualize this Contextualizable */
    public void contextualize(Context context)  {
      this.context = context;
    }  
  
    /** Compose this Composable. */
    public void compose(ComponentManager manager)  {
      if (manager instanceof ExcaliburComponentManager)
        this.manager = (ExcaliburComponentManager)manager;
    }  
  
    /** Configure the application */
    public void configure(Configuration config) {
      this.config = config;
    }  
  
    /** Initialize the application */
    public void initialize() {
      DefaultRoleManager drm = new DefaultRoleManager();
      try {
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  
        InputStream is = 
            
Thread.currentThread().getContextClassLoader().getResource("org/apache/xindice/webdav/webdav.roles").openStream();
  
        Configuration roleConfig = builder.build(is);
  
        drm.setLogger(this.getLogger());
        drm.configure(roleConfig);
        
        manager.setLogger(getLogger());
        manager.setRoleManager(drm);
        manager.configure(config);
      }  catch (Exception e) { 
        this.getLogger().error("Error initializing the application: ", e);
  
      }  
    }  
    
    /** Enable logging */
  
    public void enableLogging(Logger logger) {
      this.logger = logger;
    }  
  
    public Logger getLogger() {
      return logger;
    }  
  
    /** Initialize the servlet */
  
    public void init(ServletConfig servletConfig) throws
      ServletException {
  
      super.init(servletConfig);
  
      ServletContext servletContext = servletConfig.getServletContext();
      
      ExcaliburComponentManager manager = new ExcaliburComponentManager();
      DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
      try { 
        String webdavConf = 
this.getServletConfig().getInitParameter("configuration"); 
        Configuration webdavConfig = 
          builder.build(servletContext.getResource(webdavConf).openStream());
  
        Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor("webdav");
  
        this.enableLogging(logger);
        this.compose(manager);
        this.configure(webdavConfig);
        this.initialize();
  
      } catch (Exception e) { 
        throw new ServletException("Error initializing servlet", e);
      }  
  
    }  
  
    public void service(HttpServletRequest req, HttpServletResponse res)
      throws ServletException { 
  
      try { 
        ComponentSelector selector = (ComponentSelector) 
manager.lookup(DAVMethod.ROLE + "Selector");
  
        DAVMethod command = (DAVMethod)selector.select(req.getMethod());
  
        command.execute(req, res);
      }  catch (Exception e) { 
        e.printStackTrace(System.out);
      }  
  
    }  
  
  
    public static void main(String[] args) {
  
      if (args.length == 0) { 
        System.out.println("Usage: java WebDav [methods]");
        System.exit(1);  
      } 
  
      ExcaliburComponentManager manager = new ExcaliburComponentManager();
      WebDav webdav = new WebDav();
  
      DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  
      try { 
        Configuration webdavConfig = builder.buildFromFile("webdav.xconf");
  
        Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor("webdav");
  
        webdav.enableLogging(logger);
        webdav.compose(manager);
        webdav.configure(webdavConfig);
        webdav.initialize();
  
        ComponentSelector selector = (ComponentSelector) 
manager.lookup(DAVMethod.ROLE + "Selector");
  
        for (int i = 0; i < args.length; i++) { 
          DAVMethod command = (DAVMethod)selector.select(args[i]);
          System.out.println("Asking for hint: " + args[i] + 
            ", Got an instance of " + command.getClass().getName());
        } 
  
      } catch (Exception e) { 
        e.printStackTrace(System.err);
  
      }
    }
  
  }
  
  
  
  1.1                  
xml-xindice/java/scratchpad/src/org/apache/xindice/webdav/webdav.roles
  
  Index: webdav.roles
  ===================================================================
  <?xml version="1.0"?>
  
  <role-list>
    <role name="org.apache.xindice.webdav.methods.DAVMethodSelector"
          shorthand="methods"
          
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
 
      <hint shorthand="get" class="org.apache.xindice.webdav.methods.Get" />
      <hint shorthand="post" class="org.apache.xindice.webdav.methods.Post" />
      <hint shorthand="put" class="org.apache.xindice.webdav.methods.Put" />
      <hint shorthand="copy" class="org.apache.xindice.webdav.methods.Copy" />
      <hint shorthand="mkcol" class="org.apache.xindice.webdav.methods.Mkcol" />
      <hint shorthand="move" class="org.apache.xindice.webdav.methods.Move" />
      <hint shorthand="options" 
class="org.apache.xindice.webdav.methods.Options" />
      <hint shorthand="head" class="org.apache.xindice.webdav.methods.Head" />
      <hint shorthand="delete" class="org.apache.xindice.webdav.methods.Delete" 
/>
      <hint shorthand="trace" class="org.apache.xindice.webdav.methods.Trace" 
/> 
      <hint shorthand="propfind" 
class="org.apache.xindice.webdav.methods.Propfind" /> 
      <hint shorthand="proppatch" 
class="org.apache.xindice.webdav.methods.Proppatch" /> 
    </role>      
  </role-list>
  
  
  

Reply via email to