Index: lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java
===================================================================
RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java,v
diff -u -r1.9 -r1.9.4.1
--- lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java 13 Feb 2009 04:56:53 -0000 1.9
+++ lams_central/src/java/org/lamsfoundation/lams/web/LAMSConnectorServlet.java 29 Apr 2009 06:34:28 -0000 1.9.4.1
@@ -20,16 +20,21 @@
package org.lamsfoundation.lams.web;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
@@ -40,13 +45,19 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.jfree.util.Log;
import org.lamsfoundation.lams.authoring.web.AuthoringConstants;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.Base64StringToImageUtil;
import org.lamsfoundation.lams.util.Configuration;
import org.lamsfoundation.lams.util.ConfigurationKeys;
import org.lamsfoundation.lams.util.FileUtil;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -258,56 +269,107 @@
String retVal="0";
String newName="";
- if(!commandStr.equals("FileUpload") || !isEnabled(currentFolderStr))
- 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";
- }
+ try {
+ if(commandStr.equals("PaintUpload"))
+ newName = createNewPaint(validCurrentDirPath, request);
+ if(!commandStr.equals("FileUpload") || !isEnabled(currentFolderStr))
+ throw new Exception();
+ else
+ newName = createNewFile(validCurrentDirPath, request);
+ retVal="201";
+ } catch(Exception ex) {
+ if(debug) System.out.println(ex.getMessage());
+ retVal="203";
}
- out.println("");
- out.flush();
- out.close();
+ if(!commandStr.equals("PaintUpload")) {
+ out.println("");
+ out.flush();
+ out.close();
+ } else {
+ // send back URL to new Paint file
+
+ }
if (debug) System.out.println("--- END DOPOST ---");
}
+
+ private String createNewFile(String validCurrentDirPath, HttpServletRequest request) throws FileUploadException, IOException, Exception {
+ if (debug) System.out.println("--- BEGIN FILE SAVE ---");
+ String newName = "";
+ DiskFileUpload upload = new DiskFileUpload();
+ 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()){
+ fileName = nameWithoutExt+"_"+counter+"."+ext;
+ pathToSave = new File(validCurrentDirPath, fileName);
+ counter++;
+ }
+
+ uplFile.write(pathToSave);
+
+ if (debug) System.out.println("--- END FILE SAVE ---");
+
+ return fileName;
+ }
+ private String createNewPaint(String validCurrentDirPath, HttpServletRequest request) throws IOException {
+ if (debug) System.out.println("--- BEGIN PAINT SAVE ---");
+
+ String extension = "png";
+ String nameWithoutExt = getUserID() + "_" + String.valueOf(new Date().getTime());
+ String fileName = nameWithoutExt + "." + extension;
+
+ File pathToSave = new File(validCurrentDirPath, fileName);
+
+ int counter=1;
+ while(pathToSave.exists()){
+ fileName = nameWithoutExt+"_"+counter+"."+extension;
+ pathToSave = new File(validCurrentDirPath, fileName);
+ counter++;
+ }
+
+ if(Base64StringToImageUtil.store(validCurrentDirPath, nameWithoutExt, extension, request.getInputStream())) {
+ // file created
+ if (debug) System.out.println("--- File created: " + fileName + " ---");
+
+ } else {
+ // send error
+ if (debug) System.out.println("--- Error occurred writing to file: " + fileName + " ---");
+ }
+
+ if (debug) System.out.println("--- END PAINT SAVE ---");
+
+ return fileName;
+ }
+
private void setCreateFolderResponse(String retValue,Node root,Document doc) {
Element myEl=doc.createElement("Error");
myEl.setAttribute("number",retValue);
@@ -383,5 +445,12 @@
realBaseDir = Configuration.get(ConfigurationKeys.LAMS_EAR_DIR) + File.separator + FileUtil.LAMS_WWW_DIR + File.separator + baseDir;
lamsContextPath = "/" + Configuration.get(ConfigurationKeys.SERVER_URL_CONTEXT_PATH) +"/";
}
+
+ private String getUserID() {
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ return user != null ? user.getUserID().toString() : "";
+ }
+
}
Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_central/web/fckeditor/editor/plugins/paint/content.jsp'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_central/web/includes/javascript/fckconfig_custom.js
===================================================================
RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/Attic/fckconfig_custom.js,v
diff -u -r1.20.2.1 -r1.20.2.2
--- lams_central/web/includes/javascript/fckconfig_custom.js 14 Apr 2009 02:39:26 -0000 1.20.2.1
+++ lams_central/web/includes/javascript/fckconfig_custom.js 29 Apr 2009 06:34:28 -0000 1.20.2.2
@@ -1,6 +1,6 @@
FCKConfig.ToolbarSets["Default"] = [
['Source','-','FitWindow', 'Preview','PasteWord','Undo','Redo','Bold','Italic','Underline', '-','Subscript','Superscript','OrderedList','UnorderedList','-','Outdent','Indent','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','TextColor','BGColor','Equation'],
- ['MoviePlayer','VideoRecorder','Image','Link','Table','Rule','Smiley','SpecialChar','Templates','FontFormat','FontName','FontSize','About']
+ ['Paint_Button','MoviePlayer','VideoRecorder','Image','Link','Table','Rule','Smiley','SpecialChar','Templates','FontFormat','FontName','FontSize','About']
] ;
FCKConfig.ToolbarSets["Default-Learner"] = [
@@ -46,3 +46,4 @@
FCKConfig.Plugins.Add('equation', 'en');
FCKConfig.Plugins.Add('movieplayer', 'en');
FCKConfig.Plugins.Add('videorecorder', 'en');
+FCKConfig.Plugins.Add('paint', 'en');
\ No newline at end of file
Index: lams_common/src/java/org/lamsfoundation/lams/util/Base64StringToImageUtil.java
===================================================================
RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/util/Base64StringToImageUtil.java,v
diff -u -r1.1.2.2 -r1.1.2.3
--- lams_common/src/java/org/lamsfoundation/lams/util/Base64StringToImageUtil.java 17 Apr 2009 08:21:20 -0000 1.1.2.2
+++ lams_common/src/java/org/lamsfoundation/lams/util/Base64StringToImageUtil.java 29 Apr 2009 06:33:48 -0000 1.1.2.3
@@ -47,4 +47,31 @@
return false;
}
+
+ public static boolean store(String dir, String filename, String ext, InputStream in) {
+ try {
+ BufferedImage image = javax.imageio.ImageIO.read(in);
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ try {
+ // put buffer data into byte output stream
+ ImageIO.write(image, ext, os);
+ byte[] imagebytes = os.toByteArray();
+
+ // write bytes into file
+ FileOutputStream fileos = new FileOutputStream(new File(dir + filename + "." + ext));
+ fileos.write(imagebytes);
+ fileos.close();
+
+ return true;
+ }catch (Exception e) {
+ log.error(e);
+ }
+ }catch (Exception e) {
+ log.error(e);
+ }
+
+ return false;
+ }
}