01: /*
02: * Created on Mar 14, 2005
03: */
04: package com.sun.portal.wireless.htmlconversion.servlet;
05:
06: import java.io.IOException;
07: import java.io.Writer;
08:
09: import javax.servlet.RequestDispatcher;
10: import javax.servlet.ServletException;
11: import javax.servlet.http.HttpServlet;
12: import javax.servlet.http.HttpServletRequest;
13: import javax.servlet.http.HttpServletResponse;
14:
15: /**
16: * Servlet for converting HTML to AML
17: *
18: * @author ashwin.mathew@sun.com
19: */
20: public class ViewHtmlServlet extends HttpServlet {
21:
22: private static final String AML_CONTENT_TYPE = "text/aml";
23:
24: private static final String ERROR_PAGE_PATH = "/jsp/default/error/aml/errorPage.jsp";
25:
26: /* (non-Javadoc)
27: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
28: */
29: protected void service(HttpServletRequest request,
30: HttpServletResponse response) throws ServletException,
31: IOException {
32: String amlContent = null;
33: URLScraper scraper = null;
34:
35: try {
36: scraper = new URLScraper(request, response, false);
37:
38: amlContent = scraper.getAMLContent();
39: } catch (Exception ex) {
40: ex.printStackTrace();
41:
42: // Redirect to error page
43: RequestDispatcher dispatcher = getServletContext()
44: .getRequestDispatcher(ERROR_PAGE_PATH);
45: dispatcher.forward(request, response);
46: return;
47: }
48:
49: int responseCode = scraper.getResponseCode();
50:
51: // Response is OK
52: response.setStatus(responseCode);
53: response.setContentType(AML_CONTENT_TYPE);
54:
55: Writer out = response.getWriter();
56: out.write(amlContent);
57: out.flush();
58: out.close();
59: }
60: }
|