package com.abnamro.infinity.servlet; import java.io.*; import java.net.*; import java.util.*; import com.ibm.xml.parser.*; import org.w3c.dom.*; import com.lotus.xsl.*; import com.lotus.xsl.xml4j.*; import javax.servlet.*; import javax.servlet.http.*; public class xml2html extends HttpServlet { public void init(ServletConfig config) throws ServletException { super.init(config); // Right now there is nothing to do herex } public void destroy() { super.destroy(); // And, nothing to do here yet, either } protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doRequest_(req, resp); } protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doRequest_(req, resp); } // Purposely do not implement doPut - no ftp-like interface yet // Purposely do not implement doDelete - no delete interface yet private void doRequest_(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String xmlFileName = req.getParameter(XML_); String xslFileName = req.getParameter(XSL_); PrintWriter printer = new PrintWriter(resp.getWriter()); if (xmlFileName != null && xslFileName != null) { resp.setContentType("text/html"); process(xmlFileName, xslFileName, printer); } else { resp.setContentType("text/html"); resp.getWriter().write("Mistake in Request"); resp.getWriter().write("

Mistake in using xml2html

"); resp.getWriter().write("XML and XSL are both required parameters to the servlet"); } } public void process(String inputFileName, String xslFileName, PrintWriter pr) { boolean anErrorOccurred = false; Document XMLDoc = null, XSLDoc = null, outputDoc = null; ProcessXSL xmlProcessorLiason = null; XSLProcessor p = null; try { xmlProcessorLiason = new ProcessXSL(); p = new XSLProcessor(xmlProcessorLiason); try { XMLDoc = p.parseXML(inputFileName, 0); XSLDoc = p.parseXML(xslFileName, 0); String resultns = new String(""); outputDoc = p.process(XMLDoc, XSLDoc, resultns, pr); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String [] argv) { xml2html x = new xml2html(); PrintWriter printer = new PrintWriter(System.out); x.process(argv[0], argv[1], printer); } private static final String XML_ = "XML"; private static final String XSL_ = "XSL"; }