1 package org.kuali.ole.servlet;
2
3 import org.kuali.ole.OleSRUConstants;
4 import org.kuali.ole.PropertyUtil;
5 import org.kuali.ole.service.OleSRUWebService;
6 import org.kuali.ole.serviceimpl.OleSRUWebServiceImpl;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import javax.servlet.ServletException;
11 import javax.servlet.http.HttpServlet;
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14 import java.io.IOException;
15 import java.io.PrintWriter;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21
22
23
24
25
26
27
28 public class OleSRUServlet extends HttpServlet{
29
30 final Logger log = LoggerFactory.getLogger(OleSRUServlet.class);
31
32 @Override
33 public void init() throws ServletException {
34
35 log.info("init method");
36 }
37
38 @Override
39 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
40 doGet(request,response);
41 }
42
43 @Override
44 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
45
46 log.info("doGet method");
47 OleSRUWebService oleSRUWebService=new OleSRUWebServiceImpl();
48 Map reqParamMap=getReqParameters(request);
49 String xml=oleSRUWebService.getOleSRUResponse(reqParamMap);
50 PrintWriter out=response.getWriter();
51 out.write(xml);
52 }
53
54 public Map getReqParameters(HttpServletRequest request) {
55
56
57 HashMap reqParamMap=new HashMap();
58 reqParamMap.put(OleSRUConstants.OPERATION_TYPE,request.getParameter(OleSRUConstants.OPERATION_TYPE));
59 reqParamMap.put(OleSRUConstants.VERSION,request.getParameter(OleSRUConstants.VERSION));
60 reqParamMap.put(OleSRUConstants.QUERY,request.getParameter(OleSRUConstants.QUERY));
61 if((request.getParameter(OleSRUConstants.START_RECORD))!=null && !"".equals(request.getParameter(OleSRUConstants.START_RECORD))) {
62 int startRecord=Integer.parseInt((String)(request.getParameter(OleSRUConstants.START_RECORD)));
63 reqParamMap.put(OleSRUConstants.START_RECORD,startRecord);
64 }else
65 reqParamMap.put(OleSRUConstants.START_RECORD,Integer.parseInt(PropertyUtil.getPropertyUtil().getProperty(OleSRUConstants.STARTRECORD)));
66
67 if((request.getParameter(OleSRUConstants.MAXIMUM_RECORDS))!=null && !"".equals(request.getParameter(OleSRUConstants.MAXIMUM_RECORDS))) {
68 int maxRecord=Integer.parseInt((String)(request.getParameter(OleSRUConstants.MAXIMUM_RECORDS)));
69 reqParamMap.put(OleSRUConstants.MAXIMUM_RECORDS,maxRecord);
70 }else
71 reqParamMap.put(OleSRUConstants.MAXIMUM_RECORDS,Integer.parseInt(PropertyUtil.getPropertyUtil().getProperty(OleSRUConstants.MAXRECORD)));
72
73 if((request.getParameter(OleSRUConstants.RECORD_PACKING))!=null && !"".equals(request.getParameter(OleSRUConstants.RECORD_PACKING))) {
74 String recordPacking=(String)(request.getParameter(OleSRUConstants.RECORD_PACKING));
75 reqParamMap.put(OleSRUConstants.RECORD_PACKING,recordPacking);
76 }else
77 reqParamMap.put(OleSRUConstants.RECORD_PACKING,OleSRUConstants.RECORD_PACK_XML);
78
79 if((request.getParameter(OleSRUConstants.SORTKEYS))!=null && !"".equals(request.getParameter(OleSRUConstants.SORTKEYS))) {
80 String sortKey=(String)(request.getParameter(OleSRUConstants.SORTKEYS));
81 reqParamMap.put(OleSRUConstants.SORTKEYS,sortKey);
82 }else
83 reqParamMap.put(OleSRUConstants.SORTKEYS,OleSRUConstants.TITLE_SORT_KEYS);
84
85 if((request.getParameter(OleSRUConstants.STYLE_SHEET))!=null) {
86 reqParamMap.put(OleSRUConstants.STYLE_SHEET,request.getParameter(OleSRUConstants.STYLE_SHEET));
87 }
88
89 if((request.getParameter(OleSRUConstants.RECORD_SCHEMA))!=null) {
90 if(OleSRUConstants.DC_RECORD_SCHEMA.equals((String)(request.getParameter(OleSRUConstants.RECORD_SCHEMA))))
91 reqParamMap.put(OleSRUConstants.RECORD_SCHEMA,OleSRUConstants.DUBLIN_RECORD_SCHEMA);
92 }
93
94 setExtraRequestData(request,reqParamMap);
95 return reqParamMap;
96
97 }
98
99 public void setExtraRequestData(HttpServletRequest request,Map reqParamMap){
100
101 List<String> reqParams=new ArrayList<String>(request.getParameterMap().keySet());
102 reqParams.remove(OleSRUConstants.OPERATION_TYPE);
103 reqParams.remove(OleSRUConstants.VERSION);
104 reqParams.remove(OleSRUConstants.QUERY);
105 reqParams.remove(OleSRUConstants.START_RECORD);
106 reqParams.remove(OleSRUConstants.MAXIMUM_RECORDS);
107 reqParams.remove(OleSRUConstants.RECORD_PACKING);
108 reqParams.remove(OleSRUConstants.SORTKEYS);
109 reqParams.remove(OleSRUConstants.RECORD_SCHEMA);
110 reqParams.remove(OleSRUConstants.STYLE_SHEET);
111 if(reqParams.size()>0) {
112 String extraDataKeyValue[]=reqParams.get(0).split("-");
113 String extraReqDataKey=extraDataKeyValue[extraDataKeyValue.length-1];
114 String extraReqDataValue=(String)request.getParameter(reqParams.get(0));
115 reqParamMap.put(OleSRUConstants.EXTRA_REQ_DATA_KEY,extraReqDataKey);
116 reqParamMap.put(OleSRUConstants.EXTRA_REQ_DATA_VALUE,extraReqDataValue);
117 }
118
119 }
120 }