1 7 8 package fops.presentation; 9 10 import java.io.*; 11 import java.net.*; 12 import java.util.Date ; 13 import java.text.DateFormat ; 14 15 import org.apache.fop.apps.Driver; 16 import org.apache.fop.apps.Options; 17 import org.apache.fop.apps.Version; 18 import org.apache.fop.apps.XSLTInputHandler; 19 import org.apache.fop.messaging.MessageHandler; 20 21 import org.xml.sax.InputSource ; 22 import org.xml.sax.XMLReader ; 23 24 import org.apache.avalon.framework.logger.ConsoleLogger; 25 import org.apache.avalon.framework.logger.Logger; 26 27 import fops.spec.*; 28 29 import com.lutris.appserver.server.httpPresentation.*; 31 32 33 public class ServletEditor implements HttpPresentation { 34 35 private Logger log = null; 36 37 private String DateHTML = null; 38 private String NameHTML = null; 39 private String SubjHTML = null; 40 private String AppletHTML = null; 41 private String xmlParam =null; 42 private String xslParam = null; 43 private String foParam = null; 44 45 private File userConfigFile; 46 private String fopBaseDir; 47 48 boolean noParams = false; 49 50 public void run(HttpPresentationComms comms) throws Exception { 51 if (log == null) 52 { 53 log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN); 54 MessageHandler.setScreenLogger(log); 55 } 56 57 xmlParam = comms.request.getParameter("xml"); 58 xslParam = comms.request.getParameter("xsl"); 59 foParam = comms.request.getParameter("fo"); 60 DateHTML=comms.request.getParameter("date"); 61 NameHTML=comms.request.getParameter("name"); 62 SubjHTML=comms.request.getParameter("subject"); 63 AppletHTML = comms.request.getParameter("context"); 64 65 66 try{ 67 RenderManager renderManager = RenderManagerFactory.getRenderManager("fops.business.RenderManagerImpl"); 68 69 userConfigFile=((fops.Fopes)comms.application).getUserConfigFile(); 71 fopBaseDir=((fops.Fopes)comms.application).getFopBaseDir(); 73 Options options = new Options(userConfigFile); 74 75 if (fopBaseDir!=null) 76 org.apache.fop.configuration.Configuration.put("baseDir",fopBaseDir); 77 78 if((xmlParam != null) && (xslParam != null)){ 79 System.out.println("PDF from XML: "+xmlParam+" and XSL: "+xslParam); 81 82 83 byte[] content = renderManager.renderXML(xmlParam,xslParam,log); 84 comms.response.setContentType("application/pdf"); 85 comms.response.setContentLength(content.length); 86 comms.response.getOutputStream().write(content); 87 comms.response.getOutputStream().flush(); 88 89 90 }else if(foParam !=null){ 91 93 94 byte[] content = renderManager.renderFOFile(foParam,log); 95 comms.response.setContentType("application/pdf"); 96 comms.response.setContentLength(content.length); 97 comms.response.getOutputStream().write(content); 98 comms.response.getOutputStream().flush(); 99 100 }else if(DateHTML!=null || NameHTML!=null || SubjHTML!=null || AppletHTML!=null){ 101 103 byte[] content = renderManager.renderFO(noParams,DateHTML,NameHTML,SubjHTML,AppletHTML,log); 104 comms.response.setContentType("application/pdf"); 105 comms.response.setContentLength(content.length); 106 comms.response.getOutputStream().write(content); 107 comms.response.getOutputStream().flush(); 108 109 }else{ 110 System.out.println("There is no any request parameter given!!!"); 111 noParams = true; 112 113 byte[] content = renderManager.renderFO(noParams,DateHTML,NameHTML,SubjHTML,AppletHTML,log); 114 comms.response.setContentType("application/pdf"); 115 comms.response.setContentLength(content.length); 116 comms.response.getOutputStream().write(content); 117 comms.response.getOutputStream().flush(); 118 119 120 } 121 }catch(NullPointerException e){ 122 throw new ClientPageRedirectException("IndexPO.po"); 123 } 124 } 125 } 126 127 | Popular Tags |