Source Code Cross Referenced for FopPdfViewHandler.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » content » webapp » view » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » SourceTap CRM » org.ofbiz.content.webapp.view 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: FopPdfViewHandler.java,v 1.3 2003/09/08 20:42:12 ajzeneski Exp $
003:         *
004:         * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
005:         *
006:         * Permission is hereby granted, free of charge, to any person obtaining a
007:         * copy of this software and associated documentation files (the "Software"),
008:         * to deal in the Software without restriction, including without limitation
009:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         * and/or sell copies of the Software, and to permit persons to whom the
011:         * Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included
014:         * in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         *
024:         */
025:        package org.ofbiz.content.webapp.view;
026:
027:        import java.io.ByteArrayOutputStream;
028:        import java.io.IOException;
029:        import java.io.StringWriter;
030:        import java.io.Writer;
031:
032:        import javax.servlet.http.HttpServletRequest;
033:        import javax.servlet.http.HttpServletResponse;
034:
035:        import org.apache.avalon.framework.logger.Log4JLogger;
036:        import org.apache.avalon.framework.logger.Logger;
037:        import org.apache.fop.apps.Driver;
038:        import org.apache.fop.messaging.MessageHandler;
039:        import org.apache.fop.tools.DocumentInputSource;
040:        import org.ofbiz.base.util.Debug;
041:        import org.ofbiz.base.util.UtilXml;
042:        import org.w3c.dom.Document;
043:        import org.xml.sax.InputSource;
044:
045:        /**
046:         * Uses XSL-FO formatted templates to generate PDF views
047:         * This handler will use JPublish to generate the XSL-FO
048:         *
049:         * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
050:         * @version    $Revision: 1.3 $
051:         * @since      3.0
052:         */
053:        public class FopPdfViewHandler extends JPublishViewHandler {
054:
055:            public static final String module = FopPdfViewHandler.class
056:                    .getName();
057:
058:            /**
059:             * @see org.ofbiz.content.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
060:             */
061:            public void render(String name, String page, String info,
062:                    String contentType, String encoding,
063:                    HttpServletRequest request, HttpServletResponse response)
064:                    throws ViewHandlerException {
065:                // render and obtain the XSL-FO 
066:                Writer writer = new StringWriter();
067:                try {
068:                    wrapper
069:                            .render(page, request, response, writer, null,
070:                                    false);
071:                } catch (Throwable t) {
072:                    throw new ViewHandlerException(
073:                            "Problems with the response writer/output stream",
074:                            t);
075:                }
076:                if (Debug.verboseOn()) {
077:                    Debug.logVerbose("XSL-FO : " + writer.toString(), module);
078:                }
079:
080:                // configure logging for the FOP
081:                Logger logger = new Log4JLogger(Debug.getLogger(module));
082:                MessageHandler.setScreenLogger(logger);
083:
084:                // load the FOP driver
085:                Driver driver = new Driver();
086:                driver.setRenderer(Driver.RENDER_PDF);
087:                driver.setLogger(logger);
088:
089:                // read the XSL-FO XML Document
090:                Document xslfo = null;
091:                try {
092:                    xslfo = UtilXml.readXmlDocument(writer.toString());
093:                } catch (Throwable t) {
094:                    throw new ViewHandlerException(
095:                            "Problems reading the parsed content to XML Document",
096:                            t);
097:                }
098:
099:                // create the output stream for the PDF
100:                ByteArrayOutputStream out = new ByteArrayOutputStream();
101:                driver.setOutputStream(out);
102:
103:                // set the input source (XSL-FO) and generate the PDF        
104:                InputSource is = new DocumentInputSource(xslfo);
105:                driver.setInputSource(is);
106:                try {
107:                    driver.run();
108:                } catch (Throwable t) {
109:                    throw new ViewHandlerException(
110:                            "Unable to generate PDF from XSL-FO", t);
111:                }
112:
113:                // set the content type and length                    
114:                response.setContentType("application/pdf");
115:                response.setContentLength(out.size());
116:
117:                // write to the browser
118:                try {
119:                    response.getOutputStream().write(out.toByteArray());
120:                    response.getOutputStream().flush();
121:                } catch (IOException e) {
122:                    throw new ViewHandlerException(
123:                            "Unable write to browser OutputStream", e);
124:                }
125:            }
126:
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.