1 17 18 19 20 package org.apache.fop.servlet; 21 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 25 import javax.servlet.http.HttpServletResponse ; 26 27 import javax.xml.transform.Transformer ; 28 import javax.xml.transform.TransformerException ; 29 import javax.xml.transform.Result ; 30 import javax.xml.transform.Source ; 31 import javax.xml.transform.sax.SAXResult ; 32 33 import org.apache.fop.apps.FOPException; 34 import org.apache.fop.apps.FOUserAgent; 35 import org.apache.fop.apps.Fop; 36 import org.apache.fop.apps.MimeConstants; 37 38 39 62 public class FopPrintServlet extends FopServlet { 63 64 68 protected void render(Source src, Transformer transformer, HttpServletResponse response) 69 throws FOPException, TransformerException , IOException { 70 71 FOUserAgent foUserAgent = getFOUserAgent(); 72 73 Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, foUserAgent); 75 76 Result res = new SAXResult (fop.getDefaultHandler()); 78 79 transformer.transform(src, res); 81 82 reportOK(response); 84 } 85 86 private void reportOK(HttpServletResponse response) throws IOException { 88 String sMsg = "<html><title>Success</title>\n" 89 + "<body><h1>FopPrintServlet: </h1>" 90 + "<h3>The requested data was printed to the default printer.</h3></body></html>"; 91 92 response.setContentType("text/html"); 93 response.setContentLength(sMsg.length()); 94 95 PrintWriter out = response.getWriter(); 96 out.println(sMsg); 97 out.flush(); 98 } 99 100 } 101 102 | Popular Tags |