001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import java.io.OutputStream;
008:
009: import javax.servlet.http.HttpServletResponse;
010:
011: import org.apache.commons.logging.Log;
012: import org.apache.commons.logging.LogFactory;
013: import org.w3c.dom.Document;
014: import org.w3c.dom.Element;
015:
016: import com.opensymphony.webwork.ServletActionContext;
017: import com.opensymphony.webwork.components.AbstractRichtexteditorConnector.Folder;
018: import com.opensymphony.xwork.ActionInvocation;
019:
020: /**
021: * <!-- START SNIPPET: javadoc -->
022: *
023: * WebWork's result, creating the appropriate result (in xml form) and write to the
024: * response stream corresponding the the Rich Text Editor's 'GetFolders' command.
025: *
026: * <p/>
027: *
028: * An example of the response would be as follows:
029: *
030: * <pre>
031: * <?xml version="1.0" encoding="utf-8" ?>
032: * <Connector command="GetFolders" resourceType="File">
033: * <CurrentFolder path="/Samples/Docs/" url="/UserFiles/File/Samples/Docs/" />
034: * <Folders>
035: * <Folder name="Documents" />
036: * <Folder name="Files" />
037: * <Folder name="Other Files" />
038: * <Folder name="Related" />
039: * </Folders>
040: * </Connector>
041: * </pre>
042: *
043: * <!-- END SNIPPET: javadoc -->
044: *
045: * @author tm_jee
046: * @version $Date: 2006-02-20 16:30:28 +0100 (Mon, 20 Feb 2006) $ $Id: RichtexteditorGetFoldersResult.java 2246 2006-02-20 15:30:28Z tmjee $
047: */
048: public class RichtexteditorGetFoldersResult extends
049: AbstractRichtexteditorResult {
050:
051: private static final Log _log = LogFactory
052: .getLog(RichtexteditorGetFoldersResult.class);
053:
054: private static final long serialVersionUID = -6414969434944547862L;
055:
056: /**
057: * <!-- START SNIPPET: execute -->
058: *
059: * Write the response (in xml form) to the response stream corresponding to
060: * the Rich Text Editor's 'GetFolders' command.
061: *
062: * <!-- END SNIPPET: execute -->
063: */
064: public void execute(ActionInvocation invocation) throws Exception {
065:
066: Folder[] folders = richtexteditorFolders(invocation);
067: HttpServletResponse response = ServletActionContext
068: .getResponse();
069: response.setContentType("text/xml; charset=UTF-8");
070: response.setHeader("Cache-Control", "no-cache");
071:
072: OutputStream os = response.getOutputStream();
073:
074: Document document = buildDocument();
075: Element root = buildCommonResponseXml(document,
076: getCommand(invocation), getType(invocation),
077: getFolderPath(invocation), getServerPath(invocation));
078:
079: Element foldersElement = document.createElement("Folders");
080: if (folders != null) {
081: for (int a = 0; a < folders.length; a++) {
082: Element folderElement = document
083: .createElement("Folder");
084: folderElement.setAttribute("name", folders[a]
085: .getFoldername());
086: foldersElement.appendChild(folderElement);
087: }
088: }
089: root.appendChild(foldersElement);
090:
091: if (_log.isDebugEnabled()) {
092: String result = stringFromDocument(document);
093: _log.debug(result);
094: }
095:
096: writeDocumentToStream(document, os);
097: os.flush();
098: os.close();
099: }
100: }
|