KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderMEDIA


1 /******************************************************************************
2  * ResponderMEDIA.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.servlets.responders;
11
12 import java.io.*;
13 import java.util.Properties JavaDoc;
14 import javax.servlet.ServletConfig JavaDoc;
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18 import javax.servlet.ServletOutputStream JavaDoc;
19 import org.openlaszlo.cache.MediaCache;
20 import org.openlaszlo.cache.RequestCache;
21 import org.openlaszlo.server.LPS;
22
23 import org.apache.log4j.Logger;
24
25 public final class ResponderMEDIA extends ResponderCache
26 {
27     private static MediaCache mCache = null;
28     private static boolean mIsInitialized = false;
29     private static Logger mLogger = Logger.getLogger(ResponderMEDIA.class);
30
31     public void init(String JavaDoc reqName, ServletConfig JavaDoc config, Properties JavaDoc prop)
32         throws ServletException JavaDoc, IOException
33     {
34         if (! mIsInitialized) {
35             // Initialize media cache
36
String JavaDoc cacheDir = config.getInitParameter("lps.mcache.directory");
37             if (cacheDir == null) {
38                 cacheDir = prop.getProperty("mcache.directory");
39             }
40             if (cacheDir == null) {
41                 cacheDir = LPS.getWorkDirectory() + File.separator + "mcache";
42             }
43
44             File cache = checkDirectory(cacheDir);
45             mLogger.info("Media Cache is at " + cacheDir);
46
47             try {
48                 mCache = new MediaCache(cache, prop);
49             } catch (IOException e) {
50                 throw new ServletException JavaDoc(e.getMessage());
51             }
52
53             mIsInitialized = true;
54         }
55
56         super.init(reqName, config, mCache, prop);
57     }
58
59     static public RequestCache getCache()
60     {
61         return mCache;
62     }
63 }
64
Popular Tags