~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/engine/export/oasis/StyleBuilder.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:51:16 UTC
  • Revision ID: brian.thomason@canonical.com-20111220175116-apwo6unuaedvgzo3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JasperReports - Free Java Reporting Library.
 
3
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
 
4
 * http://www.jaspersoft.com
 
5
 *
 
6
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 
7
 * the following license terms apply:
 
8
 *
 
9
 * This program is part of JasperReports.
 
10
 *
 
11
 * JasperReports is free software: you can redistribute it and/or modify
 
12
 * it under the terms of the GNU Lesser General Public License as published by
 
13
 * the Free Software Foundation, either version 3 of the License, or
 
14
 * (at your option) any later version.
 
15
 *
 
16
 * JasperReports is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
 
23
 */
 
24
 
 
25
/*
 
26
 * Special thanks to Google 'Summer of Code 2005' program for supporting this development
 
27
 * 
 
28
 * Contributors:
 
29
 * Majid Ali Khan - majidkk@users.sourceforge.net
 
30
 * Frank Sch�nheit - Frank.Schoenheit@Sun.COM
 
31
 */
 
32
package net.sf.jasperreports.engine.export.oasis;
 
33
 
 
34
import java.io.IOException;
 
35
import java.io.Writer;
 
36
import java.util.List;
 
37
 
 
38
import net.sf.jasperreports.engine.JasperPrint;
 
39
 
 
40
 
 
41
/**
 
42
 * @author Teodor Danciu (teodord@users.sourceforge.net)
 
43
 * @version $Id: StyleBuilder.java 3518 2010-03-05 11:53:03Z shertage $
 
44
 */
 
45
public class StyleBuilder
 
46
{
 
47
        /**
 
48
         * 
 
49
         */
 
50
        private List jasperPrintList = null;
 
51
        private Writer writer = null;
 
52
        
 
53
        /**
 
54
         * 
 
55
         */
 
56
        public StyleBuilder(List jasperPrintList, Writer writer)
 
57
        {
 
58
                this.jasperPrintList = jasperPrintList;
 
59
                this.writer = writer;
 
60
        }
 
61
 
 
62
        /**
 
63
         * 
 
64
         */
 
65
        public void build() throws IOException
 
66
        {
 
67
                buildBeforeAutomaticStyles();
 
68
                
 
69
                for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
 
70
                {
 
71
                        JasperPrint jasperPrint = (JasperPrint)jasperPrintList.get(reportIndex);
 
72
                        
 
73
                        buildPageLayout(reportIndex, jasperPrint);
 
74
                }
 
75
 
 
76
                buildBetweenAutomaticAndMasterStyles();
 
77
 
 
78
                for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
 
79
                {
 
80
                        buildMasterPage(reportIndex);
 
81
                }
 
82
 
 
83
                buildAfterMasterStyles();
 
84
                
 
85
                writer.flush();
 
86
        }
 
87
        
 
88
        /**
 
89
         * 
 
90
         */
 
91
        private void buildBeforeAutomaticStyles() throws IOException
 
92
        {
 
93
                writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
 
94
 
 
95
                writer.write("<office:document-styles");
 
96
                writer.write(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"");
 
97
                writer.write(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"");
 
98
                writer.write(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"");
 
99
                writer.write(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"");
 
100
                writer.write(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"");
 
101
                writer.write(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"");
 
102
                writer.write(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
 
103
                writer.write(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
 
104
                writer.write(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"");
 
105
                writer.write(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"");
 
106
                writer.write(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"");
 
107
                writer.write(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"");
 
108
                writer.write(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"");
 
109
                writer.write(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"");
 
110
                writer.write(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"");
 
111
                writer.write(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"");
 
112
                writer.write(" xmlns:ooo=\"http://openoffice.org/2004/office\"");
 
113
                writer.write(" xmlns:ooow=\"http://openoffice.org/2004/writer\"");
 
114
                writer.write(" xmlns:oooc=\"http://openoffice.org/2004/calc\"");
 
115
                writer.write(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"");
 
116
                writer.write(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"");
 
117
                writer.write(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
 
118
                writer.write(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
 
119
                writer.write(" office:version=\"");             
 
120
                writer.write(ContentBuilder.VERSION);           
 
121
                writer.write("\">\n");          
 
122
 
 
123
                writer.write(" <office:styles>\n");     
 
124
                writer.write("<draw:stroke-dash draw:name=\"Dashed\" draw:display-name=\"Dashed\" " +
 
125
                        "draw:style=\"rect\" draw:dots1=\"1\" draw:dots1-length=\"0.05cm\" draw:dots2=\"1\" " +
 
126
                        "draw:dots2-length=\"0.05cm\" draw:distance=\"0.05cm\"/>");
 
127
                writer.write(" </office:styles>\n");    
 
128
                writer.write(" <office:automatic-styles>\n");   
 
129
        }
 
130
        
 
131
        /**
 
132
         * 
 
133
         */
 
134
        private void buildBetweenAutomaticAndMasterStyles() throws IOException
 
135
        {
 
136
                writer.write(" </office:automatic-styles>\n");
 
137
                writer.write(" <office:master-styles>\n");      
 
138
        }
 
139
        
 
140
        /**
 
141
         * 
 
142
         */
 
143
        private void buildAfterMasterStyles() throws IOException
 
144
        {
 
145
                writer.write(" </office:master-styles>\n");     
 
146
                writer.write("</office:document-styles>\n");
 
147
        }
 
148
 
 
149
        /**
 
150
         * 
 
151
         */
 
152
        private void buildPageLayout(int reportIndex, JasperPrint jasperPrint) throws IOException 
 
153
        {
 
154
                        writer.write("<style:page-layout");
 
155
                        writer.write(" style:name=\"page_" + reportIndex + "\">\n");
 
156
                        
 
157
                        writer.write("<style:page-layout-properties");
 
158
                        writer.write(" fo:page-width=\"" + Utility.translatePixelsToInchesRound(jasperPrint.getPageWidth()) +"in\"");
 
159
                        writer.write(" fo:page-height=\"" + Utility.translatePixelsToInchesRound(jasperPrint.getPageHeight()) +"in\"");//FIXMEODT we probably need some actualHeight trick
 
160
                        writer.write(" fo:margin-top=\"0in\"");//FIXMEODT if first cell on page is for frame (nested table), this forcing of margins to zero does not work
 
161
                        writer.write(" fo:margin-bottom=\"0in\"");
 
162
                        writer.write(" fo:margin-left=\"0in\"");
 
163
                        writer.write(" fo:margin-right=\"0in\"");
 
164
 
 
165
                        switch (jasperPrint.getOrientationValue())
 
166
                        {
 
167
                                case LANDSCAPE:
 
168
                                        writer.write(" style:print-orientation=\"landscape\"");
 
169
                                        break;
 
170
                                default:
 
171
                                        writer.write(" style:print-orientation=\"portrait\"");
 
172
                                        break;
 
173
                        }
 
174
                        
 
175
                        writer.write("/>\n");
 
176
                        writer.write("</style:page-layout>\n");
 
177
        }
 
178
 
 
179
        /**
 
180
         * 
 
181
         */
 
182
        private void buildMasterPage(int reportIndex) throws IOException 
 
183
        {
 
184
                writer.write("<style:master-page style:name=\"master_");
 
185
                writer.write(String.valueOf(reportIndex));
 
186
                writer.write("\" style:page-layout-name=\"page_");
 
187
                writer.write(String.valueOf(reportIndex));
 
188
                writer.write("\"/>\n");
 
189
        }
 
190
 
 
191
}