Update of /cvsroot/phpslash/phpslash-dev/public_html/scripts/fckeditor/_jsp/src/com/fredck/FCKeditor/connector
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6026/phpslash-dev/public_html/scripts/fckeditor/_jsp/src/com/fredck/FCKeditor/connector
Added Files:
10b36~ue.html ConnectorServlet.java package.html
Log Message:
complete fckeditor addition
--- NEW FILE: 10b36~ue.html ---
<!--
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: 10b36~ue.html
* FCKeditor Browser connector package description
*
* Version: 2.0 Beta 1
* Modified: 2004-05-30 22:12:00
*
* File Authors:
* Simone Chiaretta (si...@pi...)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.60 98/01/27
Copyright 1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This software is the confidential and proprietary information of Sun
Microsystems, Inc. ("Confidential Information"). You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into
with Sun.
CopyrightVersion 1.2
-->
</head>
<body bgcolor="white">
Connector used by the FCKeditor to list and create resources on the server.
<h2>Package Specification</h2>
This servlet is access directly from the file browser in the FCKeditor.<br>
To make everything work correctly you have to add the following piece of code in your application's web.xml
<br>
<pre>
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>
</pre>
<br>
And put in the fckconfig.js the following line:
<pre>
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ;
</pre>
Also, since the servlet manage a file upload using the Jakarta Common fileupload library, you need to put in your <code>WEB-INF/lib/</code> the <code>commons-fileupload.jar</code>.
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li>_sample/jsp directory for example of how to implement FCKEditor in your application
</ul>
<!-- Put @see and @since tags down here. -->
</body>
</html>
--- NEW FILE: ConnectorServlet.java ---
/*
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: ConnectorServlet.java
* Connector used to browse and upload files.
*
* Version: 2.0 Beta 1
* Modified: 2004-05-30 21:52:18
*
* File Authors:
* Simone Chiaretta (si...@pi...)
*/
package com.fredck.FCKeditor.connector;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import org.apache.commons.fileupload.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
/**
* Servlet to upload and browse files.<br>
*
* This servlet accepts 4 commands used to retrieve and create files and folders from a server directory.
* The allowed commands are:
* <ul>
* <li>GetFolders: Retrive the list of directory under the current folder
* <li>GetFoldersAndFiles: Retrive the list of files and directory under the current folder
* <li>CreateFolder: Create a new directory under the current folder
* <li>FileUpload: Send a new file to the server (must be sent with a POST)
* </ul>
*
* @author Simone Chiaretta (si...@pi...)
*/
public class ConnectorServlet extends HttpServlet {
private static String baseDir;
/**
* Initialize the servlet.<br>
* Retrieve from the servlet configuration the "baseDir" which is the root of the file repository:<br>
* If not specified the value of "/UserFiles/" will be used.
*
* @author Simone Chiaretta (si...@pi...)
*/
public void init() throws ServletException {
baseDir=getInitParameter("baseDir");
if(baseDir==null)
baseDir="/UserFiles/";
String realBaseDir=getServletContext().getRealPath(baseDir);
File baseFile=new File(realBaseDir);
if(!baseFile.exists()){
baseFile.mkdir();
}
}
/**
* Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).<br>
*
* The servlet accepts commands sent in the following format:<br>
* connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br><br>
* It execute the command and then return the results to the client in XML format.
*
* @author Simone Chiaretta (si...@pi...)
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml");
response.setHeader("Cache-Control","no-cache");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String commandStr=request.getParameter("Command");
String typeStr=request.getParameter("Type");
String currentFolderStr=request.getParameter("CurrentFolder");
String currentPath=baseDir+typeStr+currentFolderStr;
String currentDirPath=getServletContext().getRealPath(currentPath);
File currentDir=new File(currentDirPath);
if(!currentDir.exists()){
currentDir.mkdir();
}
Document document=null;
try {
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document=builder.newDocument();
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
}
Node root=CreateCommonXml(document,commandStr,typeStr,currentFolderStr,currentPath);
if(commandStr.equals("GetFolders")) {
getFolders(currentDir,root,document);
}
else if (commandStr.equals("GetFoldersAndFiles")) {
getFolders(currentDir,root,document);
getFiles(currentDir,root,document);
}
else if (commandStr.equals("CreateFolder")) {
String newFolderStr=request.getParameter("NewFolderName");
File newFolder=new File(currentDir,newFolderStr);
String retValue="110";
if(newFolder.exists()){
retValue="101";
}
else {
try {
boolean dirCreated = newFolder.mkdir();
if(dirCreated)
retValue="0";
else
retValue="102";
}catch(SecurityException sex) {
retValue="103";
}
}
setCreateFolderResponse(retValue,root,document);
}
document.getDocumentElement().normalize();
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
} catch (Exception ex) {
ex.printStackTrace();
}
out.flush();
out.close();
}
/**
* Manage the Post requests (FileUpload).<br>
*
* The servlet accepts commands sent in the following format:<br>
* connector?Command=FileUpload&Type=ResourceType&CurrentFolder=FolderPath<br><br>
* It store the file (renaming it in case a file with the same name exists) and then return an HTML file
* with a javascript command in it.
*
* @author Simone Chiaretta (si...@pi...)
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setHeader("Cache-Control","no-cache");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
String commandStr=request.getParameter("Command");
String typeStr=request.getParameter("Type");
String currentFolderStr=request.getParameter("CurrentFolder");
String currentPath=baseDir+typeStr+currentFolderStr;
String currentDirPath=getServletContext().getRealPath(currentPath);
String retVal="0";
String newName="";
if(!commandStr.equals("FileUpload"))
retVal="203";
else {
DiskFileUpload upload = new DiskFileUpload();
try {
List items = upload.parseRequest(request);
Map fields=new HashMap();
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField())
fields.put(item.getFieldName(),item.getString());
else
fields.put(item.getFieldName(),item);
}
FileItem uplFile=(FileItem)fields.get("NewFile");
String fileNameLong=uplFile.getName();
fileNameLong=fileNameLong.replace('\\','/');
String[] pathParts=fileNameLong.split("/");
String fileName=pathParts[pathParts.length-1];
String nameWithoutExt=getNameWithoutExtension(fileName);
String ext=getExtension(fileName);
File pathToSave=new File(currentDirPath,fileName);
int counter=1;
while(pathToSave.exists()){
newName=nameWithoutExt+"("+counter+")"+"."+ext;
retVal="201";
pathToSave=new File(currentDirPath,newName);
counter++;
}
uplFile.write(pathToSave);
}catch (Exception ex) {
retVal="203";
}
}
out.println("<script type=\"text/javascript\">");
out.println("window.parent.frames['frmUpload'].OnUploadCompleted("+retVal+",'"+newName+"');");
out.println("</script>");
out.flush();
out.close();
}
private void setCreateFolderResponse(String retValue,Node root,Document doc) {
Element myEl=doc.createElement("Error");
myEl.setAttribute("number",retValue);
root.appendChild(myEl);
}
private void getFolders(File dir,Node root,Document doc) {
Element folders=doc.createElement("Folders");
root.appendChild(folders);
File[] fileList=dir.listFiles();
for(int i=0;i<fileList.length;++i) {
if(fileList[i].isDirectory()){
Element myEl=doc.createElement("Folder");
myEl.setAttribute("name",fileList[i].getName());
folders.appendChild(myEl);
}
}
}
private void getFiles(File dir,Node root,Document doc) {
Element files=doc.createElement("Files");
root.appendChild(files);
File[] fileList=dir.listFiles();
for(int i=0;i<fileList.length;++i) {
if(fileList[i].isFile()){
Element myEl=doc.createElement("File");
myEl.setAttribute("name",fileList[i].getName());
myEl.setAttribute("size",""+fileList[i].length()/1024);
files.appendChild(myEl);
}
}
}
private Node CreateCommonXml(Document doc,String commandStr, String typeStr, String currentPath, String currentUrl ) {
Element root=doc.createElement("Connector");
doc.appendChild(root);
root.setAttribute("command",commandStr);
root.setAttribute("resourceType",typeStr);
Element myEl=doc.createElement("CurrentFolder");
myEl.setAttribute("path",currentPath);
myEl.setAttribute("url",currentUrl);
root.appendChild(myEl);
return root;
}
private String getExtension(String fileName) {
String[] nameParts=fileName.split("\\.");
String ext="";
for (int i=1;i<nameParts.length;++i)
ext+="."+nameParts[i];
if(ext.length()!=0)
ext=ext.substring(1);
return ext;
}
private String getNameWithoutExtension(String fileName) {
String[] nameParts=fileName.split("\\.");
return nameParts[0];
}
}
--- NEW FILE: package.html ---
<!--
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: package.html
* FCKeditor Browser connector package description
*
* Version: 2.0 Beta 1
* Modified: 2004-05-30 22:11:56
*
* File Authors:
* Simone Chiaretta (si...@pi...)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!--
@(#)package.html 1.60 98/01/27
Copyright 1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This software is the confidential and proprietary information of Sun
Microsystems, Inc. ("Confidential Information"). You shall not
disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement you entered into
with Sun.
CopyrightVersion 1.2
-->
</head>
<body bgcolor="white">
Connector used by the FCKeditor to list and create resources on the server.
<h2>Package Specification</h2>
This servlet is access directly from the file browser in the FCKeditor.<br>
To make everything work correctly you have to add the following piece of code in your application's web.xml
<br>
<pre>
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>
</pre>
<br>
And put in the fckconfig.js the following line:
<pre>
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ;
</pre>
Also, since the servlet manage a file upload using the Jakarta Common fileupload library, you need to put in your <code>WEB-INF/lib/</code> the <code>commons-fileupload.jar</code>.
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li>_sample/jsp directory for example of how to implement FCKEditor in your application
</ul>
<!-- Put @see and @since tags down here. -->
</body>
</html>
|