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 Wed, 31 Dec 2003 19:48:46 GMT
weaver      2003/12/31 11:48:46

  Modified:    content-server project.xml
  Added:       content-server/src/java/org/apache/jetspeed/contentserver
                        ContentFilter.java
               content-server/src/webapp/WEB-INF/content/themes/red/html/images
                        myimage.png myimage.gif
               content-server/src/webapp/WEB-INF/content/themes/blue/html/images
                        myimage.png myimage.gif
               content-server README.txt
               content-server/src/webapp index.jsp
               content-server/src/webapp/images myimage.png myimage.gif
               content-server/src/webapp/WEB-INF web.xml
  Removed:     content-server/src/java/org/apache/jetspeed/contentserver
                        ContentServlet.java
  Log:
  Content server is now ready for rudimentary testing by its lonesome.
  
  You can maven war the test app and deploy it.  The default page, index.jsp,
  will allow you to change between the two available themes, blue and red.
  
  What still needs to be done:
  - support locallization
  - support "prefered content type" for client probably use the Capability map for this.
  - support content other then that of themes.
  - finish and implement the deployment system.
  - DOCUMENT, DOCUMENT, DOCUMENT!!!!
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
  
  Index: ContentFilter.java
  ===================================================================
  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.HashMap;
  import java.util.Map;
  
  import javax.servlet.Filter;
  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;
  
  /**
   * Created on Dec 30, 2003
   *
   * 
   * @author
   */
  
  /**
   * <p>
   * ContentFilter
   * </p>
   * 
   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
   * @version $Id: ContentFilter.java,v 1.1 2003/12/31 19:48:45 weaver Exp $
   *
   */
  public class ContentFilter implements Filter
  {
      public static final String SESSION_THEME_ATTR = "org.apache.jetspeed.theme";
      private FilterConfig config;
      private String defaultTheme;
      private String contentDir;
      private String themesDir;
      private File contentDirFile;
      private Map fileCache;
  
      /**
       * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
       */
      public void init(FilterConfig config) throws ServletException
      {
          this.config = config;
          this.defaultTheme = config.getInitParameter("default.theme");
          String dir = config.getInitParameter("content.directory");
          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!");
          }
  
      }
  
      /**
       * @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
      {
          try
          {
              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.");
                  }
  
                  if (mimeType.equals("image/gif"))
                  {
                      System.out.println("GIF detected: " + requestURI);
  
                      boolean found = setThemeContent(requestURI, httpRequest, httpResponse,
mimeType);
  
                      if (found)
                      {
                          System.out.println("Setting status to OK");
                          httpResponse.setStatus(HttpServletResponse.SC_OK);
                      }
                      else
                      {
                          chain.doFilter(request, response);
                      }
  
                      return;
                  }
              }
          }
          catch (Exception e)
          {
  
              System.out.println("Error filtering image, " + e.toString());
              e.printStackTrace();
          }
  
          chain.doFilter(request, response);
      }
  
      /**
       * @see javax.servlet.Filter#destroy()
       */
      public void destroy()
      {
  
      }
  
      protected boolean setThemeContent(String URI, HttpServletRequest request, HttpServletResponse
response, String mimeType)
      {
          int rootLen = 13;
          int rootStart = URI.indexOf("content/theme");
          if (rootStart != -1)
          {
              String dir = URI.substring(rootStart + rootLen);
              String themeName = getCurrentTheme(request);
              File fqFile = null;
              if (fileCache.containsKey(themeName + ":" + URI))
              {
                  fqFile = (File) fileCache.get(themeName + ":" + URI);
  				System.out.println("Found cached theme file for URI: " + URI);
              }
              else
              {
                  String fqPath = themesDir + "/" + themeName + "/html" + dir;
                  fqFile = new File(fqPath);
                  System.out.println("Actual theme content located at: " + fqPath);
                  System.out.println("Theme content exists? " + fqFile.exists());
  				fileCache.put(themeName + ":" + 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 i = bis.read(); i != -1; i = bis.read())
                  {
                      sos.write((byte) i);
                  }
                  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 String getCurrentTheme(HttpServletRequest request)
      {
          String themeName = (String) request.getSession().getAttribute(SESSION_THEME_ATTR);
          if (themeName == null)
          {
              themeName = defaultTheme;
          }
  
          return themeName;
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/red/html/images/myimage.png
  
  	<<Binary file>>
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/red/html/images/myimage.gif
  
  	<<Binary file>>
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/blue/html/images/myimage.png
  
  	<<Binary file>>
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/blue/html/images/myimage.gif
  
  	<<Binary file>>
  
  
  1.3       +19 -6     jakarta-jetspeed-2/content-server/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/content-server/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml	26 Dec 2003 16:24:27 -0000	1.2
  +++ project.xml	31 Dec 2003 19:48:45 -0000	1.3
  @@ -2,7 +2,7 @@
   
   <project>
     <pomVersion>3</pomVersion>
  -  <id>jetspeed2-content-server</id>
  +  <id>content-server</id>
     <name>Jetspeed 2 Enterprise Portal Content Server</name>
     <groupId>jetspeed2</groupId>
     <currentVersion>2.0-a1-dev</currentVersion>
  @@ -96,11 +96,25 @@
   
       </developers>
      <dependencies>
  +   	  <dependency>
  +      <id>commons-io</id>
  +      <version>0.1</version>
  +      <properties>
  +        <war.bundle.jar>true</war.bundle.jar>
  +      </properties>
  +    </dependency>
  +   	  <dependency>
  +      <id>commons-lang</id>
  +      <version>1.0.1</version>
  +      <properties>
  +        <war.bundle.jar>true</war.bundle.jar>
  +      </properties>
  +    </dependency>
        <dependency>
         <id>commons-logging</id>
         <version>1.0.2</version>
         <properties>
  -        <war.bundle.jar>false</war.bundle.jar>
  +        <war.bundle.jar>true</war.bundle.jar>
         </properties>
       </dependency>
         <dependency>
  @@ -114,8 +128,9 @@
   
     <build>
       <nagEmailAddress>david@bluesunrise.com</nagEmailAddress>
  -    <!--
  +
       <sourceDirectory>src/java</sourceDirectory>
  +    <!--
       <unitTestSourceDirectory>src/test</unitTestSourceDirectory>
       <aspectSourceDirectory></aspectSourceDirectory>
       -->
  @@ -123,9 +138,7 @@
         <includes>
           <include>**/*Test*.java</include>
         </includes>
  -      <excludes>
  -        <exclude>**/BaseTestCase.java</exclude>
  -      </excludes>
  +
       </unitTest>
     </build>
   </project>
  
  
  
  1.1                  jakarta-jetspeed-2/content-server/README.txt
  
  Index: README.txt
  ===================================================================
  To run a simple test on the content server just "maven war" this sub-project and deploy
the war to your app server.
  
  The index.jsp should automatically come up and you should be able to test changing between
the test themes:
  red and blue.
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/index.jsp
  
  Index: index.jsp
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <%
  	if(request.getParameter("setTheme") != null)
  	{
  		session.setAttribute("org.apache.jetspeed.theme", request.getParameter("setTheme"));
  	}
  %>
  <html>
    <head>
      <title>Test content</title>
    </head>
    <body>
     <p>
     	 This is a normal, static image: <img src="images/myimage.gif" align="middle"/>
     </p>
        <p>
     	 This is  image was located and served by the content server filter: <img src="content/theme/images/myimage.gif"
align="middle"/>
     </p>
     <p>
       Current theme is: <%=session.getAttribute("org.apache.jetspeed.theme")%>
       <br />
        <a href="index.jsp?setTheme=red">Set theme to Red</a>
       <br />
        <a href="index.jsp?setTheme=blue">Set theme to Blue</a>
     </p>
    </body>
   </html>  
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/images/myimage.png
  
  	<<Binary file>>
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/images/myimage.gif
  
  	<<Binary file>>
  
  
  1.1                  jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
  <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                           "http://java.sun.com/dtd/web-app_2.3.dtd">
  -->                         
  <web-app>
    <display-name>Test Content Server</display-name>
    <description>Test application for the content server filter</description>
    <filter>
      <filter-name>ContentServer</filter-name>
      <filter-class>org.apache.jetspeed.contentserver.ContentFilter</filter-class>
       <init-param>
          <param-name>default.theme</param-name>
          <param-value>
             blue
          </param-value>
      </init-param>
       <init-param>
          <param-name>content.directory</param-name>
          <param-value>
             WEB-INF/content
          </param-value>
      </init-param>
    </filter>
  
    <filter-mapping>
      <filter-name>ContentServer</filter-name>
      <url-pattern>*.gif</url-pattern>    
    </filter-mapping>
    <filter-mapping>
      <filter-name>ContentServer</filter-name>
      <url-pattern>*.jpg</url-pattern>
    </filter-mapping>
    <filter-mapping>
      <filter-name>ContentServer</filter-name>
      <url-pattern>*.jpeg</url-pattern>
    </filter-mapping>
    <filter-mapping>
      <filter-name>ContentServer</filter-name>
      <url-pattern>*.png</url-pattern>
    </filter-mapping>
    <filter-mapping>
      <filter-name>ContentServer</filter-name>
      <url-pattern>*.js</url-pattern>
    </filter-mapping>
    
    
    
  
  
  </web-app>
  
  
  

---------------------------------------------------------------------
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