weaver 2004/03/11 13:58:26
Modified: content-server/src/java/org/apache/jetspeed/contentserver
ContentFilter.java
content-server/src/webapp index.jsp
content-server/src/webapp/WEB-INF web.xml
Added: content-server/src/webapp/WEB-INF/content/themes/blue
page.html
content-server/src/webapp/WEB-INF/content/themes/blue/script
test.js
content-server/src/webapp/WEB-INF/content/themes/blue/images
myimage.gif myimage.png
content-server/src/webapp/WEB-INF/content/themes/red/images
myimage.png myimage.gif
content-server/src/webapp/WEB-INF/content/themes/red
page.html
content-server/src/webapp/WEB-INF/content/themes/red/script
test.js
Removed: content-server/src/webapp/WEB-INF/content/themes/red/html/images
myimage.png myimage.gif
content-server/src/webapp/WEB-INF/content/themes/red/html/script
test.js
content-server/src/webapp/WEB-INF/content/themes/blue/html/script
test.js
content-server/src/webapp/WEB-INF/content/themes/blue/html/images
myimage.png myimage.gif
content-server/src/webapp/WEB-INF/content/themes/blue/html
page.html
content-server/src/webapp/WEB-INF/content/themes/red/html
page.html
Log:
made content server more generic and less bound to themes
Revision Changes Path
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/blue/page.html
Index: page.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Blue IFRAME</title>
</head>
<body style="background-color: blue">
<h2>
This is IFRAME's html was loaded from the blue theme
</h2>
</body>
</html>
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/blue/script/test.js
Index: test.js
===================================================================
function Hello()
{
var target = document.getElementById("target");
target.innerHTML="This content was generated by the javascript Hello() loaded
from the blue theme";
}
1.3 +100 -75
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContentFilter.java 31 Dec 2003 20:08:38 -0000 1.2
+++ ContentFilter.java 11 Mar 2004 21:58:25 -0000 1.3
@@ -1,11 +1,14 @@
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;
+import java.util.List;
import java.util.Map;
import javax.servlet.Filter;
@@ -22,7 +25,6 @@
/**
* Created on Dec 30, 2003
- *
*
* @author
*/
@@ -32,18 +34,24 @@
* ContentFilter
* </p>
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
* @version $Id$
- *
+ *
*/
public class ContentFilter implements Filter
{
- public static final String SESSION_THEME_ATTR = "org.apache.jetspeed.theme";
+
+ public static final String SESSION_THEME_ATTR =
"org.apache.jetspeed.content.pathes";
+
private FilterConfig config;
- private String defaultTheme;
+
+ private String defaultContentPath;
+
private String contentDir;
- private String themesDir;
+
+ // private String themesDir;
private File contentDirFile;
+
private Map fileCache;
/**
@@ -52,23 +60,25 @@
public void init(FilterConfig config) throws ServletException
{
this.config = config;
- this.defaultTheme = config.getInitParameter("default.theme");
+ this.defaultContentPath = config
+ .getInitParameter("default.content.path");
String dir = config.getInitParameter("content.directory");
this.contentDir = config.getServletContext().getRealPath(dir);
- this.themesDir = this.contentDir + "/themes";
+ // 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!");
- }
+ 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)
+ * @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
{
try
{
@@ -78,26 +88,24 @@
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String requestURI = httpRequest.getRequestURI();
- String mimeType =
config.getServletContext().getMimeType(requestURI);
+ String mimeType = config.getServletContext().getMimeType(
+ requestURI);
- if (mimeType == null)
- {
- throw new NullPointerException(
+ 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.");
- }
+ + requestURI
+ + " could not be located. Make sure your container
is properly configured to detect MIME types."); }
System.out.println(mimeType + " detected: " + requestURI);
- boolean found = setThemeContent(requestURI, httpRequest,
httpResponse, mimeType);
+ boolean found = setThemeContent(requestURI, httpRequest,
+ httpResponse, mimeType);
if (found)
{
System.out.println("Setting status to OK");
httpResponse.setStatus(HttpServletResponse.SC_OK);
- }
- else
+ } else
{
chain.doFilter(request, response);
}
@@ -105,8 +113,7 @@
return;
}
- }
- catch (Exception e)
+ } catch (Exception e)
{
System.out.println("Error filtering image, " + e.toString());
@@ -124,64 +131,77 @@
}
- protected boolean setThemeContent(String URI, HttpServletRequest request,
HttpServletResponse response, String mimeType)
+ protected boolean setThemeContent(String URI, HttpServletRequest request,
+ HttpServletResponse response, String mimeType)
{
- int rootLen = 13;
- int rootStart = URI.indexOf("content/theme");
+ int rootLen = 7;
+ int rootStart = URI.lastIndexOf("content");
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);
- }
+ List pathes = getContentSearchPathes(request);
- BufferedInputStream bis = null;
- try
+ for (int i = 0; i < pathes.size(); i++)
{
-
- 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())
+ 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
{
- sos.write((byte) i);
+ // String fqPath = pathes.get(i) + "/html" + dir;
+ String fqPath = contentDir + "/" + 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);
}
- System.out.println("Wrote " + fqFile.length() + " to the response
output stream.");
- return true;
-
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- finally
- {
+ BufferedInputStream bis = null;
try
{
- if (bis != null)
+
+ 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())
{
- bis.close();
+ sos.write((byte) j);
}
- }
- catch (IOException e1)
+ System.out.println("Wrote " + fqFile.length()
+ + " to the response output stream.");
+
+ return true;
+
+ } catch (Exception e)
{
- // ignore
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (bis != null)
+ {
+ bis.close();
+ }
+ } catch (IOException e1)
+ {
+ // ignore
+ }
}
}
}
@@ -189,15 +209,20 @@
}
- protected String getCurrentTheme(HttpServletRequest request)
+ protected List getContentSearchPathes(HttpServletRequest request)
{
- String themeName = (String)
request.getSession().getAttribute(SESSION_THEME_ATTR);
- if (themeName == null)
+ List contentPathes = (List) request.getSession().getAttribute(
+ SESSION_THEME_ATTR);
+ if (contentPathes == null || contentPathes.size() == 0)
{
- themeName = defaultTheme;
+ contentPathes = new ArrayList(2);
+ contentPathes.add(defaultContentPath);
+ request.getSession()
+ .setAttribute(SESSION_THEME_ATTR, contentPathes);
+ contentPathes.add("");
}
- return themeName;
+ return contentPathes;
}
}
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/blue/images/myimage.gif
<<Binary file>>
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/blue/images/myimage.png
<<Binary file>>
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/red/images/myimage.png
<<Binary file>>
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/red/images/myimage.gif
<<Binary file>>
1.3 +9 -6 jakarta-jetspeed-2/content-server/src/webapp/index.jsp
Index: index.jsp
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/content-server/src/webapp/index.jsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- index.jsp 31 Dec 2003 20:06:04 -0000 1.2
+++ index.jsp 11 Mar 2004 21:58:25 -0000 1.3
@@ -5,13 +5,16 @@
<%
if(request.getParameter("setTheme") != null)
{
- session.setAttribute("org.apache.jetspeed.theme",
request.getParameter("setTheme"));
+ java.util.List contentPathes = new java.util.ArrayList(2);
+ contentPathes.add(request.getParameter("setTheme"));
+ request.getSession().setAttribute("org.apache.jetspeed.content.pathes",
contentPathes);
+ contentPathes.add("");
}
%>
<html>
<head>
<title>Test content</title>
- <script language="JavaScript1.2" type="text/javascript"
src="content/theme/script/test.js"></script>
+ <script language="JavaScript1.2" type="text/javascript"
src="content/script/test.js"></script>
</head>
<body onLoad="Hello();">
<h1 id="target">
@@ -20,15 +23,15 @@
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"/>
+ This is image was located and served by the content server filter: <img
src="content/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>
+ <a href="index.jsp?setTheme=themes/red">Set theme to Red</a>
<br />
- <a href="index.jsp?setTheme=blue">Set theme to Blue</a>
+ <a href="index.jsp?setTheme=themes/blue">Set theme to Blue</a>
</p>
- <iframe src="content/theme/page.html" width="300" height="300" />
+ <iframe src="content/page.html" width="300" height="300" />
</body>
</html>
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/red/page.html
Index: page.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Red IFRAME</title>
</head>
<body style="background-color: red">
<h2>
This is IFRAME's html was loaded from the red theme
</h2>
</body>
</html>
1.1
jakarta-jetspeed-2/content-server/src/webapp/WEB-INF/content/themes/red/script/test.js
Index: test.js
===================================================================
function Hello()
{
var target = document.getElementById("target");
target.innerHTML="This content was generated by the javascript Hello() loaded
from the red theme";
}
1.3 +2 -2 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- web.xml 31 Dec 2003 20:06:04 -0000 1.2
+++ web.xml 11 Mar 2004 21:58:26 -0000 1.3
@@ -10,9 +10,9 @@
<filter-name>ContentServer</filter-name>
<filter-class>org.apache.jetspeed.contentserver.ContentFilter</filter-class>
<init-param>
- <param-name>default.theme</param-name>
+ <param-name>default.content.path</param-name>
<param-value>
- blue
+ themes/blue
</param-value>
</init-param>
<init-param>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]