xml-xang-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdier...@locus.apache.org
Subject cvs commit: xml-xang/java/src/org/apache/xang/util ServletUtil.java
Date Thu, 25 May 2000 19:54:28 GMT
mdierken    00/05/25 12:54:28

  Added:       java/src/org/apache/xang/util ServletUtil.java
  Log:
  Utilities to deal with different servlet engine implementations.
  
  Revision  Changes    Path
  1.1                  xml-xang/java/src/org/apache/xang/util/ServletUtil.java
  
  Index: ServletUtil.java
  ===================================================================
  package org.apache.xang.util;
  
  import javax.servlet.*;
  import org.apache.xang.net.http.object.*;
  
  public class ServletUtil
  {
      /** This will get the location of the file which the servlet is handling.
       */
      public static String getRealPath(IHTTPContext context)
      {
          String path;
          String realPath=null;
  
          path = context.getRequest().getServletPath();
          
          // detect odd Servlet API behavior
          if (null == context.getServletContext().getRealPath(path))
          {
              int pos;
              // We'll have to parse stuff out.
              path = context.getRequest().getPathInfo();
              path = context.getRequest().getRealPath(path);
              if (path != null)
              {
                  pos = path.indexOf(".");
                  if (pos >= 0)
                  {
                      while (pos < path.length() &&
                             path.charAt(pos) != '/' &&
                             path.charAt(pos) != '\\')
                      {
                          pos++;
                      }
                      realPath = path.substring(0,pos);
                  }
              }
          }
          else
          {
              // let the API do it.
              realPath = context.getServletContext().getRealPath(path);
          }
  
          return realPath;
      }
  
      /** This will get the location of the file which the servlet is handling.
       */
      public static String getPathInfo(IHTTPContext context)
      {
          String path;
          String realPath=null;
  
          path = context.getRequest().getServletPath();
          
          // detect odd Servlet API behavior
          if (null == context.getServletContext().getRealPath(path))
          {
              int pos;
              // We'll have to parse stuff out.
              path = context.getRequest().getPathInfo();
              if (path != null)
              {
                  pos = path.indexOf(".");
                  if (pos >= 0)
                  {
                      while (pos < path.length() &&
                             path.charAt(pos) != '/' &&
                             path.charAt(pos) != '\\')
                      {
                          pos++;
                      }
                      realPath = path.substring(pos);
                  }
              }
          }
          else
          {
              // let the API do it.
              realPath = context.getRequest().getPathInfo();
          }
  
          return realPath;
      }
  }
  
  
  
  

Mime
View raw message