Index: lams_central/conf/xdoclet/servlet-mappings.xml =================================================================== diff -u -r8f6d6a60fc7c387a228d25067500c316e3bff68b -rdf67712bc22a94b9af5da6ba10fe6c4557a228fa --- lams_central/conf/xdoclet/servlet-mappings.xml (.../servlet-mappings.xml) (revision 8f6d6a60fc7c387a228d25067500c316e3bff68b) +++ lams_central/conf/xdoclet/servlet-mappings.xml (.../servlet-mappings.xml) (revision df67712bc22a94b9af5da6ba10fe6c4557a228fa) @@ -3,19 +3,7 @@ *.do - - Connector - /fckeditor/editor/filemanager/browser/default/connectors/jsp/connector - - - - - SimpleUploader - /fckeditor/editor/filemanager/upload/simpleuploader - - - download /download/* \ No newline at end of file Index: lams_central/conf/xdoclet/servlets.xml =================================================================== diff -u -r9b86062d232d20d13b9f4052a48852090d18934e -rdf67712bc22a94b9af5da6ba10fe6c4557a228fa --- lams_central/conf/xdoclet/servlets.xml (.../servlets.xml) (revision 9b86062d232d20d13b9f4052a48852090d18934e) +++ lams_central/conf/xdoclet/servlets.xml (.../servlets.xml) (revision df67712bc22a94b9af5da6ba10fe6c4557a228fa) @@ -20,66 +20,7 @@ 1 - - - Connector - org.lamsfoundation.lams.authoring.web.LAMSConnectorServlet - - baseDir - secure - - - debug - true - - 1 - - - - - SimpleUploader - org.lamsfoundation.lams.authoring.web.LAMSUploadServlet - - baseDir - secure - - - debug - true - - - enabled - true - - - AllowedExtensionsFile - - - - DeniedExtensionsFile - php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi - - - AllowedExtensionsImage - jpg|gif|jpeg|png|bmp - - - DeniedExtensionsImage - - - - AllowedExtensionsFlash - swf|fla - - - DeniedExtensionsFlash - - - 1 - - - Instructions Download Instructions Download download Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringConstants.java =================================================================== diff -u -re21e46d35a751657ff3b63704419ad212747425e -rdf67712bc22a94b9af5da6ba10fe6c4557a228fa --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringConstants.java (.../AuthoringConstants.java) (revision e21e46d35a751657ff3b63704419ad212747425e) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringConstants.java (.../AuthoringConstants.java) (revision df67712bc22a94b9af5da6ba10fe6c4557a228fa) @@ -39,5 +39,6 @@ // used for tool content folder creation. public static final String LAMS_WWW_DIR = "lams-www.war"; + public static final String LAMS_WWW_FOLDER = "www/"; public static final String LAMS_WWW_SECURE_DIR = "secure"; } Fisheye: Tag df67712bc22a94b9af5da6ba10fe6c4557a228fa refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/authoring/web/LAMSConnectorServlet.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag df67712bc22a94b9af5da6ba10fe6c4557a228fa refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/authoring/web/LAMSUploadServlet.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java (revision df67712bc22a94b9af5da6ba10fe6c4557a228fa) @@ -0,0 +1,360 @@ +/* + * FCKeditor - The text editor for internet + * Copyright (C) 2003-2005 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 + * Java Connector for Resource Manager class. + * + * Version: 2.3 + * Modified: 2005-08-11 16:29:00 + * + * File Authors: + * Simone Chiaretta (simo@users.sourceforge.net) + */ + +package org.lamsfoundation.lams.web; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.lamsfoundation.lams.authoring.web.AuthoringConstants; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; + +import org.apache.commons.fileupload.DiskFileUpload; +import org.apache.commons.fileupload.FileItem; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Servlet to upload and browse files.
+ * + * This servlet accepts 4 commands used to retrieve and create files and folders from a server directory. + * The allowed commands are: + * + * + * @author Simone Chiaretta (simo@users.sourceforge.net) + * @author Mitchell Seaton + * + * @web:servlet name="Connector" load-on-startup = "1" + * @web.servlet-init-param name = "baseDir" + * value = "secure" + * @web.servlet-init-param name = "debug" + * value = "true" + * + * @web:servlet-mapping url-pattern="/fckeditor/editor/filemanager/browser/default/connectors/jsp/connector" + + */ + +public class LAMSConnectorServlet extends HttpServlet { + + private static String baseDir; + private String realBaseDir; + private static boolean debug=false; + + /** + * Initialize the servlet.
+ * Retrieve from the servlet configuration the "baseDir" which is the root of the file repository:
+ * If not specified the value of "/UserFiles/" will be used. + * + */ + public void init() throws ServletException { + baseDir=getInitParameter("baseDir"); + debug=(new Boolean(getInitParameter("debug"))).booleanValue(); + + if(baseDir==null) + baseDir="secure"; + + realBaseDir = Configuration.get(ConfigurationKeys.LAMS_EAR_DIR) + File.separator + AuthoringConstants.LAMS_WWW_DIR + File.separator + baseDir; + + File baseFile=new File(realBaseDir); + if(!baseFile.exists()){ + baseFile.mkdir(); + } + } + + /** + * Manage the Get requests (GetFolders, GetFoldersAndFiles, CreateFolder).
+ * + * The servlet accepts commands sent in the following format:
+ * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath

+ * It execute the command and then return the results to the client in XML format. + * + */ + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + if (debug) System.out.println("--- BEGIN DOGET ---"); + + response.setContentType("text/xml; charset=UTF-8"); + response.setHeader("Cache-Control","no-cache"); + PrintWriter out = response.getWriter(); + + String commandStr=request.getParameter("Command"); + String typeStr=request.getParameter("Type"); + String currentFolderStr=request.getParameter("CurrentFolder"); + + // create content directory if non-existant + String currentDirPath=realBaseDir + currentFolderStr; + String validCurrentDirPath = currentDirPath.replace('/', File.separatorChar); + + String currentWebPath= Configuration.get(ConfigurationKeys.SERVER_URL) + AuthoringConstants.LAMS_WWW_FOLDER + AuthoringConstants.LAMS_WWW_SECURE_DIR + currentFolderStr + typeStr + "/"; + + File currentContentDir=new File(validCurrentDirPath); + if(!currentContentDir.exists()){ + currentContentDir.mkdir(); + } + + // create content type directory if non-existant + validCurrentDirPath += typeStr; + + File currentDir=new File(validCurrentDirPath); + 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,currentWebPath); + + if (debug) System.out.println("Command = " + commandStr); + + 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); + + if (debug) { + StreamResult dbgResult = new StreamResult(System.out); + transformer.transform(source, dbgResult); + System.out.println(""); + System.out.println("--- END DOGET ---"); + } + + + } catch (Exception ex) { + ex.printStackTrace(); + } + + + out.flush(); + out.close(); + } + + + /** + * Manage the Post requests (FileUpload).
+ * + * The servlet accepts commands sent in the following format:
+ * connector?Command=FileUpload&Type=ResourceType&CurrentFolder=FolderPath

+ * 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. + * + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + if (debug) System.out.println("--- BEGIN DOPOST ---"); + + response.setContentType("text/html; charset=UTF-8"); + response.setHeader("Cache-Control","no-cache"); + PrintWriter out = response.getWriter(); + + String commandStr=request.getParameter("Command"); + String typeStr=request.getParameter("Type"); + String currentFolderStr=request.getParameter("CurrentFolder"); + + String currentDirPath=realBaseDir + currentFolderStr + typeStr; + String validCurrentDirPath = currentDirPath.replace("/", File.separator); + + if (debug) System.out.println(currentDirPath); + + 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(validCurrentDirPath,fileName); + int counter=1; + while(pathToSave.exists()){ + newName=nameWithoutExt+"("+counter+")"+"."+ext; + retVal="201"; + pathToSave=new File(validCurrentDirPath,newName); + counter++; + } + uplFile.write(pathToSave); + }catch (Exception ex) { + retVal="203"; + } + + } + + out.println(""); + out.flush(); + out.close(); + + if (debug) System.out.println("--- END DOPOST ---"); + + } + + 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 + * + * This servlet accepts just file uploads, eventually with a parameter specifying file type + * + * @author Simone Chiaretta (simo@users.sourceforge.net) + * @author Mitchell Seaton + * + * @web:servlet name="SimpleUploader" load-on-startup = "1" + * @web.servlet-init-param name = "baseDir" + * value = "secure" + * @web.servlet-init-param name = "debug" + * value = "true" + * @web.servlet-init-param name = "enabled" + * value = "true" + * @web.servlet-init-param name = "AllowedExtensionsFile" + * value = "" + * @web.servlet-init-param name = "DeniedExtensionsFile" + * value = "php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cg" + * @web.servlet-init-param name = "AllowedExtensionsImage" + * value = "jpg|gif|jpeg|png|bmp" + * @web.servlet-init-param name = "DeniedExtensionsImage" + * value = "" + * @web.servlet-init-param name = "AllowedExtensionsFlash" + * value = "swf|fla" + * @web.servlet-init-param name = "DeniedExtensionsFlash" + * value = "" + * @web:servlet-mapping url-pattern="/fckeditor/editor/filemanager/upload/simpleuploader" + * + */ + +public class LAMSUploadServlet extends HttpServlet { + + private static String baseDir; + private String realBaseDir; + private static boolean debug=false; + private static boolean enabled=false; + private static Hashtable allowedExtensions; + private static Hashtable deniedExtensions; + + /** + * Initialize the servlet.
+ * Retrieve from the servlet configuration the "baseDir" which is the root of the file repository:
+ * If not specified the value of "/UserFiles/" will be used.
+ * Also it retrieve all allowed and denied extensions to be handled. + * + */ + public void init() throws ServletException { + + debug=(new Boolean(getInitParameter("debug"))).booleanValue(); + + if(debug) System.out.println("\r\n---- SimpleUploaderServlet initialization started ----"); + + baseDir=getInitParameter("baseDir"); + enabled=(new Boolean(getInitParameter("enabled"))).booleanValue(); + + if(baseDir==null) + baseDir="secure"; + + realBaseDir = Configuration.get(ConfigurationKeys.LAMS_EAR_DIR) + File.separator + AuthoringConstants.LAMS_WWW_DIR + File.separator + baseDir; + + File baseFile=new File(realBaseDir); + if(!baseFile.exists()){ + baseFile.mkdir(); + } + + allowedExtensions = new Hashtable(3); + deniedExtensions = new Hashtable(3); + + allowedExtensions.put("File",stringToArrayList(getInitParameter("AllowedExtensionsFile"))); + deniedExtensions.put("File",stringToArrayList(getInitParameter("DeniedExtensionsFile"))); + + allowedExtensions.put("Image",stringToArrayList(getInitParameter("AllowedExtensionsImage"))); + deniedExtensions.put("Image",stringToArrayList(getInitParameter("DeniedExtensionsImage"))); + + allowedExtensions.put("Flash",stringToArrayList(getInitParameter("AllowedExtensionsFlash"))); + deniedExtensions.put("Flash",stringToArrayList(getInitParameter("DeniedExtensionsFlash"))); + + if(debug) System.out.println("---- SimpleUploaderServlet initialization completed ----\r\n"); + + } + + + /** + * Manage the Upload requests.
+ * + * The servlet accepts commands sent in the following format:
+ * simpleUploader?Type=ResourceType

+ * 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. + * + */ + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + if (debug) System.out.println("--- BEGIN DOPOST ---"); + + response.setContentType("text/html; charset=UTF-8"); + response.setHeader("Cache-Control","no-cache"); + PrintWriter out = response.getWriter(); + + + String typeStr=request.getParameter("Type"); + String currentFolderStr=request.getParameter("CurrentFolder"); + + //String currentPath=baseDir+typeStr; + //String currentDirPath=getServletContext().getRealPath(currentPath); + //currentPath=request.getContextPath()+currentPath; + + // create content directory if non-existant + String currentDirPath=realBaseDir + currentFolderStr; + String validCurrentDirPath = currentDirPath.replace('/', File.separatorChar); + + String currentWebPath= Configuration.get(ConfigurationKeys.SERVER_URL) + AuthoringConstants.LAMS_WWW_FOLDER + AuthoringConstants.LAMS_WWW_SECURE_DIR + currentFolderStr + typeStr; + + File currentContentDir=new File(validCurrentDirPath); + if(!currentContentDir.exists()){ + currentContentDir.mkdir(); + } + + // create content type directory if non-existant + validCurrentDirPath += typeStr; + + File currentDir=new File(validCurrentDirPath); + if(!currentDir.exists()){ + currentDir.mkdir(); + } + + if (debug) System.out.println(currentDirPath); + + String retVal="0"; + String newName=""; + String fileUrl=""; + String errorMessage=""; + + if(enabled) { + 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(validCurrentDirPath,fileName); + fileUrl=currentWebPath+'/'+fileName; + if(extIsAllowed(typeStr,ext)) { + int counter=1; + while(pathToSave.exists()){ + newName=nameWithoutExt+"("+counter+")"+"."+ext; + fileUrl=currentWebPath+'/'+newName; + retVal="201"; + pathToSave=new File(currentDirPath,newName); + counter++; + } + uplFile.write(pathToSave); + } + else { + retVal="202"; + errorMessage=""; + if (debug) System.out.println("Invalid file type: " + ext); + } + }catch (Exception ex) { + if (debug) ex.printStackTrace(); + retVal="203"; + } + } + else { + retVal="1"; + errorMessage="This file uploader is disabled. Please check the WEB-INF/web.xml file"; + } + + + out.println(""); + out.flush(); + out.close(); + + if (debug) System.out.println("--- END DOPOST ---"); + + } + + + /* + * This method was fixed after Kris Barnhoorn (kurioskronic) submitted SF bug #991489 + */ + private static String getNameWithoutExtension(String fileName) { + return fileName.substring(0, fileName.lastIndexOf(".")); + } + + /* + * This method was fixed after Kris Barnhoorn (kurioskronic) submitted SF bug #991489 + */ + private String getExtension(String fileName) { + return fileName.substring(fileName.lastIndexOf(".")+1); + } + + + + /** + * Helper function to convert the configuration string to an ArrayList. + */ + + private ArrayList stringToArrayList(String str) { + + if(debug) System.out.println(str); + String[] strArr=str.split("\\|"); + + ArrayList tmp=new ArrayList(); + if(str.length()>0) { + for(int i=0;i + SimpleUploader + org.lamsfoundation.lams.web.LAMSUploadServlet + + + baseDir + secure + + + debug + true + + + enabled + true + + + AllowedExtensionsFile + + + + DeniedExtensionsFile + php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cg + + + AllowedExtensionsImage + jpg|gif|jpeg|png|bmp + + + DeniedExtensionsImage + + + + AllowedExtensionsFlash + swf|fla + + + DeniedExtensionsFlash + + + + 1 + + + storeNotebookEntry org.lamsfoundation.lams.notebook.web.StoreNBEntryServlet + Connector + org.lamsfoundation.lams.web.LAMSConnectorServlet + + + baseDir + secure + + + debug + true + + + 1 + + + flashCrashDump org.lamsfoundation.lams.web.FlashCrashDumpServlet @@ -117,66 +177,7 @@ 1 - - - Connector - org.lamsfoundation.lams.authoring.web.LAMSConnectorServlet - - baseDir - secure - - - debug - true - - 1 - - - - - SimpleUploader - org.lamsfoundation.lams.authoring.web.LAMSUploadServlet - - baseDir - secure - - - debug - true - - - enabled - true - - - AllowedExtensionsFile - - - - DeniedExtensionsFile - php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi - - - AllowedExtensionsImage - jpg|gif|jpeg|png|bmp - - - DeniedExtensionsImage - - - - AllowedExtensionsFlash - swf|fla - - - DeniedExtensionsFlash - - - 1 - - - Instructions Download Instructions Download download @@ -193,19 +194,7 @@ *.do - - Connector - /fckeditor/editor/filemanager/browser/default/connectors/jsp/connector - - - - - SimpleUploader - /fckeditor/editor/filemanager/upload/simpleuploader - - - download /download/* @@ -223,10 +212,18 @@ /dumpWDDX + SimpleUploader + /fckeditor/editor/filemanager/upload/simpleuploader + + storeNotebookEntry /notebook/storeNotebookEntry + Connector + /fckeditor/editor/filemanager/browser/default/connectors/jsp/connector + + flashCrashDump /flashCrashDump Index: lams_central/web/fckeditor/editor/filemanager/browser/default/browser.html =================================================================== diff -u -rcbb1944b89d093e3b7a2dca7f7a46476cf08c585 -rdf67712bc22a94b9af5da6ba10fe6c4557a228fa --- lams_central/web/fckeditor/editor/filemanager/browser/default/browser.html (.../browser.html) (revision cbb1944b89d093e3b7a2dca7f7a46476cf08c585) +++ lams_central/web/fckeditor/editor/filemanager/browser/default/browser.html (.../browser.html) (revision df67712bc22a94b9af5da6ba10fe6c4557a228fa) @@ -136,13 +136,13 @@ - + - - - - - + + + + +