ozeigermann    2005/02/09 11:14:38

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        WebdavUtils.java
               src/conf/webapp web.xml
  Added:       src/webdav/server/org/apache/slide/webdav/util
                        PathMapper.java
  Log:
  Added means for a path mapper hook that allows to map the http request to 
random paths
  
  Revision  Changes    Path
  1.36      +37 -12    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WebdavUtils.java
  
  Index: WebdavUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/WebdavUtils.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- WebdavUtils.java  9 Feb 2005 19:11:56 -0000       1.35
  +++ WebdavUtils.java  9 Feb 2005 19:14:38 -0000       1.36
  @@ -314,22 +314,47 @@
           // get the requested path, depending on whether the servlet is mapped
           // as default servlet.
           String result = null;
  -        if (config.isDefaultServlet()) {
  -            result = req.getServletPath();
  -        } else {
  -            result = req.getRequestURI();
  -            result = result.substring(req.getContextPath().length()+ 
req.getServletPath().length());
  +    
  +        String pathMapperClassName = 
config.getInitParameter("path-mapper-hook");
  +        if (pathMapperClassName != null) {
  +            try {
  +                Class storeClass = Class.forName(pathMapperClassName);
  +                PathMapper mapper = (PathMapper) storeClass.newInstance();
  +                result = mapper.map(req, config);
  +            } catch (Exception e) {
  +                // XXX that's bad, but right here we have no way to react
  +                // appropriately
  +                // or at least issue a warning
  +            }
  +        }
  +    
  +        if (result == null) {
  +            PathMapper mapper = (PathMapper) 
config.getServletContext().getAttribute(
  +                    "org.apache.slide.webdav.util.PathMapper");
  +            if (mapper != null) {
  +                result = mapper.map(req, config);
  +            }
  +        }
  +        
  +        if (result == null) {
  +            if (config.isDefaultServlet()) {
  +                result = req.getServletPath();
  +            } else {
  +                result = req.getRequestURI();
  +                result = result.substring(req.getContextPath().length()+ 
req.getServletPath().length());
  +            }
           }
           
           // default to the namespace root if no path-info is specified
           if ((result == null) || (result.length() == 0)) {
               result = "/";
           }
  -        
  +    
           // prefix the URI with the configured scope
           result = config.getScope() + result;
  -
  -        return normalizeURL(fixTomcatURL(result));  // the request URL is 
utf-8 encoded
  +        result = normalizeURL(fixTomcatURL(result));  // the request URL is 
utf-8 encoded
  +        return result;
  +    
       }
   
       /**
  
  
  
  1.1                  
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PathMapper.java
  
  Index: PathMapper.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PathMapper.java,v
 1.1 2005/02/09 19:14:38 ozeigermann Exp $
   * $Revision: 1.1 $
   * $Date: 2005/02/09 19:14:38 $
   *
   * ====================================================================
   *
   * Copyright 2005 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  package org.apache.slide.webdav.util;
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.apache.slide.webdav.WebdavServletConfig;
  
  /**
   * Interface for a mapper hook from an HttpServletRequest to the path passed 
to the Slide core.
   * Is used by 
   * [EMAIL PROTECTED] 
org.apache.slide.webdav.util.WebdavUtils#getRelativePath(HttpServletRequest, 
WebdavServletConfig)}
   * and can either be configured in web.xml by setting its implementing class 
   * using initial parameter <em>path-mapper-hook</em>
   * or by setting attribute <em>org.apache.slide.webdav.util.PathMapper</em> 
in the servlet context
   * to an instance of this interface.<br>
   * <br>
   * This hook can also be used to pass information to the store level.
   * 
   * @see 
org.apache.slide.webdav.util.WebdavUtils#getRelativePath(HttpServletRequest, 
WebdavServletConfig)
   */
  public interface PathMapper {
  
      /**
       * Maps the request URI of a HTTP request to a path used in the core and 
store layer.
       * (this does not necessarily mean that a node exists at that URI).
       * 
       * @param req the request object
       * @param config configuration of the WebdavServlet
       *
       * @return the mapped request URI
       */
      String map(HttpServletRequest req, WebdavServletConfig config);
  }
  
  
  1.35      +10 -0     jakarta-slide/src/conf/webapp/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/conf/webapp/web.xml,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- web.xml   25 Jan 2005 10:42:20 -0000      1.34
  +++ web.xml   9 Feb 2005 19:14:38 -0000       1.35
  @@ -218,6 +218,16 @@
                   resource to be updated or not.
               </description>
           </init-param>
  +        <!--init-param>
  +            <param-name>path-mapper-hook</param-name>
  +            <param-value>mypackage.MyPathMapperHook</param-value>
  +            <description>
  +                You can configure a hook class that maps the 
HttpServletRequest
  +                to the path passed to the Slide core. Have a look at the 
mapper
  +                interface in org.apache.slide.webdav.util.PathMapper for more
  +                information.
  +            </description>
  +        </init-param-->
           <load-on-startup>1</load-on-startup>
           <!-- Uncomment this to get authentication -->
           <@[EMAIL PROTECTED]>
  
  
  

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

Reply via email to