Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2004-2009 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* - GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
* http://www.gnu.org/licenses/lgpl.html
*
* - Mozilla Public License Version 1.1 or later (the "MPL")
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*/
package net.fckeditor.response;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import net.fckeditor.connector.Connector;
import net.fckeditor.handlers.Command;
import net.fckeditor.handlers.ResourceType;
import net.fckeditor.localization.LocalizedMessages;
import net.fckeditor.requestcycle.ThreadLocalData;
import net.fckeditor.tool.Utils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Represents the XML response for the File Browser GET
* requests.
*
* @version $Id: GetResponse.java 3759 2009-06-22 20:02:26Z mosipov $
*/
public class GetResponse {
/** Underlying DOM document */
protected Document document;
/** Error element, in case of an invalid request */
protected Element errorElement;
/** Folders element, in case of a GetResources request */
protected Element foldersElement;
/** Files element, in case of a GetResources request */
protected Element filesElement;
/** Error number OK */
public static final int EN_OK = 0;
/** Error number CUSTOM ERROR */
public static final int EN_CUSTOM_ERROR = 1;
/** Error number FOLDER ALREADY EXISTS */
public static final int EN_FOLDER_ALREADY_EXISTS_ERROR = 101;
/** Error number INVALID NEW FOLDER NAME */
public static final int EN_INVALID_NEW_FOLDER_NAME_ERROR = 102;
/** Error number SECURITY ERROR */
public static final int EN_CREATE_FOLDER_SECURITY_ERROR = 103;
/** Error number UNKNOWN ERROR */
public static final int EN_UKNOWN_CREATE_FOLDER_ERROR = 110;
/**
* Constructs a response with a specific error number and message.
*
* @param number
* the error number of the new get response
* @param message
* the specific message of the new get response
* @throws RuntimeException
* if creation of the underlying DOM document failed
*/
public GetResponse(int number, String message) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
Element root = document.createElement("Connector");
document.appendChild(root);
setError(number, message);
}
/**
* Constructs a successful response for a specific command and resource
* type.
*
* @param command
* the current command of the new get response
* @param type
* the current resource type of the new get response
* @param currentFolder
* the current folder of the new get response
* @param constructedUrl
* the final URL of the new get response
* @throws RuntimeException
* if creation of the underlying DOM document failed
*/
public GetResponse(Command command, ResourceType type,
String currentFolder, String constructedUrl) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
Element root = document.createElement("Connector");
document.appendChild(root);
root.setAttribute("command", command.getName());
root.setAttribute("resourceType", type.getName());
Element currentFolderElement = document.createElement("CurrentFolder");
currentFolderElement.setAttribute("path", currentFolder);
currentFolderElement.setAttribute("url", constructedUrl);
root.appendChild(currentFolderElement);
}
/**
* Constructs a response with a specific error number only.
*
* @param number
* the error number of the new get response
* @throws RuntimeException
* if creation of the underlying DOM document failed
*/
public GetResponse(int number) {
this(number, null);
}
/**
* Sets the error number and specific message of this get response.
*
* @param number
* the error number of this get response
* @param message
* the specific message of this get response
*/
public void setError(int number, String message) {
if (errorElement == null) {
errorElement = document.createElement("Error");
document.getDocumentElement().appendChild(errorElement);
}
errorElement.setAttribute("number", String.valueOf(number));
if (Utils.isNotEmpty(message))
errorElement.setAttribute("text", message);
}
/**
* Sets the error number of this get response.
*
* @param number
* the error number of this get response
*/
public void setError(int number) {
setError(number, null);
}
/**
* Sets the folders of this get response.
*
* @see Connector#getFolders(ResourceType, String)
* @param folders
* the folders of this get response
*/
public void setFolders(final List folders) {
if (foldersElement != null) {
Element parent = (Element) foldersElement.getParentNode();
parent.removeChild(foldersElement);
}
foldersElement = document.createElement("Folders");
document.getDocumentElement().appendChild(foldersElement);
for (String folder : folders) {
Element folderElement = document.createElement("Folder");
folderElement.setAttribute("name", folder);
foldersElement.appendChild(folderElement);
}
}
/**
* Sets the folders of this get response.
*
* @see Connector#getFiles(ResourceType, String)
* @param files
* the files of this get response
*/
public void setFiles(final List