1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.web;
17
18 import org.apache.commons.fileupload.FileItem;
19 import org.apache.commons.fileupload.FileUploadException;
20 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
21 import org.apache.commons.fileupload.servlet.ServletFileUpload;
22 import org.apache.commons.io.FilenameUtils;
23
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServlet;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import java.io.IOException;
29 import java.util.*;
30
31
32
33
34
35
36
37 public class CheckinServlet extends HttpServlet {
38 private static final String RESULTS_JSP =
39 "/checkinResults.jsp";
40 private Map<String, String> fieldsMap;
41 private HashMap<String, FileItem> fileItemMap;
42
43 @Override
44 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
45 List<FileItem> items = null;
46 try {
47 items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(req);
48 } catch (FileUploadException e) {
49 throw new ServletException("Cannot parse multipart request.", e);
50 }
51 for (FileItem item : items) {
52 if (item.isFormField()) {
53 getFieldsMap().put(item.getFieldName(), item.getString());
54 }
55 }
56
57 for (FileItem item : items) {
58 String filename = FilenameUtils.getName(item.getName());
59 fileItemMap = new HashMap<String, FileItem>();
60 fileItemMap.put(filename, item);
61 getFieldsMap().put("fileName", filename);
62 }
63 callService(req, resp);
64 }
65
66 private void callService(HttpServletRequest req, HttpServletResponse resp) throws IOException {
67
68
69
70
71
72
73
74
75
76
77
78
79 }
80
81 public Map<String, String> getFieldsMap() {
82 if (null == fieldsMap) {
83 fieldsMap = new HashMap<String, String>();
84 }
85 return fieldsMap;
86 }
87
88 private String getUUID() {
89 Set<String> strings = getFieldsMap().keySet();
90 for (Iterator<String> iterator = strings.iterator(); iterator.hasNext();) {
91 String key = iterator.next();
92 if (key.equals("uuid")) {
93 return getFieldsMap().get(key);
94 }
95 }
96 return null;
97 }
98
99 public HashMap<String, FileItem> getFileItemMap() {
100 return fileItemMap;
101 }
102
103 public FileItem getItem() {
104 String fileName = getFieldsMap().get("fileName");
105 return getFileItemMap().get(fileName);
106 }
107 }