01: /******************************************************************************
02: * ResponderDATA.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.Properties;
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11: import javax.servlet.ServletOutputStream;
12: import org.openlaszlo.cache.DataCache;
13: import org.openlaszlo.cache.RequestCache;
14: import org.openlaszlo.server.LPS;
15:
16: import org.apache.log4j.Logger;
17:
18: /**
19: *
20: */
21: public final class ResponderDATA extends ResponderCache {
22: private static DataCache mCache = null;
23: private static boolean mIsInitialized = false;
24: private static Logger mLogger = Logger
25: .getLogger(ResponderDATA.class);
26:
27: synchronized public void init(String reqName, ServletConfig config,
28: Properties prop) throws ServletException, IOException {
29: // Cache should only be initialized once.
30: if (!mIsInitialized) {
31: // Initialize data cache
32: String cacheDir = config
33: .getInitParameter("lps.dcache.directory");
34: if (cacheDir == null) {
35: cacheDir = prop.getProperty("dcache.directory");
36: }
37: if (cacheDir == null) {
38: cacheDir = LPS.getWorkDirectory() + File.separator
39: + "dcache";
40: }
41:
42: File cache = checkDirectory(cacheDir);
43: mLogger.info(
44: /* (non-Javadoc)
45: * @i18n.test
46: * @org-mes="Data Cache is at " + p[0]
47: */
48: org.openlaszlo.i18n.LaszloMessages.getMessage(
49: ResponderDATA.class.getName(), "051018-54",
50: new Object[] { cacheDir }));
51:
52: //------------------------------------------------------------
53: // Support for new style data response
54: //------------------------------------------------------------
55: try {
56: mCache = new DataCache(cache, prop);
57: } catch (IOException e) {
58: throw new ServletException(e.getMessage());
59: }
60:
61: mIsInitialized = true;
62: }
63: super .init(reqName, config, mCache, prop);
64: }
65:
66: static public RequestCache getCache() {
67: return mCache;
68: }
69: }
|