01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.views.jsp.ui;
06:
07: import java.io.PrintWriter;
08:
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.apache.commons.logging.Log;
12: import org.apache.commons.logging.LogFactory;
13:
14: import com.opensymphony.webwork.ServletActionContext;
15: import com.opensymphony.webwork.components.AbstractRichtexteditorConnector.FileUploadResult;
16: import com.opensymphony.xwork.ActionInvocation;
17:
18: /**
19: * <!-- START SNIPPET: javadoc -->
20: *
21: * WebWork's result, creating the appropriate result (in javascript form) and write to
22: * the response stream corresponding to a 'FileUpload' command from the
23: * Rich Text Editor.
24: *
25: * <p/>
26: *
27: * An example of the response would be as follows:
28: *
29: * <pre>
30: * <script type="text/javascript">
31: * window.parent.frames['frmUpload'].OnUploadCompleted(0) ;
32: * </script>
33: * </pre>
34: *
35: * <!-- END SNIPPET: javadoc -->
36: *
37: * @author tm_jee
38: * @version $Date: 2006-02-20 16:24:38 +0100 (Mon, 20 Feb 2006) $ $Id: RichtexteditorFileUploadResult.java 2245 2006-02-20 15:24:38Z tmjee $
39: */
40: public class RichtexteditorFileUploadResult extends
41: AbstractRichtexteditorResult {
42:
43: private static final long serialVersionUID = 4094812005581706392L;
44:
45: private static final Log _log = LogFactory
46: .getLog(RichtexteditorFileUploadResult.class);
47:
48: /**
49: * <!-- START SNIPPET: execute -->
50: *
51: * Write the result (in javascript form) to the response stream corresponding to
52: * the Rich Text Editor's 'FileUpload' command.
53: *
54: * <!-- END SNIPPET: execute -->
55: */
56: public void execute(ActionInvocation invocation) throws Exception {
57:
58: HttpServletResponse response = ServletActionContext
59: .getResponse();
60: response.setContentType("text/html; charset=UTF-8");
61: response.setHeader("Cache-Control", "no-cache");
62: PrintWriter out = response.getWriter();
63:
64: /**
65: <script type="text/javascript">
66: window.parent.frames['frmUpload'].OnUploadCompleted(0) ;
67: </script>
68: */
69:
70: FileUploadResult fileUploadResult = richtexteditorFileUploadResult(invocation);
71:
72: StringBuffer buffer = new StringBuffer();
73: buffer.append("<script type=\"text/javascript\">");
74: if (fileUploadResult.getFilename() != null) {
75: buffer
76: .append("window.parent.frames['frmUpload'].OnUploadCompleted("
77: + fileUploadResult.getCode()
78: + ", '"
79: + fileUploadResult.getFilename() + "');");
80: } else {
81: buffer
82: .append("window.parent.frames['frmUpload'].OnUploadCompleted("
83: + fileUploadResult.getCode() + ");");
84: }
85: buffer.append("</script>");
86:
87: String s = buffer.toString();
88: if (_log.isDebugEnabled()) {
89: _log.debug(s);
90: }
91:
92: out.println(s);
93: out.flush();
94: out.close();
95: }
96:
97: }
|