KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Collection JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import net.sf.jasperreports.engine.JRStyle;
34 import net.sf.jasperreports.engine.design.JRDesignElement;
35 import net.sf.jasperreports.engine.design.JRDesignGroup;
36 import net.sf.jasperreports.engine.design.JasperDesign;
37
38 import org.xml.sax.Attributes JavaDoc;
39
40
41 /**
42  * @author Teodor Danciu (teodord@users.sourceforge.net)
43  * @version $Id: JRElementFactory.java 1291 2006-06-13 18:11:10 +0300 (Tue, 13 Jun 2006) teodord $
44  */

45 public class JRElementFactory extends JRBaseFactory
46 {
47
48
49     /**
50      *
51      */

52     private static final String JavaDoc ATTRIBUTE_key = "key";
53     private static final String JavaDoc ATTRIBUTE_positionType = "positionType";
54     private static final String JavaDoc ATTRIBUTE_stretchType = "stretchType";
55     private static final String JavaDoc ATTRIBUTE_isPrintRepeatedValues = "isPrintRepeatedValues";
56     private static final String JavaDoc ATTRIBUTE_mode = "mode";
57     private static final String JavaDoc ATTRIBUTE_x = "x";
58     private static final String JavaDoc ATTRIBUTE_y = "y";
59     private static final String JavaDoc ATTRIBUTE_width = "width";
60     private static final String JavaDoc ATTRIBUTE_height = "height";
61     private static final String JavaDoc ATTRIBUTE_isRemoveLineWhenBlank = "isRemoveLineWhenBlank";
62     private static final String JavaDoc ATTRIBUTE_isPrintInFirstWholeBand = "isPrintInFirstWholeBand";
63     private static final String JavaDoc ATTRIBUTE_isPrintWhenDetailOverflows = "isPrintWhenDetailOverflows";
64     private static final String JavaDoc ATTRIBUTE_printWhenGroupChanges = "printWhenGroupChanges";
65     private static final String JavaDoc ATTRIBUTE_forecolor = "forecolor";
66     private static final String JavaDoc ATTRIBUTE_backcolor = "backcolor";
67     private static final String JavaDoc ATTRIBUTE_style = "style";
68
69
70     /**
71      *
72      */

73     public Object JavaDoc createObject(Attributes JavaDoc atts)
74     {
75         JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
76         JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2);
77         Collection JavaDoc groupReprintedElements = xmlLoader.getGroupReprintedElements();
78
79         JRDesignElement element = (JRDesignElement)digester.peek();
80
81         element.setKey(atts.getValue(ATTRIBUTE_key));
82
83         Byte JavaDoc positionType = (Byte JavaDoc)JRXmlConstants.getPositionTypeMap().get(atts.getValue(ATTRIBUTE_positionType));
84         if (positionType != null)
85         {
86             element.setPositionType(positionType.byteValue());
87         }
88
89         Byte JavaDoc stretchType = (Byte JavaDoc)JRXmlConstants.getStretchTypeMap().get(atts.getValue(ATTRIBUTE_stretchType));
90         if (stretchType != null)
91         {
92             element.setStretchType(stretchType.byteValue());
93         }
94
95         String JavaDoc isPrintRepeatedValues = atts.getValue(ATTRIBUTE_isPrintRepeatedValues);
96         if (isPrintRepeatedValues != null && isPrintRepeatedValues.length() > 0)
97         {
98             element.setPrintRepeatedValues(Boolean.valueOf(isPrintRepeatedValues).booleanValue());
99         }
100         
101         Byte JavaDoc mode = (Byte JavaDoc)JRXmlConstants.getModeMap().get(atts.getValue(ATTRIBUTE_mode));
102         if (mode != null)
103         {
104             element.setMode(mode);
105         }
106         
107         String JavaDoc x = atts.getValue(ATTRIBUTE_x);
108         if (x != null && x.length() > 0)
109         {
110             element.setX(Integer.parseInt(x));
111         }
112
113         String JavaDoc y = atts.getValue(ATTRIBUTE_y);
114         if (y != null && y.length() > 0)
115         {
116             element.setY(Integer.parseInt(y));
117         }
118
119         String JavaDoc width = atts.getValue(ATTRIBUTE_width);
120         if (width != null && width.length() > 0)
121         {
122             element.setWidth(Integer.parseInt(width));
123         }
124
125         String JavaDoc height = atts.getValue(ATTRIBUTE_height);
126         if (height != null && height.length() > 0)
127         {
128             element.setHeight(Integer.parseInt(height));
129         }
130
131         String JavaDoc isRemoveLineWhenBlank = atts.getValue(ATTRIBUTE_isRemoveLineWhenBlank);
132         if (isRemoveLineWhenBlank != null && isRemoveLineWhenBlank.length() > 0)
133         {
134             element.setRemoveLineWhenBlank(Boolean.valueOf(isRemoveLineWhenBlank).booleanValue());
135         }
136
137         String JavaDoc isPrintInFirstWholeBand = atts.getValue(ATTRIBUTE_isPrintInFirstWholeBand);
138         if (isPrintInFirstWholeBand != null && isPrintInFirstWholeBand.length() > 0)
139         {
140             element.setPrintInFirstWholeBand(Boolean.valueOf(isPrintInFirstWholeBand).booleanValue());
141         }
142
143         String JavaDoc isPrintWhenDetailOverflows = atts.getValue(ATTRIBUTE_isPrintWhenDetailOverflows);
144         if (isPrintWhenDetailOverflows != null && isPrintWhenDetailOverflows.length() > 0)
145         {
146             element.setPrintWhenDetailOverflows(Boolean.valueOf(isPrintWhenDetailOverflows).booleanValue());
147         }
148
149         String JavaDoc groupName = atts.getValue(ATTRIBUTE_printWhenGroupChanges);
150         if (groupName != null)
151         {
152             JRDesignGroup group = new JRDesignGroup();
153             group.setName(groupName);
154             element.setPrintWhenGroupChanges(group);
155             groupReprintedElements.add(element);
156         }
157
158         String JavaDoc forecolor = atts.getValue(ATTRIBUTE_forecolor);
159         if (forecolor != null && forecolor.length() > 0)
160         {
161             element.setForecolor(JRXmlConstants.getColor(forecolor, null));
162         }
163
164         String JavaDoc backcolor = atts.getValue(ATTRIBUTE_backcolor);
165         if (backcolor != null && backcolor.length() > 0)
166         {
167             element.setBackcolor(JRXmlConstants.getColor(backcolor, null));
168         }
169         
170         if (atts.getValue(ATTRIBUTE_style) != null)
171         {
172             Map JavaDoc stylesMap = jasperDesign.getStylesMap();
173
174             if ( !stylesMap.containsKey(atts.getValue(ATTRIBUTE_style)) )
175             {
176                 xmlLoader.addError(new Exception JavaDoc("Unknown report style : " + atts.getValue(ATTRIBUTE_style)));
177             }
178
179             element.setStyle((JRStyle) stylesMap.get(atts.getValue(ATTRIBUTE_style)));
180         }
181
182         return element;
183     }
184 }
185
Popular Tags