You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2004/08/16 15:25:31 UTC

cvs commit: jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver AbstractContentLocator.java ContentLocatingResponseWrapper.java ContentLocatingRequestWrapper.java SimpleContentLocator.java ContentLocator.java ContentFilter.java

weaver      2004/08/16 06:25:31

  Modified:    content-server/src/java/org/apache/jetspeed/contentserver
                        SimpleContentLocator.java ContentLocator.java
                        ContentFilter.java
  Added:       content-server/src/java/org/apache/jetspeed/contentserver
                        AbstractContentLocator.java
                        ContentLocatingResponseWrapper.java
                        ContentLocatingRequestWrapper.java
  Log:
  Refactored content filter.  Added raw content caching.  Added cache switch to the filter init-params.
  
  Revision  Changes    Path
  1.6       +77 -136   jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java
  
  Index: SimpleContentLocator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleContentLocator.java	27 Jul 2004 13:42:13 -0000	1.5
  +++ SimpleContentLocator.java	16 Aug 2004 13:25:30 -0000	1.6
  @@ -15,17 +15,8 @@
    */
   package org.apache.jetspeed.contentserver;
   
  -import java.io.BufferedInputStream;
   import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.util.HashMap;
   import java.util.List;
  -import java.util.Map;
  -
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * <p>
  @@ -36,153 +27,103 @@
    * @version $Id$
    *  
    */
  -public class SimpleContentLocator implements ContentLocator
  +public class SimpleContentLocator extends AbstractContentLocator implements ContentLocator
   {
  -
  -    private String rootPath;
  -
  -    private boolean useCachedLookup;
  -
  -    private Map fileCache;
  -
  -    private String[] URLHints;
  -
  -    private static final Log log = LogFactory.getLog(SimpleContentLocator.class);
  -
  -    private String contextRoot;
  -
  -    public SimpleContentLocator( String rootPath, String[] URLHints, boolean useCachedLookup, String contextRoot )
  -    {
  -        this.contextRoot = contextRoot;
  -        this.rootPath = rootPath;
  -        this.useCachedLookup = useCachedLookup;
  -        fileCache = new HashMap();
  -        this.URLHints = URLHints;
  -    }
  -
  -    public long mergeContent( String URI, List lookupPathes, OutputStream os )
  +    
  +    protected String realPath;
  +    
  +    /**
  +     * @param rootPath
  +     * @param URLHints
  +     * @param useCachedLookup
  +     * @param contextRoot
  +     * @param URI
  +     * @param lookupPathes
  +     */
  +    public SimpleContentLocator( String rootPath, String[] URLHints, boolean useCachedLookup, String contextRoot, String URI, List lookupPathes )
       {
  - 
  -        File content = locateContent(URI, lookupPathes);
  -        if (content != null)
  -        {
  -            return setContent(content, os);
  -        }
  -        else
  -        {
  -            return -1;
  -        }
  -    }
  +        super(rootPath, URLHints, useCachedLookup, contextRoot, URI, lookupPathes);
  +    }  
   
  -    protected File locateContent( String URI, List lookupPathes )
  +    /**
  +     * <p>
  +     * getRealPath
  +     * </p>
  +     * 
  +     * @see org.apache.jetspeed.contentserver.ContentLocator#getRealPath()
  +     * @return
  +     */
  +    public String getRealPath()
       {
  -        for (int j = 0; j < URLHints.length; j++)
  +        if (realPath == null)
           {
  -            String URLHint = URLHints[j];
  -            int rootLen = URLHint.length();
  -            // int rootStart = URI.indexOf(URLHint);
  -            int rootStart = URI.lastIndexOf(URLHint);
  -            File fqFile = null;
  -            if (rootStart != -1)
  -            {   
  -                String dir = null;
  -                if(rootLen > 1)                
  -                {
  -                   dir = URI.substring(rootStart + rootLen);
  -                }
  -                else
  -                {
  -                    dir = URI.substring(contextRoot.length());
  -                    
  -                }
  -
  -                for (int i = 0; i < lookupPathes.size(); i++)
  +            for (int j = 0; j < URLHints.length; j++)
  +            {
  +                String URLHint = URLHints[j];
  +                int rootLen = URLHint.length();
  +                // int rootStart = URI.indexOf(URLHint);
  +                int rootStart = URI.lastIndexOf(URLHint);
  +                File fqFile = null;
  +                if (rootStart != -1)
                   {
  -
  -                    if (useCachedLookup && fileCache.containsKey(lookupPathes.get(i) + ":" + URI))
  +                    String dir = null;
  +                    if (rootLen > 1)
                       {
  -                        fqFile = (File) fileCache.get(lookupPathes.get(i) + ":" + URI);
  -                        log.debug("Found cached file for URI: " + URI);
  -                        return fqFile;
  +                        dir = URI.substring(rootStart + rootLen);
                       }
                       else
                       {
  -                        // String fqPath = pathes.get(i) + "/html" + dir;
  -                        String[] sep = new String[]{"", ""};
  +                        dir = URI.substring(contextRoot.length());
   
  -                        if (lookupPathes.get(i).toString().trim().length() > 1)
  -                        {
  -                            sep[0] = "/";
  -                        }
  -
  -                        if (!dir.startsWith("/"))
  -                        {
  -                            sep[1] = "/";
  -                        }
  +                    }
   
  -                        String fqPath = this.rootPath + sep[0] + lookupPathes.get(i) + sep[1] + dir;
  +                    for (int i = 0; i < lookupPathes.size(); i++)
  +                    {
   
  -                        fqFile = new File(fqPath);
  -                        log.debug("Actual content located at: " + fqPath);
  -                        log.debug("Content exists? " + fqFile.exists());
  -                        if (!fqFile.exists())
  +                        if (useCachedLookup && fileCache.containsKey(lookupPathes.get(i) + ":" + URI))
                           {
  -                            fqFile = null;
  -                            continue;
  +                            realPath = (String) fileCache.get(lookupPathes.get(i) + ":" + URI);
  +                            log.debug("Found cached file for URI: " + URI);
  +                            return realPath;
                           }
  -
  -                        if (useCachedLookup)
  +                        else
                           {
  -                            fileCache.put(lookupPathes.get(i) + ":" + URI, fqFile);
  +                            // String fqPath = pathes.get(i) + "/html" + dir;
  +                            String[] sep = new String[]{"", ""};
  +
  +                            if (lookupPathes.get(i).toString().trim().length() > 1)
  +                            {
  +                                sep[0] = "/";
  +                            }
  +
  +                            if (!dir.startsWith("/"))
  +                            {
  +                                sep[1] = "/";
  +                            }
  +
  +                            String fqPath = this.rootPath + sep[0] + lookupPathes.get(i) + sep[1] + dir;
  +
  +                            fqFile = new File(fqPath);
  +                            log.debug("Actual content located at: " + fqPath);
  +                            log.debug("Content exists? " + fqFile.exists());
  +                            if (!fqFile.exists())
  +                            {
  +                                fqFile = null;
  +                                continue;
  +                            }
  +
  +                            if (useCachedLookup)
  +                            {
  +                                fileCache.put(lookupPathes.get(i) + ":" + URI, fqPath);
  +                            }
  +                            realPath = fqPath;
  +                            return realPath;
                           }
  -                        return fqFile;
                       }
                   }
               }
           }
   
  -        return null;
  -
  +        return realPath;
       }
  -
  -    protected long setContent( File fqFile, OutputStream os )
  -    {
  -        BufferedInputStream bis = null;
  -        try
  -        {
  -            // DST: TODO: optimize using larger blocks with Streams helper
  -            // utility
  -            bis = new BufferedInputStream(new FileInputStream(fqFile));
  -            for (int j = bis.read(); j != -1; j = bis.read())
  -            {
  -                os.write((byte) j);
  -            }
  -            log.debug("Wrote " + fqFile.length() + " to the output stream.");
  -
  -            return fqFile.length();
  -
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            return -1;
  -        }
  -        finally
  -        {
  -            try
  -            {
  -                if (bis != null)
  -                {
  -                    bis.close();
  -                }
  -            }
  -            catch (IOException e1)
  -            {
  -                // ignore
  -
  -            }
  -        }
  -
  -    }
  -
   }
  
  
  
  1.5       +13 -16    jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java
  
  Index: ContentLocator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContentLocator.java	8 May 2004 01:14:25 -0000	1.4
  +++ ContentLocator.java	16 Aug 2004 13:25:30 -0000	1.5
  @@ -15,8 +15,9 @@
    */
   package org.apache.jetspeed.contentserver;
   
  +import java.io.IOException;
  +import java.io.InputStream;
   import java.io.OutputStream;
  -import java.util.List;
   
   
   /**
  @@ -30,18 +31,14 @@
    */
   public interface ContentLocator
   {
  -    /**
  -     * 
  -     * <p>
  -     *  mergeContent
  -     * </p>
  -     * <p>
  -     *  Merges the content that is located in the provided <code>URI</code>     * 
  -     * </p>
  -     * @param URI Content to locate
  -     * @param os OutputStream to write the content to.
  -     * @return int the length of actual content in bytes or -1
  -     * if the <code>URI</code> was not found.
  -     */
  -    long mergeContent(String URI, List lookupPathes, OutputStream os);
  +
  +    OutputStream getOutputStream() throws IOException;
  +    
  +    InputStream getInputStream() throws IOException;
  +    
  +    String getRealPath();
  +    
  +    long writeToOutputStream(OutputStream stream) throws IOException;
  +    
  +    String getBasePath();
   }
  
  
  
  1.11      +59 -42    jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
  
  Index: ContentFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ContentFilter.java	1 Aug 2004 15:41:04 -0000	1.10
  +++ ContentFilter.java	16 Aug 2004 13:25:30 -0000	1.11
  @@ -16,6 +16,7 @@
   package org.apache.jetspeed.contentserver;
   
   import java.io.File;
  +import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.List;
  @@ -57,12 +58,14 @@
   
       private String urlHint;
   
  +    protected String[] urlHints;
   
  +    protected boolean useCache;
   
       /**
        * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
        */
  -    public void init(FilterConfig config) throws ServletException
  +    public void init( FilterConfig config ) throws ServletException
       {
           this.config = config;
           String dir = config.getInitParameter("content.directory");
  @@ -70,11 +73,30 @@
           this.contentDir = config.getServletContext().getRealPath(dir);
           // this.themesDir = this.contentDir + "/themes";
           this.contentDirFile = new File(this.contentDir);
  +        
  +        StringTokenizer hintTokenizer = new StringTokenizer(urlHint, ",");
  +        urlHints = new String[hintTokenizer.countTokens()];
  +        int i = 0;
  +        while (hintTokenizer.hasMoreTokens())
  +        {
  +            urlHints[i] = hintTokenizer.nextToken();
  +            i++;
  +        }
  +        
  +        String useCacheParam = config.getInitParameter("use.caching");
  +        if(useCacheParam == null)
  +        {
  +            useCache = true;
  +        }
  +        else
  +        {
  +            useCache = Boolean.valueOf(useCacheParam).booleanValue();
  +        }
  +        
           if (!contentDirFile.exists())
           {
  -            throw new ServletException(
  -            "The specified content directory "
  -            + contentDirFile.getAbsolutePath() + " does not exist!");
  +            throw new ServletException("The specified content directory " + contentDirFile.getAbsolutePath()
  +                    + " does not exist!");
           }
       }
   
  @@ -82,51 +104,46 @@
        * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
        *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
        */
  -    public void doFilter(ServletRequest request, ServletResponse response, 
  -    FilterChain chain) throws IOException, ServletException
  +    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException,
  +            ServletException
       {
           if (request instanceof HttpServletRequest)
           {
               HttpServletRequest httpRequest = (HttpServletRequest) request;
               HttpServletResponse httpResponse = (HttpServletResponse) response;
               String requestURI = httpRequest.getRequestURI();
  -            String mimeType = config.getServletContext().getMimeType(requestURI);
  -            if (mimeType == null)
  -            {
  -                throw new NullPointerException(
  -                        "MIME-TYPE for "
  -                                + requestURI
  -                                + " could not be located.  Make sure your container is properly configured to detect MIME types.");
  -            }
  -            log.debug(mimeType + " detected: " + requestURI);
  -            StringTokenizer hintTokenizer = new StringTokenizer(urlHint, ",");
  -            String[] urlHints = new String[hintTokenizer.countTokens()];
  -            int i = 0;
  -            while(hintTokenizer.hasMoreTokens())
  +            
  +            SimpleContentLocator contentLocator = new SimpleContentLocator(this.contentDir, urlHints, useCache, httpRequest
  +                    .getContextPath(), requestURI, getContentSearchPathes(httpRequest));
  +
  +            ContentLocatingResponseWrapper respWrapper = new ContentLocatingResponseWrapper(httpResponse,
  +                    contentLocator);
  +            
  +            ContentLocatingRequestWrapper reqWrapper = new ContentLocatingRequestWrapper(httpRequest,
  +                    contentLocator);
  +            httpRequest.setAttribute("org.apache.jetspeed.content.filtered", "true");
  +            chain.doFilter(reqWrapper, respWrapper);
  +            if(!respWrapper.wasLocationAttempted() && !respWrapper.outputStreamCalled && !respWrapper.writerCalled)
               {
  -                urlHints[i]=hintTokenizer.nextToken();
  -                i++;
  -            }
  -            SimpleContentLocator contentLocator = new SimpleContentLocator(
  -                    this.contentDir, urlHints, true, httpRequest.getContextPath());
  -            long contentLength = contentLocator.mergeContent(requestURI,
  -                    getContentSearchPathes(httpRequest), response
  -                            .getOutputStream());
  -            if (contentLength > -1)
  -            {
  -                response.setContentType(mimeType);
  -                response.setContentLength((int) contentLength);
  -                log.debug("Setting status to OK");
  -                httpResponse.setStatus(HttpServletResponse.SC_OK);
  -            } else
  -            {
  -               // chain.doFilter(request, response);
  -                httpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
  +                try
  +                {                   
  +                    httpResponse.setContentLength((int) contentLocator.writeToOutputStream(httpResponse.getOutputStream()));
  +                    httpResponse.setStatus(HttpServletResponse.SC_OK);
  +                }
  +                catch (FileNotFoundException e)
  +                {
  +                    httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
  +                }
  +               
                   
               }
  -            return;
  +
           }
  -        chain.doFilter(request, response);
  +        else
  +        {
  +            chain.doFilter(request, response);
  +        }
  +
       }
   
       /**
  @@ -136,7 +153,7 @@
       {
       }
   
  -    protected List getContentSearchPathes(HttpServletRequest request)
  +    protected List getContentSearchPathes( HttpServletRequest request )
       {
           List contentPathes = (List) request.getSession().getAttribute(SESSION_CONTENT_PATH_ATTR);
           if (contentPathes == null)
  @@ -147,4 +164,4 @@
           }
           return contentPathes;
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/AbstractContentLocator.java
  
  Index: AbstractContentLocator.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 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.jetspeed.contentserver;
  
  import java.io.BufferedInputStream;
  import java.io.BufferedOutputStream;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * <p>
   * AbstractContentLocator
   * </p>
   * <p>
   * 
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
   * @version $Id: AbstractContentLocator.java,v 1.1 2004/08/16 13:25:30 weaver Exp $
   *  
   */
  public abstract class AbstractContentLocator implements ContentLocator
  {
  
      protected String rootPath;
      protected boolean useCachedLookup;
      protected static final Map fileCache = new HashMap();
      protected static final Map contentCache = new HashMap();
      protected String[] URLHints;
      protected static final Log log = LogFactory.getLog(SimpleContentLocator.class);
      protected String contextRoot;
      protected String URI;
      protected List lookupPathes;
      private String basePath;
  
      public AbstractContentLocator( String rootPath, String[] URLHints, boolean useCachedLookup, String contextRoot,
              String URI, List lookupPathes )
      {
          this.contextRoot = contextRoot;
          this.rootPath = rootPath;
          this.useCachedLookup = useCachedLookup;
          this.URLHints = URLHints;
          this.URI = URI;
          this.lookupPathes = lookupPathes;
      }
  
      public OutputStream getOutputStream() throws IOException
      {
          File content = new File(getRealPath());
          BufferedOutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream((int) content.length()));
          writeToOutputStream(bos);
          return bos;
      }
  
      public long writeToOutputStream( OutputStream stream ) throws IOException
      {
  
          InputStream is = getInputStream();
  
          if (is != null)
          {
              try
              {
                  // DST: TODO: optimize using larger blocks with Streams helper
                  // utility
                  long size = 0;
                  for (int j = is.read(); j != -1; j = is.read())
                  {
                      stream.write((byte) j);
                      size++;
                  }
                  return size;
  
              }
              finally
              {
                  try
                  {
                      if (is != null)
                      {
                          is.close();
                      }
                  }
                  catch (IOException e1)
                  {
                      // ignore
  
                  }
              }
          }
          else
          {
              return -1;
          }
      }
  
      /**
       * <p>
       * getInputStream
       * </p>
       * 
       * @see org.apache.jetspeed.contentserver.ContentLocator#getInputStream(java.lang.String,
       *      java.util.List)
       * @param URI
       * @param lookupPathes
       * @return
       * @throws IOException
       * @throws FileNotFoundException if the content cannot be found
       */
      public InputStream getInputStream() throws IOException
      {
          String realPath = getRealPath();
          
          if(realPath == null)
          {
              throw new FileNotFoundException("The "+URI+" could not be resolved by the ContentLocator");
          }
                  
          if (contentCache.containsKey(realPath) && useCachedLookup)
          {
              byte[] contentInBytes =(byte[]) contentCache.get(realPath);            
              return new BufferedInputStream(new ByteArrayInputStream(contentInBytes));
  
          }
          else
          {
              File content = new File(realPath);
  
              if (content != null)
              {
                  if(useCachedLookup)
                  {
                      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(content));
                      int size = (int) content.length();
                      int i = 0;
                      byte[] buffer = new byte[size];
                      for (int j = bis.read(); j != -1; j = bis.read())
                      {
                          buffer[i] = (byte) j;
                          i++;
                      }
                      
                      contentCache.put(realPath, buffer);
                      return new BufferedInputStream(new ByteArrayInputStream(buffer));
                  }
                  else
                  {
                      return new BufferedInputStream(new FileInputStream(content));
                  }
              }
              else
              {
                  throw new FileNotFoundException("Failed to load content source "+realPath);
              }
          }
      }
  
      public String getBasePath()
      {
          if (basePath == null)
          {
              String absPath = getRealPath();
              if (absPath != null)
              {
                  int startOffset = absPath.indexOf(contextRoot) + contextRoot.length();
                  basePath = absPath.substring(startOffset, absPath.length());
              }
              else
              {
                  basePath = URI;
              }
          }
          return basePath;
  
      }
  
  }
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java
  
  Index: ContentLocatingResponseWrapper.java
  ===================================================================
  /*
   * Created on Aug 10, 2004
   *
   * TODO To change the template for this generated file go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  package org.apache.jetspeed.contentserver;
  
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.PrintWriter;
  
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServletResponseWrapper;
  
  /**
   * <p>
   * ContentLocatingResponseWrapper
   * </p>
   * <p>
   * 
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
   * @version $Id: ContentLocatingResponseWrapper.java,v 1.1 2004/08/16 13:25:30 weaver Exp $
   *  
   */
  public class ContentLocatingResponseWrapper extends HttpServletResponseWrapper
  {
  
      private ContentLocator contentLocator;
      private HttpServletResponse response;
      private boolean _404sent = false;
      private boolean locationAttempted = false;
      protected boolean outputStreamCalled;
      protected boolean writerCalled;
  
      /**
       * @param arg0
       */
      public ContentLocatingResponseWrapper( HttpServletResponse response, ContentLocator contentLocator )
      {
          super(response);
          this.contentLocator = contentLocator;
          this.response = response;
  
      }
  
       /**
       * <p>
       * sendError
       * </p>
       * 
       * @see javax.servlet.http.HttpServletResponse#sendError(int,
       *      java.lang.String)
       * @param arg0
       * @param arg1
       * @throws java.io.IOException
       */
      public void sendError( int errorCode, String arg1 ) throws IOException
      {
          handleError(errorCode, arg1);
      }
  
      /**
       * <p>
       * sendError
       * </p>
       * 
       * @see javax.servlet.http.HttpServletResponse#sendError(int)
       * @param arg0
       * @throws java.io.IOException
       */
      public void sendError( int errorCode ) throws IOException
      {
          handleError(errorCode, null);
      }
  
      /**
       * <p>
       * handleError
       * </p>
       * 
       * @param errorCode
       * @throws IOException
       */
      protected void handleError( int errorCode, String message ) throws IOException
      {
          if (errorCode == SC_NOT_FOUND)
          {
              _404sent = true;
              try
              {
                  locationAttempted = true;
                  setContentLength((int) contentLocator.writeToOutputStream(getOutputStream()));
                  setStatus(SC_OK);
              }
              catch (FileNotFoundException e)
              {
                  super.sendError(SC_NOT_FOUND, e.getMessage());
              }
          }
          else
          {
              if (message != null)
              {
                  super.sendError(errorCode, message);
              }
              else
              {
                  super.sendError(errorCode);
              }
          }
      }
  
      public boolean was404sent()
      {
          return _404sent;
      }
  
      /**
       * @return Returns the locationAttempted.
       */
      public boolean wasLocationAttempted()
      {
          return locationAttempted;
      }
      /**
       * <p>
       * getOutputStream
       * </p>
       *
       * @see javax.servlet.ServletResponse#getOutputStream()
       * @return
       * @throws java.io.IOException
       */
      public ServletOutputStream getOutputStream() throws IOException
      {
          outputStreamCalled = true;
          return super.getOutputStream();
      }
      /**
       * <p>
       * getWriter
       * </p>
       *
       * @see javax.servlet.ServletResponse#getWriter()
       * @return
       * @throws java.io.IOException
       */
      public PrintWriter getWriter() throws IOException
      {
          writerCalled = true;
          return super.getWriter();
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingRequestWrapper.java
  
  Index: ContentLocatingRequestWrapper.java
  ===================================================================
  /*
   * Created on Aug 10, 2004
   *
   * TODO To change the template for this generated file go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  package org.apache.jetspeed.contentserver;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletRequestWrapper;
  
  /**
   * <p>
   * ContentLocatingRequestWrapper
   * </p>
   * <p>
   *
   * </p>
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
   * @version $Id: ContentLocatingRequestWrapper.java,v 1.1 2004/08/16 13:25:30 weaver Exp $
   *
   */
  public class ContentLocatingRequestWrapper extends HttpServletRequestWrapper
  {
  
      private ContentLocator contentLocator;
      private HttpServletRequest request;
      private boolean readerCalled, isCalled = false;
      
      
  
      public ContentLocatingRequestWrapper( HttpServletRequest request, ContentLocator contentLocator )
      {
          super(request);
          this.contentLocator = contentLocator;
          this.request = request;
          String basePath = contentLocator.getBasePath();
          this.request.setAttribute("javax.servlet.include.servlet_path", basePath);
          this.request.setAttribute("javax.servlet.include.request_uri", basePath);
      }
      
      /**
       * <p>
       * getRequestURI
       * </p>
       *
       * @see javax.servlet.http.HttpServletRequest#getRequestURI()
       * @return
       */
      public String getRequestURI()
      {
          String basePath = contentLocator.getBasePath();
          return basePath;
      }
      /**
       * <p>
       * getRequestURL
       * </p>
       *
       * @see javax.servlet.http.HttpServletRequest#getRequestURL()
       * @return
       */
      public StringBuffer getRequestURL()
      {
          StringBuffer buf = new StringBuffer(super.getRequestURL().length());
          buf.append(request.getScheme())
          .append("://")
          .append(request.getServerName())
          .append(":")
          .append(request.getServerPort())
          .append(request.getContextPath())
          .append(contentLocator.getBasePath());
          return buf;
      }   
      
      /**
       * <p>
       * getServletPath
       * </p>
       *
       * @see javax.servlet.http.HttpServletRequest#getServletPath()
       * @return
       */
      public String getServletPath()
      {   
          return contentLocator.getBasePath();
      }
      /**
       * <p>
       * getContextPath
       * </p>
       *
       * @see javax.servlet.http.HttpServletRequest#getContextPath()
       * @return
       */
      public String getContextPath()
      {
          // TODO Auto-generated method stub
          String cPath = super.getContextPath();
          return cPath;
      }
      /**
       * <p>
       * getPathInfo
       * </p>
       *
       * @see javax.servlet.http.HttpServletRequest#getPathInfo()
       * @return
       */
      public String getPathInfo()
      {
          // TODO Auto-generated method stub
          String pathInfo = super.getPathInfo();
          return pathInfo;
      }
      /**
       * <p>
       * getPathTranslated
       * </p>
       *
       * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
       * @return
       */
      public String getPathTranslated()
      {
          // TODO Auto-generated method stub
          String pathTranslated = super.getPathTranslated();
          return pathTranslated;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org