1 package org.nextime.ion.frontoffice.servlet; 2 3 import java.io.FileOutputStream ; 4 import java.io.IOException ; 5 import java.io.PrintWriter ; 6 import java.util.Iterator ; 7 8 import javax.servlet.ServletException ; 9 import javax.servlet.http.HttpServlet ; 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.http.HttpServletResponse ; 12 13 import org.nextime.ion.framework.locale.Locale; 14 import org.nextime.ion.framework.locale.LocaleList; 15 import org.nextime.ion.framework.mapping.Mapping; 16 17 20 public class PdfPipeServlet extends HttpServlet { 21 22 public void service( 23 HttpServletRequest request, 24 HttpServletResponse response) 25 throws ServletException , IOException { 26 27 String requestedId = 28 (request.getPathInfo() != null) 29 ? request.getPathInfo().substring(1) 30 : null; 31 if (requestedId != null) { 32 if (requestedId.indexOf(".") != -1) { 33 requestedId = 34 requestedId.substring(0, requestedId.indexOf(".")); 35 } 36 } 37 38 int version = Integer.parseInt(request.getParameter("version")); 39 String view = request.getParameter("view"); 40 41 try { 42 Mapping.begin(); 43 org.nextime.ion.framework.business.Publication p = 44 org.nextime.ion.framework.business.Publication.getInstance( 45 requestedId); 46 byte[] buffer = 47 org.nextime.ion.framework.helper.Viewer.getView( 48 p, 49 version, 50 view, 51 request.getSession().getAttribute("currentLocale") + ""); 52 53 PrintWriter out = new PrintWriter (response.getOutputStream()); 54 55 response.setContentType("application/pdf"); 56 response.setContentLength(buffer.length); 57 response.getOutputStream().write(buffer); 58 response.getOutputStream().flush(); 59 response.getOutputStream().close(); 60 61 } catch (Exception e) { 62 System.out.println(e.getMessage()); 63 e.printStackTrace(); 64 throw new ServletException (e); 65 } finally { 66 Mapping.rollback(); 67 } 68 } 69 70 } 71 | Popular Tags |