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/>.
24
package net.sf.jasperreports.engine.xml;
26
import java.io.IOException;
28
import net.sf.jasperreports.engine.JRConditionalStyle;
29
import net.sf.jasperreports.engine.JRLineBox;
30
import net.sf.jasperreports.engine.JRPen;
31
import net.sf.jasperreports.engine.JRStyle;
32
import net.sf.jasperreports.engine.JRStyleContainer;
33
import net.sf.jasperreports.engine.util.JRXmlWriteHelper;
34
import net.sf.jasperreports.engine.util.XmlNamespace;
40
* @author Lucian Chirita (lucianc@users.sourceforge.net)
41
* @version $Id: JRXmlBaseWriter.java 3794 2010-05-13 07:47:16Z teodord $
43
public abstract class JRXmlBaseWriter
46
protected JRXmlWriteHelper writer;
49
* Sets the XML write helper.
51
* @param aWriter the XML write helper
53
protected void useWriter(JRXmlWriteHelper aWriter)
55
this.writer = aWriter;
61
* @param style the style to write.
64
protected void writeStyle(JRStyle style) throws IOException
66
writer.startElement(JRXmlConstants.ELEMENT_style);
67
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, style.getName());
68
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isDefault, style.isDefault(), false);
69
writeStyleReferenceAttr(style);
70
writer.addAttribute(JRXmlConstants.ATTRIBUTE_mode, style.getOwnModeValue());
71
writer.addAttribute(JRXmlConstants.ATTRIBUTE_forecolor, style.getOwnForecolor());
72
writer.addAttribute(JRXmlConstants.ATTRIBUTE_backcolor, style.getOwnBackcolor());
73
writer.addAttribute(JRXmlConstants.ATTRIBUTE_fill, style.getOwnFillValue());
74
writer.addAttribute(JRXmlConstants.ATTRIBUTE_radius, style.getOwnRadius());
75
writer.addAttribute(JRXmlConstants.ATTRIBUTE_scaleImage, style.getOwnScaleImageValue());
76
writer.addAttribute(JRXmlConstants.ATTRIBUTE_hAlign, style.getOwnHorizontalAlignmentValue());
77
writer.addAttribute(JRXmlConstants.ATTRIBUTE_vAlign, style.getOwnVerticalAlignmentValue());
78
writer.addAttribute(JRXmlConstants.ATTRIBUTE_rotation, style.getOwnRotationValue());
79
writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacing, style.getOwnLineSpacingValue());
80
writer.addAttribute(JRXmlConstants.ATTRIBUTE_markup, style.getOwnMarkup());
81
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_pattern, style.getOwnPattern());
82
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isBlankWhenNull, style.isOwnBlankWhenNull());
84
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_fontName, style.getOwnFontName());
85
writer.addAttribute(JRXmlConstants.ATTRIBUTE_fontSize, style.getOwnFontSize());
86
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isBold, style.isOwnBold());
87
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isItalic, style.isOwnItalic());
88
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isUnderline, style.isOwnUnderline());
89
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isStrikeThrough, style.isOwnStrikeThrough());
90
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_pdfFontName, style.getOwnPdfFontName());
91
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_pdfEncoding, style.getOwnPdfEncoding());
92
writer.addAttribute(JRXmlConstants.ATTRIBUTE_isPdfEmbedded, style.isOwnPdfEmbedded());
94
writePen(style.getLinePen());
95
writeBox(style.getLineBox());
97
if (toWriteConditionalStyles())
99
JRConditionalStyle[] conditionalStyles = style.getConditionalStyles();
100
if (!(style instanceof JRConditionalStyle) && conditionalStyles != null)
102
for (int i = 0; i < conditionalStyles.length; i++)
104
writeConditionalStyle(conditionalStyles[i]);
109
writer.closeElement();
112
public void writeStyleReferenceAttr(JRStyleContainer styleContainer)
114
if (!(styleContainer instanceof JRConditionalStyle))
116
if (styleContainer.getStyle() != null)
118
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_style, styleContainer.getStyle().getName());
120
else if (styleContainer.getStyleNameReference() != null)
122
writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_style, styleContainer.getStyleNameReference());
128
* Decides whether conditional styles are to be written.
130
* @return whether conditional styles are to be written
132
protected abstract boolean toWriteConditionalStyles();
135
* Writes a conditional style.
137
* @param style the conditional style
138
* @throws IOException
140
protected void writeConditionalStyle(JRConditionalStyle style) throws IOException
142
writer.startElement(JRXmlConstants.ELEMENT_conditionalStyle);
143
writer.writeExpression(JRXmlConstants.ELEMENT_conditionExpression, style.getConditionExpression(), false);
145
writer.closeElement();
151
protected void writePen(JRPen pen) throws IOException
153
writePen(JRXmlConstants.ELEMENT_pen, pen);
159
private void writePen(String element, JRPen pen) throws IOException
161
writer.startElement(element);
162
writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineWidth, pen.getOwnLineWidth());
163
writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineStyle, pen.getOwnLineStyleValue());
164
writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineColor, pen.getOwnLineColor());
165
writer.closeElement(true);
168
public void writeBox(JRLineBox box) throws IOException
176
public void writeBox(JRLineBox box, XmlNamespace namespace) throws IOException
180
writer.startElement(JRXmlConstants.ELEMENT_box, namespace);
182
writer.addAttribute(JRXmlConstants.ATTRIBUTE_padding, box.getOwnPadding());
183
writer.addAttribute(JRXmlConstants.ATTRIBUTE_topPadding, box.getOwnTopPadding());
184
writer.addAttribute(JRXmlConstants.ATTRIBUTE_leftPadding, box.getOwnLeftPadding());
185
writer.addAttribute(JRXmlConstants.ATTRIBUTE_bottomPadding, box.getOwnBottomPadding());
186
writer.addAttribute(JRXmlConstants.ATTRIBUTE_rightPadding, box.getOwnRightPadding());
188
writePen(JRXmlConstants.ELEMENT_pen, box.getPen());
189
writePen(JRXmlConstants.ELEMENT_topPen, box.getTopPen());
190
writePen(JRXmlConstants.ELEMENT_leftPen, box.getLeftPen());
191
writePen(JRXmlConstants.ELEMENT_bottomPen, box.getBottomPen());
192
writePen(JRXmlConstants.ELEMENT_rightPen, box.getRightPen());
194
writer.closeElement(true);