001: package org.contineo.web.document;
002:
003: import org.apache.commons.lang.StringUtils;
004: import org.apache.commons.logging.Log;
005: import org.apache.commons.logging.LogFactory;
006:
007: import org.contineo.core.document.DownloadTicket;
008: import org.contineo.core.document.dao.DownloadTicketDAO;
009:
010: import org.contineo.util.Context;
011:
012: import java.io.IOException;
013: import java.io.PrintWriter;
014:
015: import javax.servlet.ServletException;
016: import javax.servlet.http.HttpServlet;
017: import javax.servlet.http.HttpServletRequest;
018: import javax.servlet.http.HttpServletResponse;
019: import javax.servlet.http.HttpSession;
020:
021: /**
022: * This servlet is responsible for document downloads using download tickets. It
023: * searches for the attribute ticketId in any scope and extracts the proper
024: * document's content.
025: *
026: * @author Marco Meschieri
027: * @version $Id: TicketDownload.java,v 1.3 2006/08/24 08:35:08 marco Exp $
028: * @since 2.6
029: */
030: public class TicketDownload extends HttpServlet {
031: protected static Log logger = LogFactory
032: .getLog(TicketDownload.class);
033:
034: /**
035: * Constructor of the object.
036: */
037: public TicketDownload() {
038: super ();
039: }
040:
041: /**
042: * The doGet method of the servlet. <br>
043: *
044: * This method is called when a form has its tag value method equals to get.
045: *
046: * @param request the request send by the client to the server
047: * @param response the response send by the server to the client
048: * @throws ServletException if an error occurred
049: * @throws IOException if an error occurred
050: */
051: public void doGet(HttpServletRequest request,
052: HttpServletResponse response) throws ServletException,
053: IOException {
054: HttpSession session = request.getSession();
055: String ticketId = request.getParameter("ticketId");
056:
057: if (StringUtils.isEmpty(ticketId)) {
058: ticketId = (String) request.getAttribute("ticketId");
059: }
060:
061: if (StringUtils.isEmpty(ticketId)) {
062: ticketId = (String) session.getAttribute("ticketId");
063: }
064:
065: logger.debug("Download ticket ticketId=" + ticketId);
066:
067: try {
068: DownloadTicketDAO ticketDao = (DownloadTicketDAO) Context
069: .getInstance().getBean(DownloadTicketDAO.class);
070: DownloadTicket ticket = ticketDao
071: .findByPrimaryKey(ticketId);
072:
073: if ((ticket != null) && (ticket.getMenuId() != 0)) {
074: DownloadDocUtil.downloadDocument(response, ticket
075: .getMenuId(), null);
076: }
077: } catch (Exception e) {
078: logger.error(e.getMessage(), e);
079: }
080: }
081:
082: /**
083: * The doPost method of the servlet. <br>
084: *
085: * This method is called when a form has its tag value method equals to
086: * post.
087: *
088: * @param request the request send by the client to the server
089: * @param response the response send by the server to the client
090: * @throws ServletException if an error occurred
091: * @throws IOException if an error occurred
092: */
093: public void doPost(HttpServletRequest request,
094: HttpServletResponse response) throws ServletException,
095: IOException {
096: response.setContentType("text/html");
097:
098: PrintWriter out = response.getWriter();
099: out
100: .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
101: out.println("<HTML>");
102: out
103: .println(" <HEAD><TITLE>Download Ticket Action</TITLE></HEAD>");
104: out.println(" <BODY>");
105: out.print(" This is ");
106: out.print(this .getClass());
107: out.println(", using the POST method");
108: out.println(" </BODY>");
109: out.println("</HTML>");
110: out.flush();
111: out.close();
112: }
113: }
|