KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************************
2  * ResponderEVAL.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 javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15 import javax.servlet.ServletOutputStream JavaDoc;
16 import org.openlaszlo.compiler.Compiler;
17 import org.openlaszlo.compiler.CompilationEnvironment;
18 import org.openlaszlo.media.MimeType;
19 import org.openlaszlo.sc.ScriptCompiler;
20 import org.openlaszlo.utils.FileUtils;
21 import org.apache.log4j.Logger;
22
23 public final class ResponderEVAL extends Responder
24 {
25     private static Logger mLogger = Logger.getLogger(ResponderEVAL.class);
26
27     protected void respondImpl(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
28         throws IOException
29     {
30         ServletOutputStream JavaDoc out = res.getOutputStream();
31
32         String JavaDoc script = req.getParameter("lz_script");
33         boolean logmsg = false;
34
35         String JavaDoc seqnum = req.getParameter("lzrdbseq");
36
37         String JavaDoc lz_log = req.getParameter("lz_log");
38
39         if ((lz_log != null) && lz_log.equals("true")) {
40             logmsg = true;
41         }
42
43         if (logmsg) {
44             // Just write to the log and let the output connection close
45
mLogger.info("CLIENT_LOG " + script);
46             byte[] action = new byte[0];
47             int swfversion = 5;
48             ScriptCompiler.writeScriptToStream(action, out, swfversion);
49             out.flush();
50             FileUtils.close(out);
51         } else {
52             mLogger.info("doEval for " + script+", seqnum="+seqnum);
53             try {
54                 res.setContentType(MimeType.SWF);
55                 Compiler JavaDoc compiler = new Compiler JavaDoc();
56                 String JavaDoc swfversion = req.getParameter("lzr");
57                 // For back compatibility, should an older app that doesn't pass "lzr" arg
58
// be running somehow.
59
if (swfversion == null) {
60                     swfversion = "swf5";
61                 }
62                 compiler.compileAndWriteToSWF(script, seqnum, out, swfversion);
63             } catch (Exception JavaDoc e) {
64                 mLogger.info("LZServlet got error compiling/writing SWF!" + e);
65                 StringWriter err = new StringWriter();
66                 e.printStackTrace(new PrintWriter(err));
67                 mLogger.info(err.toString());
68             }
69         }
70     }
71
72     public int getMimeType()
73     {
74         return MIME_TYPE_SWF;
75     }
76 }
77
Popular Tags