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/07/27 15:42:13 UTC
cvs commit: jakarta-jetspeed-2/content-server/src/java/org/apache/jetspeed/contentserver SimpleContentLocator.java ContentFilter.java
weaver 2004/07/27 06:42:13
Modified: content-server/src/java/org/apache/jetspeed/contentserver
SimpleContentLocator.java ContentFilter.java
Log:
Allow for multiple URL hints
Revision Changes Path
1.5 +78 -61 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SimpleContentLocator.java 8 May 2004 01:14:25 -0000 1.4
+++ SimpleContentLocator.java 27 Jul 2004 13:42:13 -0000 1.5
@@ -37,7 +37,7 @@
*
*/
public class SimpleContentLocator implements ContentLocator
-{
+{
private String rootPath;
@@ -45,23 +45,26 @@
private Map fileCache;
- private String URLHint;
-
+ private String[] URLHints;
+
private static final Log log = LogFactory.getLog(SimpleContentLocator.class);
- public SimpleContentLocator(String rootPath, String URLHint, boolean useCachedLookup)
- {
+ 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.URLHint = URLHint;
+ this.URLHints = URLHints;
}
- public long mergeContent(String URI, List lookupPathes, OutputStream os)
+ public long mergeContent( String URI, List lookupPathes, OutputStream os )
{
+
File content = locateContent(URI, lookupPathes);
- if(content != null)
+ if (content != null)
{
return setContent(content, os);
}
@@ -71,86 +74,99 @@
}
}
- protected File locateContent(String URI, List lookupPathes)
+ protected File locateContent( String URI, List lookupPathes )
{
- int rootLen = URLHint.length();
- // int rootStart = URI.indexOf(URLHint);
- int rootStart = URI.lastIndexOf(URLHint);
- File fqFile = null;
- if (rootStart != -1)
- {
- String dir = URI.substring(rootStart + rootLen);
-
- for (int i = 0; i < lookupPathes.size(); i++)
- {
-
- if (useCachedLookup && fileCache.containsKey(lookupPathes.get(i) + ":" + URI))
+ 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)
+ {
+ String dir = null;
+ if(rootLen > 1)
{
- fqFile = (File) fileCache.get(lookupPathes.get(i) + ":"
- + URI);
- log.debug("Found cached file for URI: " + URI);
+ dir = URI.substring(rootStart + rootLen);
}
else
{
- // 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] = "/";
- }
+ dir = URI.substring(contextRoot.length());
- 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())
+ for (int i = 0; i < lookupPathes.size(); i++)
+ {
+
+ if (useCachedLookup && fileCache.containsKey(lookupPathes.get(i) + ":" + URI))
{
- fqFile = null;
- continue;
+ fqFile = (File) fileCache.get(lookupPathes.get(i) + ":" + URI);
+ log.debug("Found cached file for URI: " + URI);
+ return fqFile;
}
-
- 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, fqFile);
+ }
+ return fqFile;
}
- return fqFile;
}
}
}
-
+
return null;
-
+
}
-
- protected long setContent(File fqFile, OutputStream os)
+
+ protected long setContent( File fqFile, OutputStream os )
{
BufferedInputStream bis = null;
try
{
- // DST: TODO: optimize using larger blocks with Streams helper utility
+ // 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.");
+ log.debug("Wrote " + fqFile.length() + " to the output stream.");
return fqFile.length();
- } catch (Exception e)
+ }
+ catch (Exception e)
{
e.printStackTrace();
return -1;
- }
+ }
finally
{
try
@@ -159,13 +175,14 @@
{
bis.close();
}
- } catch (IOException e1)
+ }
+ catch (IOException e1)
{
// ignore
}
}
-
+
}
-}
+}
\ No newline at end of file
1.9 +11 -2 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ContentFilter.java 7 May 2004 02:41:15 -0000 1.8
+++ ContentFilter.java 27 Jul 2004 13:42:13 -0000 1.9
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.StringTokenizer;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -98,8 +99,16 @@
+ " 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())
+ {
+ urlHints[i]=hintTokenizer.nextToken();
+ i++;
+ }
SimpleContentLocator contentLocator = new SimpleContentLocator(
- this.contentDir, urlHint, true);
+ this.contentDir, urlHints, true, httpRequest.getContextPath());
long contentLength = contentLocator.mergeContent(requestURI,
getContentSearchPathes(httpRequest), response
.getOutputStream());
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org