001package org.kuali.ole.docstore.discovery.servlet; 002 003/** 004 * Created by IntelliJ IDEA. 005 * User: SG7940 006 * Date: 6/26/12 007 * Time: 5:17 PM 008 * To change this template use File | Settings | File Templates. 009 */ 010 011 012import javax.servlet.ServletException; 013import javax.servlet.ServletOutputStream; 014import javax.servlet.http.HttpServlet; 015import javax.servlet.http.HttpServletRequest; 016import javax.servlet.http.HttpServletResponse; 017import java.io.BufferedInputStream; 018import java.io.File; 019import java.io.FileInputStream; 020import java.io.IOException; 021 022/** 023 * Class for getting configuration info about document categories, types, formats etc. 024 */ 025public class DocumentConfigServlet extends HttpServlet { 026 027 private static final long serialVersionUID = 1L; 028 029 /** 030 * @see javax.servlet.http.HttpServlet#HttpServlet() 031 */ 032 public DocumentConfigServlet() { 033 super(); 034 } 035 036 /** 037 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse 038 * response) 039 */ 040 041 042 public void doGet(HttpServletRequest request, 043 HttpServletResponse response) throws ServletException, IOException { 044 doPost(request, response); 045 } 046 047 public void doPost(HttpServletRequest request, 048 HttpServletResponse response) throws ServletException, IOException { 049 050 ServletOutputStream outputStream = null; 051 BufferedInputStream inputStream = null; 052 try { 053 outputStream = response.getOutputStream(); 054 String documentConfigFilePath = System.getProperty("document.config.file"); 055 File docSearchConfigFile = new File(documentConfigFilePath); 056 response.setContentType("text/xml"); 057 response.setContentLength((int) docSearchConfigFile.length()); 058 FileInputStream input = new FileInputStream(docSearchConfigFile); 059 inputStream = new BufferedInputStream(input); 060 int readBytes; 061 while ((readBytes = inputStream.read()) != -1) 062 outputStream.write(readBytes); 063 } catch (IOException ioe) { 064 throw new ServletException(ioe.getMessage()); 065 } finally { 066 if (outputStream != null) 067 outputStream.close(); 068 if (inputStream != null) 069 inputStream.close(); 070 } 071 } 072 073}