KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > frontoffice > servlet > PdfPipeServlet


1 package org.nextime.ion.frontoffice.servlet;
2
3 import java.io.FileOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.PrintWriter JavaDoc;
6 import java.util.Iterator JavaDoc;
7
8 import javax.servlet.ServletException JavaDoc;
9 import javax.servlet.http.HttpServlet JavaDoc;
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
18  * @author gbort
19  */

20 public class PdfPipeServlet extends HttpServlet JavaDoc {
21
22     public void service(
23         HttpServletRequest JavaDoc request,
24         HttpServletResponse JavaDoc response)
25         throws ServletException JavaDoc, IOException JavaDoc {
26
27         String JavaDoc 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 JavaDoc 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 JavaDoc out = new PrintWriter JavaDoc(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 JavaDoc e) {
62             System.out.println(e.getMessage());
63             e.printStackTrace();
64             throw new ServletException JavaDoc(e);
65         } finally {
66             Mapping.rollback();
67         }
68     }
69
70 }
71
Popular Tags