2
* JasperReports - Free Java Reporting Library.
3
* Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
4
* http://www.jaspersoft.com
6
* Unless you have purchased a commercial license agreement from Jaspersoft,
7
* the following license terms apply:
9
* This program is part of JasperReports.
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.
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.
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/>.
26
* Special thanks to Google 'Summer of Code 2005' program for supporting this development
29
* Majid Ali Khan - majidkk@users.sourceforge.net
30
* Frank Sch�nheit - Frank.Schoenheit@Sun.COM
32
package net.sf.jasperreports.engine.export.oasis;
34
import java.io.IOException;
35
import java.io.Writer;
36
import java.util.List;
38
import net.sf.jasperreports.engine.JasperPrint;
42
* @author Teodor Danciu (teodord@users.sourceforge.net)
43
* @version $Id: StyleBuilder.java 3518 2010-03-05 11:53:03Z shertage $
45
public class StyleBuilder
50
private List jasperPrintList = null;
51
private Writer writer = null;
56
public StyleBuilder(List jasperPrintList, Writer writer)
58
this.jasperPrintList = jasperPrintList;
65
public void build() throws IOException
67
buildBeforeAutomaticStyles();
69
for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
71
JasperPrint jasperPrint = (JasperPrint)jasperPrintList.get(reportIndex);
73
buildPageLayout(reportIndex, jasperPrint);
76
buildBetweenAutomaticAndMasterStyles();
78
for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
80
buildMasterPage(reportIndex);
83
buildAfterMasterStyles();
91
private void buildBeforeAutomaticStyles() throws IOException
93
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
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");
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");
134
private void buildBetweenAutomaticAndMasterStyles() throws IOException
136
writer.write(" </office:automatic-styles>\n");
137
writer.write(" <office:master-styles>\n");
143
private void buildAfterMasterStyles() throws IOException
145
writer.write(" </office:master-styles>\n");
146
writer.write("</office:document-styles>\n");
152
private void buildPageLayout(int reportIndex, JasperPrint jasperPrint) throws IOException
154
writer.write("<style:page-layout");
155
writer.write(" style:name=\"page_" + reportIndex + "\">\n");
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\"");
165
switch (jasperPrint.getOrientationValue())
168
writer.write(" style:print-orientation=\"landscape\"");
171
writer.write(" style:print-orientation=\"portrait\"");
175
writer.write("/>\n");
176
writer.write("</style:page-layout>\n");
182
private void buildMasterPage(int reportIndex) throws IOException
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");