portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/content-server/src/webapp/WEB-INF web.xml
Date Sat, 13 Mar 2004 23:57:41 GMT
weaver      2004/03/13 15:57:41

  Modified:    content-server/src/java/org/apache/jetspeed/contentserver
                        ContentFilter.java SimpleContentLocator.java
                        ContentLocator.java
               content-server/src/webapp/WEB-INF web.xml
  Log:
  - content server made more generic
  - ContentLocator now takes content roots in the mergeContent method instead of the constructor
  
  Revision  Changes    Path
  1.6       +21 -109   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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ContentFilter.java	12 Mar 2004 20:09:00 -0000	1.5
  +++ ContentFilter.java	13 Mar 2004 23:57:41 -0000	1.6
  @@ -1,10 +1,6 @@
   package org.apache.jetspeed.contentserver;
   
  -import java.io.BufferedInputStream;
  -import java.io.ByteArrayOutputStream;
   import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -15,13 +11,13 @@
   import javax.servlet.FilterChain;
   import javax.servlet.FilterConfig;
   import javax.servlet.ServletException;
  -import javax.servlet.ServletOutputStream;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletResponse;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  -import org.apache.commons.io.StreamUtils;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   /**
    * Created on Dec 30, 2003
  @@ -41,32 +37,32 @@
   public class ContentFilter implements Filter
   {
   
  -    public static final String SESSION_THEME_ATTR = "org.apache.jetspeed.content.pathes";
  +    public static final String SESSION_CONTENT_PATH_ATTR = "org.apache.jetspeed.content.pathes";
   
       private FilterConfig config;
   
  -    private String defaultContentPath;
  -
       private String contentDir;
   
       // private String themesDir;
       private File contentDirFile;
  +    
  +    private static final Log log = LogFactory.getLog(ContentFilter.class);
  +
  +    private String urlHint;
  +
   
  -    private Map fileCache;
   
       /**
        * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
        */
       public void init(FilterConfig config) throws ServletException
       {
  -        this.config = config;
  -        this.defaultContentPath = config
  -                .getInitParameter("default.content.path");
  +        this.config = config;        
           String dir = config.getInitParameter("content.directory");
  +        urlHint = config.getInitParameter("url.hint");
           this.contentDir = config.getServletContext().getRealPath(dir);
           // this.themesDir = this.contentDir + "/themes";
           this.contentDirFile = new File(this.contentDir);
  -        this.fileCache = new HashMap();
           if (!contentDirFile.exists()) { throw new ServletException(
                   "The specified content directory "
                           + contentDirFile.getAbsolutePath() + " does not exist!"); }
  @@ -85,7 +81,7 @@
               
               HttpServletRequest httpRequest = (HttpServletRequest) request;
               HttpServletResponse httpResponse = (HttpServletResponse) response;
  -            String requestURI = httpRequest.getRequestURI();
  +            String requestURI = httpRequest.getRequestURI();            
               String mimeType = config.getServletContext()
               .getMimeType(requestURI);
               
  @@ -94,16 +90,16 @@
                       + requestURI
                       + " could not be located.  Make sure your container is properly configured
to detect MIME types."); }
               
  -            System.out.println(mimeType + " detected: " + requestURI);
  +            log.debug(mimeType + " detected: " + requestURI);
               
  -            SimpleContentLocator contentLocator = new SimpleContentLocator(this.contentDir,
getContentSearchPathes(httpRequest), "/content/", true);
  -            long contentLength = contentLocator.mergeContent(requestURI, response.getOutputStream());
  +            SimpleContentLocator contentLocator = new SimpleContentLocator(this.contentDir,
urlHint, true);
  +            long contentLength = contentLocator.mergeContent(requestURI, getContentSearchPathes(httpRequest),
response.getOutputStream());
               
               if (contentLength > -1)
               {
                   response.setContentType(mimeType);
                   response.setContentLength((int) contentLength);
  -                System.out.println("Setting status to OK");
  +                log.debug("Setting status to OK");
                   httpResponse.setStatus(HttpServletResponse.SC_OK);
               } else
               {
  @@ -126,100 +122,16 @@
   
       }
   
  -//    protected boolean setThemeContent(String URI, HttpServletRequest request,
  -//            HttpServletResponse response, String mimeType)
  -//    {
  -//        int rootLen = 7;
  -//        int rootStart = URI.lastIndexOf("content");
  -//        if (rootStart != -1)
  -//        {
  -//            String dir = URI.substring(rootStart + rootLen);
  -//            List pathes = getContentSearchPathes(request);
  -//
  -//            for (int i = 0; i < pathes.size(); i++)
  -//            {
  -//                File fqFile = null;
  -//                if (fileCache.containsKey(pathes.get(i) + ":" + URI))
  -//                {
  -//                    fqFile = (File) fileCache.get(pathes.get(i) + ":" + URI);
  -//                    System.out.println("Found cached file for URI: "
  -//                            + URI);
  -//                } 
  -//                else
  -//                {
  -//                    // String fqPath = pathes.get(i) + "/html" + dir;
  -//                    String sep="";
  -//                    if(pathes.get(i).toString().trim().length() > 1)
  -//                    {
  -//                        sep = "/";
  -//                    }
  -//                    String fqPath = contentDir + sep + pathes.get(i) + dir;
  -//                    
  -//                    fqFile = new File(fqPath);
  -//                    System.out.println("Actual content located at: "
  -//                            + fqPath);
  -//                    System.out.println("Content exists? "
  -//                            + fqFile.exists());
  -//                    if(!fqFile.exists())
  -//                    {
  -//                        continue;
  -//                    }
  -//                    fileCache.put(pathes.get(i) + ":" + URI, fqFile);
  -//                }
  -//
  -//                BufferedInputStream bis = null;
  -//                try
  -//                {
  -//
  -//                    bis = new BufferedInputStream(new FileInputStream(fqFile));
  -//                    response.setContentType(mimeType);
  -//                    response.setContentLength((int) fqFile.length());
  -//                    ServletOutputStream sos = response.getOutputStream();
  -//                    for (int j = bis.read(); j != -1; j = bis.read())
  -//                    {
  -//                        sos.write((byte) j);
  -//                    }
  -//                    System.out.println("Wrote " + fqFile.length()
  -//                            + " to the response output stream.");
  -//
  -//                    return true;
  -//
  -//                } catch (Exception e)
  -//                {
  -//                    // TODO Auto-generated catch block
  -//                    e.printStackTrace();
  -//                } 
  -//                finally
  -//                {
  -//                    try
  -//                    {
  -//                        if (bis != null)
  -//                        {
  -//                            bis.close();
  -//                        }
  -//                    } catch (IOException e1)
  -//                    {
  -//                        // ignore
  -//
  -//                    }
  -//                }
  -//            }
  -//        }
  -//        return false;
  -//
  -//    }
   
       protected List getContentSearchPathes(HttpServletRequest request)
       {
           List contentPathes = (List) request.getSession().getAttribute(
  -                SESSION_THEME_ATTR);
  -        if (contentPathes == null || contentPathes.size() == 0)
  +                SESSION_CONTENT_PATH_ATTR);
  +        if (contentPathes == null)
           {
  -            contentPathes = new ArrayList(2);
  -            contentPathes.add(defaultContentPath);
  -            request.getSession()
  -                    .setAttribute(SESSION_THEME_ATTR, contentPathes);
  -            contentPathes.add("");
  +            contentPathes = new ArrayList();            
  +            //request.getSession()
  +            //        .setAttribute(SESSION_THEME_ATTR, contentPathes);            
           }
   
           return contentPathes;
  
  
  
  1.2       +17 -14    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleContentLocator.java	12 Mar 2004 20:09:00 -0000	1.1
  +++ SimpleContentLocator.java	13 Mar 2004 23:57:41 -0000	1.2
  @@ -15,6 +15,9 @@
   import java.util.List;
   import java.util.Map;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
   /**
    * <p>
    * SimpleContentLocator
  @@ -25,9 +28,7 @@
    *  
    */
   public class SimpleContentLocator implements ContentLocator
  -{
  -
  -    private List lookupPathes;
  +{    
   
       private String rootPath;
   
  @@ -36,20 +37,21 @@
       private Map fileCache;
   
       private String URLHint;
  +    
  +    private static final Log log = LogFactory.getLog(SimpleContentLocator.class);
   
  -    public SimpleContentLocator(String rootPath, List lookupPathes,
  -            String URLHint, boolean useCachedLookup)
  +    public SimpleContentLocator(String rootPath, String URLHint, boolean useCachedLookup)
       {
  -        this.lookupPathes = lookupPathes;
  +
           this.rootPath = rootPath;
           this.useCachedLookup = useCachedLookup;
           fileCache = new HashMap();
           this.URLHint = URLHint;
       }
   
  -    public long mergeContent(String URI, OutputStream os)
  +    public long mergeContent(String URI, List lookupPathes, OutputStream os)
       {
  -        File content = locateContent(URI);
  +        File content = locateContent(URI, lookupPathes);
           if(content != null)
           {
               return setContent(content, os);
  @@ -60,10 +62,11 @@
           }
       }
   
  -    protected File locateContent(String URI)
  +    protected File locateContent(String URI, List lookupPathes)
       {
           int rootLen = URLHint.length();
  -        int rootStart = URI.indexOf(URLHint);
  +        // int rootStart = URI.indexOf(URLHint);
  +        int rootStart = URI.lastIndexOf(URLHint);
           File fqFile = null;
           if (rootStart != -1)
           {
  @@ -76,7 +79,7 @@
                   {
                       fqFile = (File) fileCache.get(lookupPathes.get(i) + ":"
                               + URI);
  -                    System.out.println("Found cached file for URI: " + URI);
  +                    log.debug("Found cached file for URI: " + URI);
                   }
                   else
                   {
  @@ -97,8 +100,8 @@
                                       + sep[1] + dir;
   
                       fqFile = new File(fqPath);
  -                    System.out.println("Actual content located at: " + fqPath);
  -                    System.out.println("Content exists? " + fqFile.exists());
  +                    log.debug("Actual content located at: " + fqPath);
  +                    log.debug("Content exists? " + fqFile.exists());
                       if (!fqFile.exists())
                       {
                           fqFile = null;
  @@ -129,7 +132,7 @@
               {
                   os.write((byte) j);
               }
  -            System.out.println("Wrote " + fqFile.length()
  +            log.debug("Wrote " + fqFile.length()
                       + " to the output stream.");
   
               return fqFile.length();
  
  
  
  1.2       +2 -1      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContentLocator.java	12 Mar 2004 20:09:00 -0000	1.1
  +++ ContentLocator.java	13 Mar 2004 23:57:41 -0000	1.2
  @@ -7,6 +7,7 @@
   package org.apache.jetspeed.contentserver;
   
   import java.io.OutputStream;
  +import java.util.List;
   
   
   /**
  @@ -33,5 +34,5 @@
        * @return int the length of actual content in bytes or -1
        * if the <code>URI</code> was not found.
        */
  -    long mergeContent(String URI, OutputStream os);
  +    long mergeContent(String URI, List lookupPathes, OutputStream os);
   }
  
  
  
  1.4       +5 -5      jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/web.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- web.xml	11 Mar 2004 21:58:26 -0000	1.3
  +++ web.xml	13 Mar 2004 23:57:41 -0000	1.4
  @@ -10,15 +10,15 @@
       <filter-name>ContentServer</filter-name>
       <filter-class>org.apache.jetspeed.contentserver.ContentFilter</filter-class>
        <init-param>
  -        <param-name>default.content.path</param-name>
  +        <param-name>content.directory</param-name>
           <param-value>
  -           themes/blue
  +           WEB-INF/content
           </param-value>
       </init-param>
  -     <init-param>
  -        <param-name>content.directory</param-name>
  +    <init-param>
  +        <param-name>url.hint</param-name>
           <param-value>
  -           WEB-INF/content
  +           content/
           </param-value>
       </init-param>
     </filter>
  
  
  

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


Mime
View raw message