KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > cache > DataCache


1 /******************************************************************************
2  * DataCache.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.cache;
11
12
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15
16 import java.io.File JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.io.Serializable JavaDoc;
19 import java.net.MalformedURLException JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 import org.openlaszlo.data.XMLConverter;
23 import org.openlaszlo.data.DataSource;
24 import org.openlaszlo.compiler.CompilationEnvironment;
25 import org.openlaszlo.server.LPS;
26
27 /**
28  * A media cache
29  *
30  * @author <a HREF="mailto:bloch@laszlosystems.com">Eric Bloch</a>
31  */

32 public class DataCache extends RequestCache {
33
34     public DataCache(File JavaDoc cacheDirectory, Properties JavaDoc props)
35         throws IOException JavaDoc {
36
37         super("dcache", cacheDirectory, new XMLConverter(), props);
38     }
39
40     /**
41      * @return a serializable cache key for the given request
42      */

43     public Serializable JavaDoc getKey(HttpServletRequest JavaDoc req)
44         throws MalformedURLException JavaDoc {
45
46         // This is a nice readable cache key
47

48         // FIXME: [2003-04-17 bloch] someday this won't be needed
49
// when sendheaders is true, a request should not
50
// be cacheable
51
String JavaDoc hds = req.getParameter("sendheaders");
52         // note: space not allowed in URLS so it's good to
53
// use here as a separator to distinguish encoded keys
54
if (hds == null || hds.equals("true")) {
55             hds = " h=1";
56         } else {
57             hds = " h=0";
58         }
59         String JavaDoc enc = mConverter.chooseEncoding(req);
60         if (enc == null)
61             enc = "";
62         StringBuffer JavaDoc key = new StringBuffer JavaDoc();
63         key.append(DataSource.getURL(req));
64         key.append(hds);
65
66         String JavaDoc swfversion = req.getParameter("lzr");
67         if (swfversion == null) {
68             swfversion = LPS.getProperty("compiler.runtime.default", "swf6");
69         }
70         key.append(" " + swfversion);
71
72         key.append(" ");
73         key.append(enc);
74         return key.toString();
75     }
76     
77     /**
78      * @return true if the request is cacheable.
79      * FIXME: [2003-04-17 bloch] someday enable this
80      * code when we have sendheaders default to false
81     public boolean isCacheable(HttpServletRequest req) {
82         boolean is = super.isCacheable(req);
83         if (is) {
84             String hds = req.getParameter("sendheaders");
85             if (hds == null || hds.equals("false")) {
86                 return true;
87             }
88             return false;
89         } else {
90             return false;
91         }
92     }
93      */

94 }
95
Popular Tags