01: package com.technoetic.xplanner.actions;
02:
03: import java.io.InputStream;
04: import javax.servlet.http.HttpServletRequest;
05:
06: import org.apache.commons.lang.StringUtils;
07: import org.apache.log4j.Logger;
08: import org.apache.struts.action.ActionForm;
09: import org.apache.struts.upload.FormFile;
10:
11: import com.technoetic.xplanner.domain.Note;
12: import com.technoetic.xplanner.file.Directory;
13: import com.technoetic.xplanner.file.File;
14: import com.technoetic.xplanner.file.FileSystem;
15: import com.technoetic.xplanner.forms.NoteEditorForm;
16:
17: public class EditNoteAction extends EditObjectAction {
18: private FileSystem fileSystem;
19:
20: protected void populateObject(HttpServletRequest request,
21: Object object, ActionForm form) throws Exception {
22: Logger.getLogger(EditNoteAction.class).debug("Populating...");
23:
24: super .populateObject(request, object, form);
25:
26: NoteEditorForm noteForm = (NoteEditorForm) form;
27:
28: FormFile formFile = noteForm.getFormFile();
29: if (formFile != null) {
30: String filename = formFile.getFileName();
31: if (StringUtils.isNotEmpty(filename)) {
32: String contentType = formFile.getContentType();
33: InputStream input = formFile.getInputStream();
34: int fileSize = formFile.getFileSize();
35: int projectId = request.getParameter("projectId") != null ? Integer
36: .parseInt(request.getParameter("projectId"))
37: : 0;
38: Directory directory = fileSystem
39: .getDirectory("/attachments/project/"
40: + projectId);
41: File file = fileSystem.createFile(directory, filename,
42: contentType, fileSize, input);
43: Note note = (Note) object;
44: note.setFile(file);
45:
46: Logger.getLogger(EditNoteAction.class).debug(
47: "Saving note: filename=" + filename
48: + ", fileSize=" + fileSize
49: + ", contentType=" + contentType);
50:
51: }
52: }
53: }
54:
55: public void setFileSystem(FileSystem fileSystem) {
56: this.fileSystem = fileSystem;
57: }
58: }
|