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.OutputStream;
08:
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.apache.commons.logging.Log;
12: import org.apache.commons.logging.LogFactory;
13: import org.w3c.dom.Document;
14: import org.w3c.dom.Element;
15:
16: import com.opensymphony.webwork.ServletActionContext;
17: import com.opensymphony.webwork.components.AbstractRichtexteditorConnector.CreateFolderResult;
18: import com.opensymphony.xwork.ActionInvocation;
19:
20: /**
21: * <!-- START SNIPPET: javadoc -->
22: *
23: * WebWork's result, creating the apropriate result (in xml form) and write it out
24: * to the response stream corresponding to a 'CreateFolder' command from the
25: * Rich Text Editor.
26: *
27: * <p/>
28: *
29: * An example of the response would be as follows:
30: *
31: * <pre>
32: * <?xml version="1.0" encoding="utf-8" ?>
33: * <Connector command="CreateFolder" resourceType="File">
34: * <CurrentFolder path="/Samples/Docs/" url="/UserFiles/File/Samples/Docs/" />
35: * <Error number="0" />
36: * </Connector>
37: * </pre>
38: *
39: * <!-- END SNIPPET: javadoc -->
40: *
41: * @author tm_jee
42: * @version $Date: 2006-02-20 16:24:38 +0100 (Mon, 20 Feb 2006) $ $Id: RichtexteditorCreateFolderResult.java 2245 2006-02-20 15:24:38Z tmjee $
43: */
44: public class RichtexteditorCreateFolderResult extends
45: AbstractRichtexteditorResult {
46:
47: private static final Log _log = LogFactory
48: .getLog(RichtexteditorCreateFolderResult.class);
49:
50: private static final long serialVersionUID = 9024490340530057673L;
51:
52: /**
53: * <!-- START SNIPPET: execute -->
54: *
55: * Write the result (in xml form) to the response stream corresponding to
56: * the Rich Text Editor's 'CreateFolder' command
57: *
58: * <!-- END SNIPPET: execute -->
59: *
60: * @param invocation
61: */
62: public void execute(ActionInvocation invocation) throws Exception {
63: HttpServletResponse response = ServletActionContext
64: .getResponse();
65: response.setContentType("text/xml; charset=UTF-8");
66: response.setHeader("Cache-Control", "no-cache");
67:
68: OutputStream os = response.getOutputStream();
69:
70: CreateFolderResult createFolderResult = richtexteditorCreateFolderResult(invocation);
71:
72: Document document = buildDocument();
73: Element root = buildCommonResponseXml(document,
74: getCommand(invocation), getType(invocation),
75: getFolderPath(invocation), getServerPath(invocation));
76:
77: Element errorElement = document.createElement("Error");
78: errorElement.setAttribute("number", createFolderResult
79: .getCode());
80: root.appendChild(errorElement);
81:
82: if (_log.isDebugEnabled()) {
83: String result = stringFromDocument(document);
84: _log.debug(result);
85: }
86:
87: writeDocumentToStream(document, os);
88: os.flush();
89: os.close();
90: }
91: }
|