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: import java.util.Map;
032:
033: import net.sf.jasperreports.engine.JRStyle;
034: import net.sf.jasperreports.engine.JasperPrint;
035: import net.sf.jasperreports.engine.base.JRBasePrintElement;
036:
037: import org.xml.sax.Attributes;
038:
039: /**
040: * @author Teodor Danciu (teodord@users.sourceforge.net)
041: * @version $Id: JRPrintElementFactory.java 1581 2007-02-12 14:19:02Z shertage $
042: */
043: public class JRPrintElementFactory extends JRBaseFactory {
044:
045: /**
046: *
047: */
048: public Object createObject(Attributes atts) {
049: JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader) digester
050: .peek(digester.getCount() - 1);
051: JasperPrint jasperPrint = (JasperPrint) digester.peek(digester
052: .getCount() - 2);
053: JRBasePrintElement element = (JRBasePrintElement) digester
054: .peek();
055:
056: String key = atts.getValue(JRXmlConstants.ATTRIBUTE_key);
057: if (key != null) {
058: element.setKey(key);
059: }
060:
061: Byte mode = (Byte) JRXmlConstants.getModeMap().get(
062: atts.getValue(JRXmlConstants.ATTRIBUTE_mode));
063: if (mode != null) {
064: element.setMode(mode);
065: }
066:
067: String x = atts.getValue(JRXmlConstants.ATTRIBUTE_x);
068: if (x != null && x.length() > 0) {
069: element.setX(Integer.parseInt(x));
070: }
071:
072: String y = atts.getValue(JRXmlConstants.ATTRIBUTE_y);
073: if (y != null && y.length() > 0) {
074: element.setY(Integer.parseInt(y));
075: }
076:
077: String width = atts.getValue(JRXmlConstants.ATTRIBUTE_width);
078: if (width != null && width.length() > 0) {
079: element.setWidth(Integer.parseInt(width));
080: }
081:
082: String height = atts.getValue(JRXmlConstants.ATTRIBUTE_height);
083: if (height != null && height.length() > 0) {
084: element.setHeight(Integer.parseInt(height));
085: }
086:
087: String forecolor = atts
088: .getValue(JRXmlConstants.ATTRIBUTE_forecolor);
089: if (forecolor != null) {
090: if (forecolor.startsWith("#")) {
091: element.setForecolor(new Color(Integer.parseInt(
092: forecolor.substring(1), 16)));
093: } else {
094: element.setForecolor(new Color(Integer
095: .parseInt(forecolor)));
096: }
097: }
098:
099: String backcolor = atts
100: .getValue(JRXmlConstants.ATTRIBUTE_backcolor);
101: if (backcolor != null) {
102: if (backcolor.startsWith("#")) {
103: element.setBackcolor(new Color(Integer.parseInt(
104: backcolor.substring(1), 16)));
105: } else {
106: element.setBackcolor(new Color(Integer
107: .parseInt(backcolor)));
108: }
109: }
110:
111: if (atts.getValue(JRXmlConstants.ATTRIBUTE_style) != null) {
112: Map stylesMap = jasperPrint.getStylesMap();
113:
114: if (!stylesMap.containsKey(atts
115: .getValue(JRXmlConstants.ATTRIBUTE_style))) {
116: printXmlLoader
117: .addError(new Exception(
118: "Unknown report style : "
119: + atts
120: .getValue(JRXmlConstants.ATTRIBUTE_style)));
121: }
122:
123: element.setStyle((JRStyle) stylesMap.get(atts
124: .getValue(JRXmlConstants.ATTRIBUTE_style)));
125: }
126:
127: return element;
128: }
129:
130: }
|