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.repository.DocumentStoreManager;
19  
20  import javax.servlet.ServletException;
21  import javax.servlet.http.HttpServlet;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import java.io.IOException;
25  import java.io.PrintWriter;
26  
27  /**
28  * User: Peri Subrahmanya
29  * Date: 4/7/11
30  * Time: 11:30 AM
31  * To change this template use File | Settings | File Templates.
32  */
33  public class CheckoutServlet extends HttpServlet {
34  
35      @Override
36      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
37          String uuid = req.getParameter("uuid");
38          callService(resp, uuid);
39      }
40  
41      private void callService(HttpServletResponse resp, String uuid) throws IOException {
42          try {
43              String checkedOutContent = new DocumentStoreManager().checkOut(uuid, "webappUser", "CheckoutServlet.callService()");
44              resp.setCharacterEncoding("UTF-8");
45              PrintWriter out = resp.getWriter();
46              out.println(checkedOutContent);
47              out.flush();
48              out.close();
49          } catch (Exception e) {
50              e.printStackTrace();
51              PrintWriter out = resp.getWriter();
52              out.println("Problem checking the file! Please refer application logs for details");
53              out.flush();
54              out.close();
55          }
56      }
57  }