KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fops > presentation > ServletEditor


1 /**
2  * Servlet ServletEditor
3  * <P>
4  * @author: Stefanovic Nenad, Bojanic Sasa
5  * @Date: August 2001 - May 2003
6  */

7
8 package fops.presentation;
9
10 import java.io.*;
11 import java.net.*;
12 import java.util.Date JavaDoc;
13 import java.text.DateFormat JavaDoc;
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 JavaDoc;
22 import org.xml.sax.XMLReader JavaDoc;
23
24 import org.apache.avalon.framework.logger.ConsoleLogger;
25 import org.apache.avalon.framework.logger.Logger;
26
27 import fops.spec.*;
28
29 // Enhydra SuperServlet imports
30
import com.lutris.appserver.server.httpPresentation.*;
31
32
33 public class ServletEditor implements HttpPresentation {
34
35    private Logger log = null;
36
37    private String JavaDoc DateHTML = null;
38    private String JavaDoc NameHTML = null;
39    private String JavaDoc SubjHTML = null;
40    private String JavaDoc AppletHTML = null;
41    private String JavaDoc xmlParam =null;
42    private String JavaDoc xslParam = null;
43    private String JavaDoc foParam = null;
44
45    private File userConfigFile;
46    private String JavaDoc fopBaseDir;
47    
48    boolean noParams = false;
49
50    public void run(HttpPresentationComms comms) throws Exception JavaDoc {
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       //User defined configuration file for embeded fonts
70
userConfigFile=((fops.Fopes)comms.application).getUserConfigFile();
71       //User defined configuration directory
72
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         //Rendering a PDF from XML+XSL files
80
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         // Rendering a PDF from FO file
92

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         // Rendering a PDF from applet parameters
102

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 JavaDoc e){
122     throw new ClientPageRedirectException("IndexPO.po");
123     }
124 }
125   }
126
127
Popular Tags