1 /*
2 * Copyright 2011 The Kuali Foundation.
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.web;
17
18 import javax.servlet.ServletException;
19 import javax.servlet.http.HttpServlet;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import java.io.IOException;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 /**
27 * Created by IntelliJ IDEA.
28 * User: Peri Subrahmanya
29 * Date: 3/31/11
30 * Time: 8:11 AM
31 * To change this template use File | Settings | File Templates.
32 */
33 public class InjestServlet extends HttpServlet {
34 private static final long serialVersionUID = 1L;
35 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InjestServlet.class);
36 Map<String, String> fieldsMap;
37
38 @Override
39 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
40 // List<FileItem> items = null;
41 // try {
42 // items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(req);
43 // } catch (FileUploadException e) {
44 // throw new ServletException("Cannot parse multipart request.", e);
45 // }
46 // // Need to loop over all the "regular" fields first, so that we have
47 // // their values for the code below
48 // for (FileItem item : items) {
49 // if (item.isFormField()) {
50 // getFieldsMap().put(item.getFieldName(), item.getString().toLowerCase());
51 // }
52 // }
53 // for (FileItem item : items) {
54 // if (!item.isFormField()) {
55 // String filename = FilenameUtils.getName(item.getName());
56 // //File file = File.createTempFile(filename, "");
57 // File tempDir = new File(getDocumentStoreContentManager()
58 // .getDocumentManager().getIngestFolder(
59 // getFieldsMap().get("category"),
60 // getFieldsMap().get("format")));
61 // File file = File.createTempFile(filename, "", tempDir);
62 // try {
63 // item.write(file);
64 // Map<String, String> uuidMap = getDocumentStoreContentManager()
65 // .persistBulk(getFieldsMap().get("category"),
66 // getFieldsMap().get("format"), file, "webappUser", "InjestServlet.doPost()");
67 // req.setAttribute("mapResults", uuidMap);
68 // req.setAttribute("fileName", filename);
69 // } catch (Exception e) {
70 // LOG.error("Problem ingesting the file! Please refer application logs for details",e);
71 // PrintWriter out = resp.getWriter();
72 // out.println("Problem ingesting the file! Please refer application logs for details");
73 // out.flush();
74 // out.close();
75 // } finally {
76 // file.delete();
77 // }
78 // }
79 // }
80 // RequestDispatcher rd = getServletContext().getRequestDispatcher("/injestResults.jsp");
81 // rd.forward(req, resp);
82 }
83
84 public Map<String, String> getFieldsMap() {
85 if (null == fieldsMap) {
86 fieldsMap = new HashMap<String, String>();
87 }
88 return fieldsMap;
89 }
90 }