View Javadoc

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 org.kuali.ole.RepositoryBrowser;
19  
20  import javax.servlet.RequestDispatcher;
21  import javax.servlet.ServletException;
22  import javax.servlet.http.HttpServlet;
23  import javax.servlet.http.HttpServletRequest;
24  import javax.servlet.http.HttpServletResponse;
25  import java.io.IOException;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30  * Created by IntelliJ IDEA.
31  * User: peris
32  * Date: 5/23/11
33  * Time: 1:37 PM
34  * To change this template use File | Settings | File Templates.
35  */
36  public class GetUUIDServlet extends HttpServlet {
37      private static final String RESULTS_JSP =
38              "/getUUIDResults.jsp";
39      private RepositoryBrowser repositoryBrowser;
40  
41      @Override
42      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
43          List<String> uuidsList = new ArrayList<String>();
44          String category = req.getParameter("category");
45          String type = req.getParameter("type");
46          String format = req.getParameter("format");
47          String numUUIDs = req.getParameter("numUUIDs");
48          try {
49              if (null!= category && null!= format && null!=numUUIDs) {
50                  uuidsList = getRepositoryBrowser().getUUIDs(category.toLowerCase(), type.toLowerCase(), format.toLowerCase(), new Integer(numUUIDs));
51              }
52          } catch (Exception e) {
53              uuidsList.add(e.getMessage());
54          }
55          RequestDispatcher rd = getServletContext().getRequestDispatcher(RESULTS_JSP);
56          req.setAttribute("result", uuidsList);
57          rd.forward(req, resp);
58      }
59  
60  
61      public RepositoryBrowser getRepositoryBrowser() {
62          if (null == repositoryBrowser) {
63              repositoryBrowser = new RepositoryBrowser();
64          }
65          return repositoryBrowser;
66      }
67  }