001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.xml;
029:
030: import java.io.IOException;
031:
032: import net.sf.jasperreports.engine.JRConditionalStyle;
033: import net.sf.jasperreports.engine.JRStyle;
034: import net.sf.jasperreports.engine.util.JRXmlWriteHelper;
035:
036: /**
037: * Base XML writer.
038: *
039: * @author Lucian Chirita (lucianc@users.sourceforge.net)
040: * @version $Id: JRXmlBaseWriter.java 1763 2007-06-21 08:47:21Z lucianc $
041: */
042: public abstract class JRXmlBaseWriter {
043:
044: protected JRXmlWriteHelper writer;
045:
046: /**
047: * Sets the XML write helper.
048: *
049: * @param aWriter the XML write helper
050: */
051: protected void useWriter(JRXmlWriteHelper aWriter) {
052: this .writer = aWriter;
053: }
054:
055: /**
056: * Writes a style.
057: *
058: * @param style the style to write.
059: * @throws IOException
060: */
061: protected void writeStyle(JRStyle style) throws IOException {
062: writer.startElement(JRXmlConstants.ELEMENT_style);
063: writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, style
064: .getName());
065: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isDefault, style
066: .isDefault());
067:
068: if (style.getStyle() != null) {
069: writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_style,
070: style.getStyle().getName());
071: } else if (style.getStyleNameReference() != null) {
072: writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_style,
073: style.getStyleNameReference());
074: }
075:
076: writer.addAttribute(JRXmlConstants.ATTRIBUTE_mode, style
077: .getOwnMode(), JRXmlConstants.getModeMap());
078: writer.addAttribute(JRXmlConstants.ATTRIBUTE_forecolor, style
079: .getOwnForecolor());
080: writer.addAttribute(JRXmlConstants.ATTRIBUTE_backcolor, style
081: .getOwnBackcolor());
082: writer.addAttribute(JRXmlConstants.ATTRIBUTE_pen, style
083: .getOwnPen(), JRXmlConstants.getPenMap());
084: writer.addAttribute(JRXmlConstants.ATTRIBUTE_fill, style
085: .getOwnFill(), JRXmlConstants.getFillMap());
086: writer.addAttribute(JRXmlConstants.ATTRIBUTE_radius, style
087: .getOwnRadius());
088: writer.addAttribute(JRXmlConstants.ATTRIBUTE_scaleImage, style
089: .getOwnScaleImage(), JRXmlConstants.getScaleImageMap());
090: writer.addAttribute(JRXmlConstants.ATTRIBUTE_hAlign, style
091: .getOwnHorizontalAlignment(), JRXmlConstants
092: .getHorizontalAlignMap());
093: writer.addAttribute(JRXmlConstants.ATTRIBUTE_vAlign, style
094: .getOwnVerticalAlignment(), JRXmlConstants
095: .getVerticalAlignMap());
096: writer.addAttribute(JRXmlConstants.ATTRIBUTE_rotation, style
097: .getOwnRotation(), JRXmlConstants.getRotationMap());
098: writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacing, style
099: .getOwnLineSpacing(), JRXmlConstants
100: .getLineSpacingMap());
101: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isStyledText,
102: style.isOwnStyledText());
103: writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_pattern,
104: style.getOwnPattern());
105: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isBlankWhenNull,
106: style.isOwnBlankWhenNull());
107:
108: writer.addAttribute(JRXmlConstants.ATTRIBUTE_border, style
109: .getOwnBorder(), JRXmlConstants.getPenMap());
110: writer.addAttribute(JRXmlConstants.ATTRIBUTE_borderColor, style
111: .getOwnBorderColor());
112: writer.addAttribute(JRXmlConstants.ATTRIBUTE_padding, style
113: .getOwnPadding());
114:
115: writer.addAttribute(JRXmlConstants.ATTRIBUTE_topBorder, style
116: .getOwnTopBorder(), JRXmlConstants.getPenMap());
117: writer.addAttribute(JRXmlConstants.ATTRIBUTE_topBorderColor,
118: style.getOwnTopBorderColor());
119: writer.addAttribute(JRXmlConstants.ATTRIBUTE_topPadding, style
120: .getOwnTopPadding());
121:
122: writer.addAttribute(JRXmlConstants.ATTRIBUTE_leftBorder, style
123: .getOwnLeftBorder(), JRXmlConstants.getPenMap());
124: writer.addAttribute(JRXmlConstants.ATTRIBUTE_leftBorderColor,
125: style.getOwnLeftBorderColor());
126: writer.addAttribute(JRXmlConstants.ATTRIBUTE_leftPadding, style
127: .getOwnLeftPadding());
128:
129: writer.addAttribute(JRXmlConstants.ATTRIBUTE_bottomBorder,
130: style.getOwnBottomBorder(), JRXmlConstants.getPenMap());
131: writer.addAttribute(JRXmlConstants.ATTRIBUTE_bottomBorderColor,
132: style.getOwnBottomBorderColor());
133: writer.addAttribute(JRXmlConstants.ATTRIBUTE_bottomPadding,
134: style.getOwnBottomPadding());
135:
136: writer.addAttribute(JRXmlConstants.ATTRIBUTE_rightBorder, style
137: .getOwnRightBorder(), JRXmlConstants.getPenMap());
138: writer.addAttribute(JRXmlConstants.ATTRIBUTE_rightBorderColor,
139: style.getOwnRightBorderColor());
140: writer.addAttribute(JRXmlConstants.ATTRIBUTE_rightPadding,
141: style.getOwnRightPadding());
142:
143: writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_fontName,
144: style.getOwnFontName());
145: writer.addAttribute(JRXmlConstants.ATTRIBUTE_fontSize, style
146: .getOwnFontSize());
147: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isBold, style
148: .isOwnBold());
149: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isItalic, style
150: .isOwnItalic());
151: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isUnderline, style
152: .isOwnUnderline());
153: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isStrikeThrough,
154: style.isOwnStrikeThrough());
155: writer.addEncodedAttribute(
156: JRXmlConstants.ATTRIBUTE_pdfFontName, style
157: .getOwnPdfFontName());
158: writer.addEncodedAttribute(
159: JRXmlConstants.ATTRIBUTE_pdfEncoding, style
160: .getOwnPdfEncoding());
161: writer.addAttribute(JRXmlConstants.ATTRIBUTE_isPdfEmbedded,
162: style.isOwnPdfEmbedded());
163:
164: if (toWriteConditionalStyles()) {
165: JRConditionalStyle[] conditionalStyles = style
166: .getConditionalStyles();
167: if (!(style instanceof JRConditionalStyle)
168: && conditionalStyles != null) {
169: for (int i = 0; i < conditionalStyles.length; i++) {
170: writeConditionalStyle(conditionalStyles[i]);
171: }
172: }
173: }
174:
175: writer.closeElement();
176: }
177:
178: /**
179: * Decides whether conditional styles are to be written.
180: *
181: * @return whether conditional styles are to be written
182: */
183: protected abstract boolean toWriteConditionalStyles();
184:
185: /**
186: * Writes a conditional style.
187: *
188: * @param style the conditional style
189: * @throws IOException
190: */
191: protected void writeConditionalStyle(JRConditionalStyle style)
192: throws IOException {
193: writer.startElement(JRXmlConstants.ELEMENT_conditionalStyle);
194: writer.writeExpression(
195: JRXmlConstants.ELEMENT_conditionExpression, style
196: .getConditionExpression(), false);
197: writeStyle(style);
198: writer.closeElement();
199: }
200:
201: }
|