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.XMLGrabber;
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:hminsky@laszlosystems.com">Henry Minsky</a>
23: */
24: public class XMLDataCache extends RequestCache {
25:
26: public XMLDataCache(File cacheDirectory, Properties props)
27: throws IOException {
28:
29: super ("dxcache", cacheDirectory, new XMLGrabber(), 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 nsprefix = req.getParameter("nsprefix");
59: key.append(" " + nsprefix);
60:
61: String wtrim = req.getParameter("trimwhitespace");
62: key.append(" " + wtrim);
63:
64: key.append(" ");
65: key.append(enc);
66: return key.toString();
67: }
68:
69: /**
70: * @return true if the request is cacheable.
71: * FIXME: [2003-04-17 bloch] someday enable this
72: * code when we have sendheaders default to false
73: public boolean isCacheable(HttpServletRequest req) {
74: boolean is = super.isCacheable(req);
75: if (is) {
76: String hds = req.getParameter("sendheaders");
77: if (hds == null || hds.equals("false")) {
78: return true;
79: }
80: return false;
81: } else {
82: return false;
83: }
84: }
85: */
86: }
|