~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/engine/export/xmlss/XmlssStyleBuilder.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
package net.sf.jasperreports.engine.export.xmlss;
 
26
 
 
27
import java.io.IOException;
 
28
import java.io.Writer;
 
29
import java.util.List;
 
30
 
 
31
import net.sf.jasperreports.engine.JasperPrint;
 
32
 
 
33
 
 
34
/**
 
35
 * @author sanda zaharia (shertage@users.sourceforge.net)
 
36
 * @version $Id: XmlssStyleBuilder.java 3518 2010-03-05 11:53:03Z shertage $
 
37
 */
 
38
public class XmlssStyleBuilder
 
39
{
 
40
        /**
 
41
         * 
 
42
         */
 
43
        private List jasperPrintList = null;
 
44
        private Writer writer = null;
 
45
        
 
46
        /**
 
47
         * 
 
48
         */
 
49
        public XmlssStyleBuilder(List jasperPrintList, Writer writer)
 
50
        {
 
51
                this.jasperPrintList = jasperPrintList;
 
52
                this.writer = writer;
 
53
        }
 
54
 
 
55
        /**
 
56
         * 
 
57
         */
 
58
        public void build() throws IOException
 
59
        {
 
60
                buildBeforeAutomaticStyles();
 
61
                
 
62
                for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
 
63
                {
 
64
                        JasperPrint jasperPrint = (JasperPrint)jasperPrintList.get(reportIndex);
 
65
                        
 
66
                        buildPageLayout(reportIndex, jasperPrint);
 
67
                }
 
68
 
 
69
                buildBetweenAutomaticAndMasterStyles();
 
70
 
 
71
                for(int reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
 
72
                {
 
73
                        buildMasterPage(reportIndex);
 
74
                }
 
75
 
 
76
                buildAfterMasterStyles();
 
77
                
 
78
                writer.flush();
 
79
        }
 
80
        
 
81
        /**
 
82
         * 
 
83
         */
 
84
        private void buildBeforeAutomaticStyles() throws IOException
 
85
        {
 
86
                writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
 
87
 
 
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");          
 
115
 
 
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");   
 
122
        }
 
123
        
 
124
        /**
 
125
         * 
 
126
         */
 
127
        private void buildBetweenAutomaticAndMasterStyles() throws IOException
 
128
        {
 
129
                writer.write(" </office:automatic-styles>\n");
 
130
                writer.write(" <office:master-styles>\n");      
 
131
        }
 
132
        
 
133
        /**
 
134
         * 
 
135
         */
 
136
        private void buildAfterMasterStyles() throws IOException
 
137
        {
 
138
                writer.write(" </office:master-styles>\n");     
 
139
                writer.write("</office:document-styles>\n");
 
140
        }
 
141
 
 
142
        /**
 
143
         * 
 
144
         */
 
145
        private void buildPageLayout(int reportIndex, JasperPrint jasperPrint) throws IOException 
 
146
        {
 
147
                        writer.write("<style:page-layout");
 
148
                        writer.write(" style:name=\"page_" + reportIndex + "\">\n");
 
149
                        
 
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\"");
 
157
 
 
158
                        switch (jasperPrint.getOrientationValue())
 
159
                        {
 
160
                                case LANDSCAPE:
 
161
                                        writer.write(" style:print-orientation=\"landscape\"");
 
162
                                        break;
 
163
                                default:
 
164
                                        writer.write(" style:print-orientation=\"portrait\"");
 
165
                                        break;
 
166
                        }
 
167
                        
 
168
                        writer.write("/>\n");
 
169
                        writer.write("</style:page-layout>\n");
 
170
        }
 
171
 
 
172
        /**
 
173
         * 
 
174
         */
 
175
        private void buildMasterPage(int reportIndex) throws IOException 
 
176
        {
 
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");
 
182
        }
 
183
 
 
184
}