Author: weaver
Date: Tue Aug 16 13:56:54 2005
New Revision: 233055
URL: http://svn.apache.org/viewcvs?rev=233055&view=rev
Log:
Fix for JS2-303.
Modified:
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/AbstractContentLocator.java
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java
Modified:
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/AbstractContentLocator.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/AbstractContentLocator.java?rev=233055&r1=233054&r2=233055&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/AbstractContentLocator.java
(original)
+++
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/AbstractContentLocator.java
Tue Aug 16 13:56:54 2005
@@ -17,7 +17,6 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -25,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,24 +42,33 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver </a>
* @version $Id$
- *
+ *
*/
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 static final Map fileCache = 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 )
+ protected File contentFile;
+
+ public AbstractContentLocator(String rootPath, String[] URLHints, boolean
useCachedLookup, String contextRoot,
+ String URI, List lookupPathes) throws FileNotFoundException
{
this.contextRoot = contextRoot;
this.rootPath = rootPath;
@@ -67,17 +76,27 @@
this.URLHints = URLHints;
this.URI = URI;
this.lookupPathes = lookupPathes;
+ String realPath = getRealPath();
+ if (realPath != null)
+ {
+ this.contentFile = new File(realPath);
+ }
+ else
+ {
+ throw new FileNotFoundException("Target path " + URI + " not found
withint the content locations provided");
+ }
+
}
public OutputStream getOutputStream() throws IOException
{
- File content = new File(getRealPath());
- BufferedOutputStream bos = new BufferedOutputStream(new
ByteArrayOutputStream((int) content.length()));
+
+ BufferedOutputStream bos = new BufferedOutputStream(new
ByteArrayOutputStream((int) contentFile.length()));
writeToOutputStream(bos);
return bos;
}
- public long writeToOutputStream( OutputStream stream ) throws IOException
+ public long writeToOutputStream(OutputStream stream) throws IOException
{
InputStream is = getInputStream();
@@ -130,54 +149,27 @@
* @param lookupPathes
* @return
* @throws IOException
- * @throws FileNotFoundException if the content cannot be found
+ * @throws FileNotFoundException
+ * if the content cannot be found
*/
public InputStream getInputStream() throws IOException
{
String realPath = getRealPath();
-
- if(realPath == null)
+
+ if (realPath == null)
{
- throw new FileNotFoundException("The "+URI+" could not be resolved
by the ContentLocator");
+ 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));
+ if (contentFile != null)
+ {
+ return new BufferedInputStream(new FileInputStream(contentFile));
}
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);
- }
+ throw new FileNotFoundException("Failed to load content source " +
realPath);
}
+
}
public String getBasePath()
@@ -188,7 +180,7 @@
if (absPath != null)
{
- absPath = absPath.replace('\\','/');
+ absPath = absPath.replace('\\', '/');
int startOffset = absPath.indexOf(contextRoot) +
contextRoot.length();
basePath = absPath.substring(startOffset, absPath.length());
}
@@ -199,6 +191,11 @@
}
return basePath;
+ }
+
+ public Date getLastModified()
+ {
+ return new Date(contentFile.lastModified());
}
}
Modified:
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java?rev=233055&r1=233054&r2=233055&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
(original)
+++
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
Tue Aug 16 13:56:54 2005
@@ -107,42 +107,50 @@
public void doFilter( ServletRequest request, ServletResponse response,
FilterChain chain ) throws IOException,
ServletException
{
- if (request instanceof HttpServletRequest)
+ try
{
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- HttpServletResponse httpResponse = (HttpServletResponse) response;
- String requestURI = httpRequest.getRequestURI();
-
- 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)
+ if (request instanceof HttpServletRequest)
{
- try
- {
- httpResponse.setContentLength((int)
contentLocator.writeToOutputStream(httpResponse.getOutputStream()));
- httpResponse.setStatus(HttpServletResponse.SC_OK);
- }
- catch (FileNotFoundException e)
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ HttpServletResponse httpResponse = (HttpServletResponse)
response;
+ String requestURI = httpRequest.getRequestURI();
+
+ 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)
{
- httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND,
e.getMessage());
+ try
+ {
+ httpResponse.setContentLength((int)
contentLocator.writeToOutputStream(httpResponse.getOutputStream()));
+ httpResponse.setStatus(HttpServletResponse.SC_OK);
+ }
+ catch (FileNotFoundException e)
+ {
+
httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
+ }
+
+
}
-
-
- }
+ }
+ else
+ {
+ chain.doFilter(request, response);
+ }
}
- else
+ catch (FileNotFoundException e)
{
chain.doFilter(request, response);
}
+
}
Modified:
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java?rev=233055&r1=233054&r2=233055&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java
(original)
+++
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java
Tue Aug 16 13:56:54 2005
@@ -9,6 +9,9 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
@@ -47,7 +50,12 @@
super(response);
this.contentLocator = contentLocator;
this.response = response;
-
+
+ DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss
zzz");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ this.response.setHeader("Last-Modified",
dateFormat.format(contentLocator.getLastModified()));
+ this.response.setHeader("Cache-Control", "max-age=3600,
must-revalidate, proxy-revalidate");
+ this.response.setHeader("Apache-Jetspeed-Info",
"real-path="+this.contentLocator.getBasePath());
}
/**
Modified:
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java?rev=233055&r1=233054&r2=233055&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java
(original)
+++
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocator.java
Tue Aug 16 13:56:54 2005
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Date;
/**
@@ -41,4 +42,6 @@
long writeToOutputStream(OutputStream stream) throws IOException;
String getBasePath();
+
+ Date getLastModified();
}
Modified:
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java
URL:
http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java?rev=233055&r1=233054&r2=233055&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java
(original)
+++
portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/SimpleContentLocator.java
Tue Aug 16 13:56:54 2005
@@ -16,6 +16,7 @@
package org.apache.jetspeed.contentserver;
import java.io.File;
+import java.io.FileNotFoundException;
import java.util.List;
/**
@@ -39,8 +40,9 @@
* @param contextRoot
* @param URI
* @param lookupPathes
+ * @throws FileNotFoundException
*/
- public SimpleContentLocator( String rootPath, String[] URLHints, boolean
useCachedLookup, String contextRoot, String URI, List lookupPathes )
+ public SimpleContentLocator( String rootPath, String[] URLHints, boolean
useCachedLookup, String contextRoot, String URI, List lookupPathes ) throws
FileNotFoundException
{
super(rootPath, URLHints, useCachedLookup, contextRoot, URI,
lookupPathes);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]