Source Code Cross Referenced for AbstractPDFOutput.java in  » J2EE » Dinamica » dinamica » 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 » J2EE » Dinamica » dinamica 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package dinamica;
002:
003:        import javax.servlet.*;
004:        import java.io.ByteArrayOutputStream;
005:        import com.lowagie.text.*;
006:        import com.lowagie.text.pdf.*;
007:
008:        /**
009:         * Base class to produce PDF output modules (hand made reports)
010:         * based on the powerful IText-PDF open source component.<br>
011:         * This super class provides several common utility methods, including
012:         * the abiity to auto-read the report header, footer and title from web.xml
013:         * or config.xml, and to retrieve images from URLs (local or remotes), which is
014:         * used to insert charts into the PDF document by reusing a server-side chart Action, 
015:         * or to insert another dinamically generated image, like a BarCode. The method to retrieve
016:         * via HTTP is session sensitive, meaning that it can reuse the same session ID, which is
017:         * a requirement when accessing local resources that are session-sensitive, like chart Actions.
018:         * <br><br>
019:         * In order to reuse this class, you must override the method createPDF(), you may use
020:         * the default implementation as a code template. For more information look into
021:         * the /source and /templates resources included with Dinamica distribution.
022:         * <br><br>
023:         * (c) 2004 Martin Cordova<br>
024:         * This code is released under the LGPL license<br>
025:         * Dinamica Framework - http://www.martincordova.com
026:         * @author Martin Cordova (dinamica@martincordova.com)
027:         * */
028:        public class AbstractPDFOutput extends GenericOutput {
029:
030:            /* (non-Javadoc)
031:             * @see dinamica.GenericOutput#print(dinamica.GenericTransaction)
032:             */
033:            public void print(GenericTransaction data) throws Throwable {
034:                ByteArrayOutputStream buf = new ByteArrayOutputStream();
035:                createPDF(data, buf);
036:                getResponse().setContentType("application/pdf");
037:                getResponse().setContentLength(buf.size());
038:                ServletOutputStream out = getResponse().getOutputStream();
039:                buf.writeTo(out);
040:                out.close();
041:            }
042:
043:            /**
044:             * Receives a byte buffer that should be filled with resulting PDF.
045:             * @param data Data module that provides recordsets to this output module
046:             * @param buf Buffer to print PDF, then used to send to browser
047:             * @throws Throwable
048:             */
049:            protected void createPDF(GenericTransaction data,
050:                    ByteArrayOutputStream buf) throws Throwable {
051:
052:                //pdf objects
053:                Document doc = new Document();
054:                PdfWriter docWriter = PdfWriter.getInstance(doc, buf);
055:
056:                //header
057:                HeaderFooter header = new HeaderFooter(new Phrase(getHeader()),
058:                        false);
059:                header.setBorder(Rectangle.BOTTOM);
060:                header.setAlignment(Rectangle.ALIGN_CENTER);
061:                doc.setHeader(header);
062:
063:                //footer
064:                HeaderFooter footer = new HeaderFooter(new Phrase(getFooter()),
065:                        true);
066:                footer.setBorder(Rectangle.TOP);
067:                footer.setAlignment(Rectangle.ALIGN_RIGHT);
068:                doc.setFooter(footer);
069:
070:                //pagesize
071:                doc.setPageSize(PageSize.LETTER);
072:
073:                doc.open();
074:
075:                //title
076:                Paragraph t = new Paragraph(getReportTitle(), new Font(
077:                        Font.HELVETICA, 18f));
078:                t.setAlignment(Rectangle.ALIGN_CENTER);
079:                doc.add(t);
080:
081:                //paragraph
082:                Paragraph p = new Paragraph("Hello World");
083:                p.setAlignment(Rectangle.ALIGN_CENTER);
084:                doc.add(p);
085:
086:                doc.close();
087:                docWriter.close();
088:
089:            }
090:
091:            /**
092:             * Get default report header (parameter pdf-header) from web.xml (context-param) or current config.xml (custom element).
093:             * Any subclass may override this method.
094:             * @return Report header text or NULL
095:             */
096:            protected String getHeader() {
097:
098:                return getPDFConfigValue("pdf-header");
099:
100:            }
101:
102:            /**
103:             * Get default report footer (parameter pdf-footer) from web.xml (context-param) or current config.xml (custom element).
104:             * Any subclass may override this method.
105:             * @return Report footer text or NULL
106:             */
107:            protected String getFooter() {
108:                return getPDFConfigValue("pdf-footer") + " ";
109:            }
110:
111:            /**
112:             * Get default report title (parameter pdf-title) from web.xml (context-param) or current config.xml (custom element).
113:             * Most of the time the report title should be defined in config.xml because it is
114:             * specific to the report.
115:             * Any subclass may override this method.
116:             * @return Report title text or NULL
117:             */
118:            protected String getReportTitle() {
119:                return getPDFConfigValue("pdf-title");
120:            }
121:
122:            /**
123:             * Read a PDF-related config parameter. Will search first
124:             * in the Action config.xml, then in web.xml file.
125:             * @param param
126:             * @return The corresponding value or NULL if not found.
127:             */
128:            protected String getPDFConfigValue(String param) {
129:                String value = null;
130:                try {
131:                    value = getConfig().getConfigValue(param);
132:                    if (value == null || value.trim().equals("")) {
133:                        value = getContext().getInitParameter(param);
134:                    }
135:                } catch (Throwable e) {
136:                    value = getContext().getInitParameter(param);
137:                    if (value == null)
138:                        value = "";
139:                }
140:                return value;
141:            }
142:
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.