01: /******************************************************************************
02: * DataCache.java
03: * ****************************************************************************/package org.openlaszlo.cache;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: import java.io.File;
09: import java.io.IOException;
10: import java.io.Serializable;
11: import java.net.MalformedURLException;
12: import java.util.Properties;
13:
14: import org.openlaszlo.data.XMLConverter;
15: import org.openlaszlo.data.DataSource;
16: import org.openlaszlo.compiler.CompilationEnvironment;
17: import org.openlaszlo.server.LPS;
18:
19: /**
20: * A media cache
21: *
22: * @author <a href="mailto:bloch@laszlosystems.com">Eric Bloch</a>
23: */
24: public class DataCache extends RequestCache {
25:
26: public DataCache(File cacheDirectory, Properties props)
27: throws IOException {
28:
29: super ("dcache", cacheDirectory, new XMLConverter(), props);
30: }
31:
32: /**
33: * @return a serializable cache key for the given request
34: */
35: public Serializable getKey(HttpServletRequest req)
36: throws MalformedURLException {
37:
38: // This is a nice readable cache key
39:
40: // FIXME: [2003-04-17 bloch] someday this won't be needed
41: // when sendheaders is true, a request should not
42: // be cacheable
43: String hds = req.getParameter("sendheaders");
44: // note: space not allowed in URLS so it's good to
45: // use here as a separator to distinguish encoded keys
46: if (hds == null || hds.equals("true")) {
47: hds = " h=1";
48: } else {
49: hds = " h=0";
50: }
51: String enc = mConverter.chooseEncoding(req);
52: if (enc == null)
53: enc = "";
54: StringBuffer key = new StringBuffer();
55: key.append(DataSource.getURL(req));
56: key.append(hds);
57:
58: String swfversion = req.getParameter("lzr");
59: if (swfversion == null) {
60: swfversion = LPS.getProperty("compiler.runtime.default",
61: "swf6");
62: }
63: key.append(" " + swfversion);
64:
65: String nsprefix = req.getParameter("nsprefix");
66: key.append(" " + nsprefix);
67:
68: String wtrim = req.getParameter("trimwhitespace");
69: key.append(" " + wtrim);
70:
71: key.append(" ");
72: key.append(enc);
73: return key.toString();
74: }
75:
76: /**
77: * @return true if the request is cacheable.
78: * FIXME: [2003-04-17 bloch] someday enable this
79: * code when we have sendheaders default to false
80: public boolean isCacheable(HttpServletRequest req) {
81: boolean is = super.isCacheable(req);
82: if (is) {
83: String hds = req.getParameter("sendheaders");
84: if (hds == null || hds.equals("false")) {
85: return true;
86: }
87: return false;
88: } else {
89: return false;
90: }
91: }
92: */
93: }
|