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.awt.Color;
031:
032: import net.sf.jasperreports.engine.design.JRDesignStyle;
033:
034: import org.xml.sax.Attributes;
035:
036: /**
037: * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
038: * @version $Id: JRAbstractStyleFactory.java 1759 2007-06-20 16:47:34Z lucianc $
039: */
040: public abstract class JRAbstractStyleFactory extends JRBaseFactory {
041:
042: /**
043: *
044: */
045: public Object createObject(Attributes atts) {
046: JRDesignStyle style = new JRDesignStyle();
047:
048: // get style name
049: style.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name));
050:
051: String isDefault = atts
052: .getValue(JRXmlConstants.ATTRIBUTE_isDefault);
053: if (isDefault != null && isDefault.length() > 0) {
054: style.setDefault(Boolean.valueOf(isDefault).booleanValue());
055: }
056:
057: // get parent style
058: if (atts.getValue(JRXmlConstants.ATTRIBUTE_style) != null) {
059: setParentStyle(style, atts
060: .getValue(JRXmlConstants.ATTRIBUTE_style));
061: }
062:
063: // get JRElement attributes
064: Byte mode = (Byte) JRXmlConstants.getModeMap().get(
065: atts.getValue(JRXmlConstants.ATTRIBUTE_mode));
066: if (mode != null) {
067: style.setMode(mode);
068: }
069:
070: String forecolor = atts
071: .getValue(JRXmlConstants.ATTRIBUTE_forecolor);
072: style.setForecolor(JRXmlConstants.getColor(forecolor, null));
073:
074: String backcolor = atts
075: .getValue(JRXmlConstants.ATTRIBUTE_backcolor);
076: style.setBackcolor(JRXmlConstants.getColor(backcolor, null));
077:
078: // get graphic element attributes
079: Byte pen = (Byte) JRXmlConstants.getPenMap().get(
080: atts.getValue(JRXmlConstants.ATTRIBUTE_pen));
081: style.setPen(pen);
082:
083: Byte fill = (Byte) JRXmlConstants.getFillMap().get(
084: atts.getValue(JRXmlConstants.ATTRIBUTE_fill));
085: style.setFill(fill);
086:
087: // get rectangle attributes
088: String radius = atts.getValue(JRXmlConstants.ATTRIBUTE_radius);
089: if (radius != null && radius.length() > 0) {
090: style.setRadius(Integer.parseInt(radius));
091: }
092:
093: // get image attributes
094: Byte scaleImage = (Byte) JRXmlConstants.getScaleImageMap().get(
095: atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage));
096: if (scaleImage != null) {
097: style.setScaleImage(scaleImage);
098: }
099:
100: Byte horizontalAlignment = (Byte) JRXmlConstants
101: .getHorizontalAlignMap().get(
102: atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign));
103: if (horizontalAlignment != null) {
104: style.setHorizontalAlignment(horizontalAlignment);
105: }
106:
107: Byte verticalAlignment = (Byte) JRXmlConstants
108: .getVerticalAlignMap().get(
109: atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign));
110: if (verticalAlignment != null) {
111: style.setVerticalAlignment(verticalAlignment);
112: }
113:
114: // get box attributes
115: Byte border = (Byte) JRXmlConstants.getPenMap().get(
116: atts.getValue(JRXmlConstants.ATTRIBUTE_border));
117: if (border != null) {
118: style.setBorder(border);
119: }
120:
121: Color borderColor = JRXmlConstants.getColor(atts
122: .getValue(JRXmlConstants.ATTRIBUTE_borderColor), null);
123: if (borderColor != null) {
124: style.setBorderColor(borderColor);
125: }
126:
127: String padding = atts
128: .getValue(JRXmlConstants.ATTRIBUTE_padding);
129: if (padding != null && padding.length() > 0) {
130: style.setPadding(Integer.parseInt(padding));
131: }
132:
133: border = (Byte) JRXmlConstants.getPenMap().get(
134: atts.getValue(JRXmlConstants.ATTRIBUTE_topBorder));
135: if (border != null) {
136: style.setTopBorder(border);
137: }
138:
139: borderColor = JRXmlConstants.getColor(atts
140: .getValue(JRXmlConstants.ATTRIBUTE_topBorderColor),
141: Color.black);
142: if (borderColor != null) {
143: style.setTopBorderColor(borderColor);
144: }
145:
146: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_topPadding);
147: if (padding != null && padding.length() > 0) {
148: style.setTopPadding(Integer.parseInt(padding));
149: }
150:
151: border = (Byte) JRXmlConstants.getPenMap().get(
152: atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorder));
153: if (border != null) {
154: style.setLeftBorder(border);
155: }
156:
157: borderColor = JRXmlConstants.getColor(atts
158: .getValue(JRXmlConstants.ATTRIBUTE_leftBorderColor),
159: Color.black);
160: if (borderColor != null) {
161: style.setLeftBorderColor(borderColor);
162: }
163:
164: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_leftPadding);
165: if (padding != null && padding.length() > 0) {
166: style.setLeftPadding(Integer.parseInt(padding));
167: }
168:
169: border = (Byte) JRXmlConstants.getPenMap().get(
170: atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorder));
171: if (border != null) {
172: style.setBottomBorder(border);
173: }
174:
175: borderColor = JRXmlConstants.getColor(atts
176: .getValue(JRXmlConstants.ATTRIBUTE_bottomBorderColor),
177: Color.black);
178: if (borderColor != null) {
179: style.setBottomBorderColor(borderColor);
180: }
181:
182: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_bottomPadding);
183: if (padding != null && padding.length() > 0) {
184: style.setBottomPadding(Integer.parseInt(padding));
185: }
186:
187: border = (Byte) JRXmlConstants.getPenMap().get(
188: atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorder));
189: if (border != null) {
190: style.setRightBorder(border);
191: }
192:
193: borderColor = JRXmlConstants.getColor(atts
194: .getValue(JRXmlConstants.ATTRIBUTE_rightBorderColor),
195: Color.black);
196: if (borderColor != null) {
197: style.setRightBorderColor(borderColor);
198: }
199:
200: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_rightPadding);
201: if (padding != null && padding.length() > 0) {
202: style.setRightPadding(Integer.parseInt(padding));
203: }
204:
205: Byte rotation = (Byte) JRXmlConstants.getRotationMap().get(
206: atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
207: if (rotation != null) {
208: style.setRotation(rotation);
209: }
210:
211: Byte lineSpacing = (Byte) JRXmlConstants
212: .getLineSpacingMap()
213: .get(
214: atts
215: .getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
216: if (lineSpacing != null) {
217: style.setLineSpacing(lineSpacing);
218: }
219:
220: String isStyledText = atts
221: .getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
222: if (isStyledText != null && isStyledText.length() > 0) {
223: style.setStyledText(Boolean.valueOf(isStyledText));
224: }
225:
226: style.setPattern(atts
227: .getValue(JRXmlConstants.ATTRIBUTE_pattern));
228:
229: String isBlankWhenNull = atts
230: .getValue(JRXmlConstants.ATTRIBUTE_isBlankWhenNull);
231: if (isBlankWhenNull != null && isBlankWhenNull.length() > 0) {
232: style.setBlankWhenNull(Boolean.valueOf(isBlankWhenNull));
233: }
234:
235: if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null)
236: style.setFontName(atts
237: .getValue(JRXmlConstants.ATTRIBUTE_fontName));
238:
239: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null)
240: style.setBold(Boolean.valueOf(atts
241: .getValue(JRXmlConstants.ATTRIBUTE_isBold)));
242:
243: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null)
244: style.setItalic(Boolean.valueOf(atts
245: .getValue(JRXmlConstants.ATTRIBUTE_isItalic)));
246:
247: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null)
248: style.setUnderline(Boolean.valueOf(atts
249: .getValue(JRXmlConstants.ATTRIBUTE_isUnderline)));
250:
251: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null)
252: style
253: .setStrikeThrough(Boolean
254: .valueOf(atts
255: .getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough)));
256:
257: if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontSize) != null)
258: style.setFontSize(Integer.valueOf(atts
259: .getValue(JRXmlConstants.ATTRIBUTE_fontSize)));
260:
261: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null)
262: style.setPdfFontName(atts
263: .getValue(JRXmlConstants.ATTRIBUTE_pdfFontName));
264:
265: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null)
266: style.setPdfEncoding(atts
267: .getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding));
268:
269: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null)
270: style.setPdfEmbedded(Boolean.valueOf(atts
271: .getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded)));
272:
273: return style;
274: }
275:
276: protected abstract void setParentStyle(JRDesignStyle currentStyle,
277: String parentStyleName);
278:
279: }
|