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/>.
25
package net.sf.jasperreports.engine.export.xmlss;
27
import java.io.IOException;
28
import java.io.Writer;
29
import java.util.List;
31
import net.sf.jasperreports.engine.JasperPrint;
35
* @author sanda zaharia (shertage@users.sourceforge.net)
36
* @version $Id: XmlssStyleBuilder.java 3518 2010-03-05 11:53:03Z shertage $
38
public class XmlssStyleBuilder
43
private List jasperPrintList = null;
44
private Writer writer = null;
49
public XmlssStyleBuilder(List jasperPrintList, Writer writer)
51
this.jasperPrintList = jasperPrintList;
58
public void build() throws IOException
60
buildBeforeAutomaticStyles();
62
for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
64
JasperPrint jasperPrint = (JasperPrint)jasperPrintList.get(reportIndex);
66
buildPageLayout(reportIndex, jasperPrint);
69
buildBetweenAutomaticAndMasterStyles();
71
for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
73
buildMasterPage(reportIndex);
76
buildAfterMasterStyles();
84
private void buildBeforeAutomaticStyles() throws IOException
86
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
88
writer.write("<office:document-styles");
89
writer.write(" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"");
90
writer.write(" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\"");
91
writer.write(" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"");
92
writer.write(" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"");
93
writer.write(" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\"");
94
writer.write(" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\"");
95
writer.write(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"");
96
writer.write(" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
97
writer.write(" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\"");
98
writer.write(" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\"");
99
writer.write(" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\"");
100
writer.write(" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\"");
101
writer.write(" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\"");
102
writer.write(" xmlns:math=\"http://www.w3.org/1998/Math/MathML\"");
103
writer.write(" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\"");
104
writer.write(" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\"");
105
writer.write(" xmlns:ooo=\"http://openoffice.org/2004/office\"");
106
writer.write(" xmlns:ooow=\"http://openoffice.org/2004/writer\"");
107
writer.write(" xmlns:oooc=\"http://openoffice.org/2004/calc\"");
108
writer.write(" xmlns:dom=\"http://www.w3.org/2001/xml-events\"");
109
writer.write(" xmlns:xforms=\"http://www.w3.org/2002/xforms\"");
110
writer.write(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
111
writer.write(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
112
writer.write(" office:version=\"");
113
writer.write(XmlssContentBuilder.VERSION);
114
writer.write("\">\n");
116
writer.write(" <office:styles>\n");
117
writer.write("<draw:stroke-dash draw:name=\"Dashed\" draw:display-name=\"Dashed\" " +
118
"draw:style=\"rect\" draw:dots1=\"1\" draw:dots1-length=\"0.05cm\" draw:dots2=\"1\" " +
119
"draw:dots2-length=\"0.05cm\" draw:distance=\"0.05cm\"/>");
120
writer.write(" </office:styles>\n");
121
writer.write(" <office:automatic-styles>\n");
127
private void buildBetweenAutomaticAndMasterStyles() throws IOException
129
writer.write(" </office:automatic-styles>\n");
130
writer.write(" <office:master-styles>\n");
136
private void buildAfterMasterStyles() throws IOException
138
writer.write(" </office:master-styles>\n");
139
writer.write("</office:document-styles>\n");
145
private void buildPageLayout(int reportIndex, JasperPrint jasperPrint) throws IOException
147
writer.write("<style:page-layout");
148
writer.write(" style:name=\"page_" + reportIndex + "\">\n");
150
writer.write("<style:page-layout-properties");
151
writer.write(" fo:page-width=\"" + XmlssUtil.translatePixelsToInchesRound(jasperPrint.getPageWidth()) +"in\"");
152
writer.write(" fo:page-height=\"" + XmlssUtil.translatePixelsToInchesRound(jasperPrint.getPageHeight()) +"in\"");//FIXMEODT we probably need some actualHeight trick
153
writer.write(" fo:margin-top=\"0in\"");//FIXMEODT useless?
154
writer.write(" fo:margin-bottom=\"0in\"");
155
writer.write(" fo:margin-left=\"0in\"");
156
writer.write(" fo:margin-right=\"0in\"");
158
switch (jasperPrint.getOrientationValue())
161
writer.write(" style:print-orientation=\"landscape\"");
164
writer.write(" style:print-orientation=\"portrait\"");
168
writer.write("/>\n");
169
writer.write("</style:page-layout>\n");
175
private void buildMasterPage(int reportIndex) throws IOException
177
writer.write("<style:master-page style:name=\"master_");
178
writer.write(String.valueOf(reportIndex));
179
writer.write("\" style:page-layout-name=\"page_");
180
writer.write(String.valueOf(reportIndex));
181
writer.write("\"/>\n");