View Javadoc

1   package org.kuali.ole.docstore.discovery.servlet;
2   
3   /**
4    * Created by IntelliJ IDEA.
5    * User: SG7940
6    * Date: 6/26/12
7    * Time: 5:17 PM
8    * To change this template use File | Settings | File Templates.
9    */
10  
11  
12  import javax.servlet.ServletException;
13  import javax.servlet.ServletOutputStream;
14  import javax.servlet.http.HttpServlet;
15  import javax.servlet.http.HttpServletRequest;
16  import javax.servlet.http.HttpServletResponse;
17  import java.io.BufferedInputStream;
18  import java.io.File;
19  import java.io.FileInputStream;
20  import java.io.IOException;
21  
22  /**
23   * Class for getting configuration info about document categories, types, formats etc.
24   */
25  public class DocumentConfigServlet  extends HttpServlet {
26  
27       private static final long serialVersionUID = 1L;
28  
29       /**
30       * @see javax.servlet.http.HttpServlet#HttpServlet()
31       */
32      public  DocumentConfigServlet() {
33          super();
34      }
35  
36      /**
37       * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse
38       *      response)
39       */
40  
41  
42      public void doGet(HttpServletRequest request,
43                            HttpServletResponse response) throws  ServletException,IOException {
44             doPost(request,response);
45      }
46      public void doPost(HttpServletRequest request,
47                            HttpServletResponse response) throws ServletException, IOException {
48  
49          ServletOutputStream outputStream = null;
50          BufferedInputStream inputStream = null;
51          try {
52              outputStream = response.getOutputStream();
53              String documentConfigFilePath = System.getProperty("document.config.file");
54              File docSearchConfigFile = new File(documentConfigFilePath);
55              response.setContentType("text/xml");
56              response.setContentLength((int) docSearchConfigFile.length());
57              FileInputStream input = new FileInputStream(docSearchConfigFile);
58              inputStream = new BufferedInputStream(input);
59              int readBytes;
60              while ((readBytes = inputStream.read()) != -1)
61                  outputStream.write(readBytes);
62          }
63          catch (IOException ioe) {
64             throw new ServletException(ioe.getMessage());
65          }
66          finally {
67              if (outputStream != null)
68                  outputStream.close();
69              if (inputStream != null)
70                  inputStream.close();
71          }
72      }
73  
74  }