KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > xml > JRPrintElementFactory


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.xml;
29
30 import java.awt.Color JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import net.sf.jasperreports.engine.JRStyle;
34 import net.sf.jasperreports.engine.JasperPrint;
35 import net.sf.jasperreports.engine.base.JRBasePrintElement;
36
37 import org.xml.sax.Attributes JavaDoc;
38
39
40 /**
41  * @author Teodor Danciu (teodord@users.sourceforge.net)
42  * @version $Id: JRPrintElementFactory.java 1471 2006-11-09 18:16:34 +0200 (Thu, 09 Nov 2006) lucianc $
43  */

44 public class JRPrintElementFactory extends JRBaseFactory
45 {
46
47
48     public static final String JavaDoc ATTRIBUTE_key = "key";
49     
50     /**
51      *
52      */

53     private static final String JavaDoc ATTRIBUTE_mode = "mode";
54     private static final String JavaDoc ATTRIBUTE_x = "x";
55     private static final String JavaDoc ATTRIBUTE_y = "y";
56     private static final String JavaDoc ATTRIBUTE_width = "width";
57     private static final String JavaDoc ATTRIBUTE_height = "height";
58     private static final String JavaDoc ATTRIBUTE_forecolor = "forecolor";
59     private static final String JavaDoc ATTRIBUTE_backcolor = "backcolor";
60     private static final String JavaDoc ATTRIBUTE_style = "style";
61
62
63     /**
64      *
65      */

66     public Object JavaDoc createObject(Attributes JavaDoc atts)
67     {
68         JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader)digester.peek(digester.getCount() - 1);
69         JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2);
70         JRBasePrintElement element = (JRBasePrintElement)digester.peek();
71
72         String JavaDoc key = atts.getValue(ATTRIBUTE_key);
73         if (key != null)
74         {
75             element.setKey(key);
76         }
77         
78         Byte JavaDoc mode = (Byte JavaDoc)JRXmlConstants.getModeMap().get(atts.getValue(ATTRIBUTE_mode));
79         if (mode != null)
80         {
81             element.setMode(mode);
82         }
83         
84         String JavaDoc x = atts.getValue(ATTRIBUTE_x);
85         if (x != null && x.length() > 0)
86         {
87             element.setX(Integer.parseInt(x));
88         }
89
90         String JavaDoc y = atts.getValue(ATTRIBUTE_y);
91         if (y != null && y.length() > 0)
92         {
93             element.setY(Integer.parseInt(y));
94         }
95
96         String JavaDoc width = atts.getValue(ATTRIBUTE_width);
97         if (width != null && width.length() > 0)
98         {
99             element.setWidth(Integer.parseInt(width));
100         }
101
102         String JavaDoc height = atts.getValue(ATTRIBUTE_height);
103         if (height != null && height.length() > 0)
104         {
105             element.setHeight(Integer.parseInt(height));
106         }
107
108         String JavaDoc forecolor = atts.getValue(ATTRIBUTE_forecolor);
109         if (forecolor != null)
110         {
111             if (forecolor.startsWith("#"))
112             {
113                 element.setForecolor(new Color JavaDoc(Integer.parseInt(forecolor.substring(1), 16)));
114             }
115             else
116             {
117                 element.setForecolor(new Color JavaDoc(Integer.parseInt(forecolor)));
118             }
119         }
120
121         String JavaDoc backcolor = atts.getValue(ATTRIBUTE_backcolor);
122         if (backcolor != null)
123         {
124             if (backcolor.startsWith("#"))
125             {
126                 element.setBackcolor(new Color JavaDoc(Integer.parseInt(backcolor.substring(1), 16)));
127             }
128             else
129             {
130                 element.setBackcolor(new Color JavaDoc(Integer.parseInt(backcolor)));
131             }
132         }
133
134         if (atts.getValue(ATTRIBUTE_style) != null)
135         {
136             Map JavaDoc stylesMap = jasperPrint.getStylesMap();
137
138             if ( !stylesMap.containsKey(atts.getValue(ATTRIBUTE_style)) )
139             {
140                 printXmlLoader.addError(new Exception JavaDoc("Unknown report style : " + atts.getValue(ATTRIBUTE_style)));
141             }
142
143             element.setStyle((JRStyle) stylesMap.get(atts.getValue(ATTRIBUTE_style)));
144         }
145
146         return element;
147     }
148     
149
150 }
151
Popular Tags