KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > servlet > servflash


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.servlet;
11
12 import java.io.*;
13 import javax.servlet.*;
14 import javax.servlet.http.*;
15
16 import org.mmbase.module.sessionsInterface;
17 import org.mmbase.module.core.MMBaseContext;
18 import org.mmbase.module.gui.flash.*;
19 import org.mmbase.util.scanpage;
20 import org.mmbase.util.logging.Logger;
21 import org.mmbase.util.logging.Logging;
22
23 /**
24   * The Servflas servlet responds on certain file extensions to dynamically generate Shockwave Flash
25   * based on a template and information from within MMBase
26   * @rename Servflash
27  */

28 public class servflash extends JamesServlet {
29     private static Logger log;
30
31     private MMFlash gen;
32     private static sessionsInterface sessions = null;
33
34     public void init() throws ServletException {
35         super.init();
36         // Initializing log here because log4j has to be initialized first.
37
log = Logging.getLoggerInstance(servflash.class);
38     }
39     
40     public void setMMBase(org.mmbase.module.core.MMBase mmb) {
41         super.setMMBase(mmb);
42         try {
43             MMBaseContext.initHtmlRoot();
44         } catch (ServletException se) {
45             log.error(se);
46         }
47         gen = (MMFlash)getModule("mmflash");
48         sessions = (sessionsInterface)getModule("SESSION");
49     }
50
51     /**
52      * reload
53      */

54     public void reload() {
55     }
56
57     /**
58      * service call will be called by the server when a request is done
59      * by a user.
60      */

61     public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
62         if (!checkInited(res)) {
63             return;
64         }
65
66         incRefCount(req);
67         try {
68             pageLog.service("Parsing FLASH page: " + req.getRequestURI());
69             BufferedOutputStream out = null;
70             try {
71                 out = new BufferedOutputStream(res.getOutputStream());
72             } catch (Exception JavaDoc e) {
73                 log.error(Logging.stackTrace(e));
74             }
75             if (gen != null) {
76                 scanpage sp = new scanpage(this, req, res, sessions);
77                 if (req.getRequestURI().endsWith(".swt")) {
78                     res.setContentType("text/plain");
79                     byte[] bytes = gen.getDebugSwt(sp);
80                     if (bytes != null) {
81                         out.write(bytes, 0, bytes.length);
82                     } else {
83                         res.sendError(404);
84                     }
85                 } else {
86                     res.setContentType(sp.mimetype); // application/x-shockwave-flash
87
byte[] bytes = gen.getScanParsedFlash(sp);
88                     if (bytes != null) {
89                         out.write(bytes, 0, bytes.length);
90                     } else {
91                         res.sendError(404);
92                     }
93                 }
94             }
95             pageLog.debug("END Parsing FLASH page");
96         }
97         finally {
98             decRefCount(req);
99         }
100     }
101 }
102
Popular Tags