01: /******************************************************************************
02: * ResponderEVAL.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08: import javax.servlet.ServletOutputStream;
09: import org.openlaszlo.compiler.Compiler;
10: import org.openlaszlo.compiler.CompilationEnvironment;
11: import org.openlaszlo.media.MimeType;
12: import org.openlaszlo.sc.ScriptCompiler;
13: import org.openlaszlo.utils.FileUtils;
14: import org.apache.log4j.Logger;
15:
16: public final class ResponderEVAL extends Responder {
17: private static Logger mLogger = Logger
18: .getLogger(ResponderEVAL.class);
19:
20: protected void respondImpl(HttpServletRequest req,
21: HttpServletResponse res) throws IOException {
22: ServletOutputStream out = res.getOutputStream();
23:
24: String script = req.getParameter("lz_script");
25: boolean logmsg = false;
26:
27: String seqnum = req.getParameter("lzrdbseq");
28:
29: String lz_log = req.getParameter("lz_log");
30:
31: if ((lz_log != null) && lz_log.equals("true")) {
32: logmsg = true;
33: }
34:
35: if (logmsg) {
36: // Just write to the log and let the output connection close
37: mLogger.info(
38: /* (non-Javadoc)
39: * @i18n.test
40: * @org-mes="CLIENT_LOG " + p[0]
41: */
42: org.openlaszlo.i18n.LaszloMessages.getMessage(
43: ResponderEVAL.class.getName(), "051018-50",
44: new Object[] { script }));
45: byte[] action = new byte[0];
46: int swfversion = 6;
47: ScriptCompiler.writeScriptToStream(action, out, swfversion);
48: out.flush();
49: FileUtils.close(out);
50: } else {
51: mLogger.info(
52: /* (non-Javadoc)
53: * @i18n.test
54: * @org-mes="doEval for " + p[0] + ", seqnum=" + p[1]
55: */
56: org.openlaszlo.i18n.LaszloMessages.getMessage(
57: ResponderEVAL.class.getName(), "051018-64",
58: new Object[] { script, seqnum }));
59: try {
60: res.setContentType(MimeType.SWF);
61: Compiler compiler = new Compiler();
62: String swfversion = req.getParameter("lzr");
63: // For back compatibility, should an older app that doesn't pass "lzr" arg
64: // be running somehow.
65: if (swfversion == null) {
66: swfversion = "swf6";
67: }
68: compiler.compileAndWriteToSWF(script, seqnum, out,
69: swfversion);
70: } catch (Exception e) {
71: mLogger.info(
72: /* (non-Javadoc)
73: * @i18n.test
74: * @org-mes="LZServlet got error compiling/writing SWF!" + p[0]
75: */
76: org.openlaszlo.i18n.LaszloMessages.getMessage(
77: ResponderEVAL.class.getName(), "051018-83",
78: new Object[] { e }));
79: StringWriter err = new StringWriter();
80: e.printStackTrace(new PrintWriter(err));
81: mLogger.info(err.toString());
82: }
83: }
84: }
85:
86: public int getMimeType() {
87: return MIME_TYPE_SWF;
88: }
89: }
|