KickJava   Java API By Example, From Geeks To Geeks.

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


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
32 import net.sf.jasperreports.engine.JRExpression;
33 import net.sf.jasperreports.engine.design.JRDesignGroup;
34 import net.sf.jasperreports.engine.design.JRDesignImage;
35 import net.sf.jasperreports.engine.design.JasperDesign;
36
37 import org.xml.sax.Attributes JavaDoc;
38
39
40 /**
41  * @author Teodor Danciu (teodord@users.sourceforge.net)
42  * @version $Id: JRImageFactory.java 1355 2006-08-04 17:31:54 +0300 (Fri, 04 Aug 2006) lucianc $
43  */

44 public class JRImageFactory extends JRBaseFactory
45 {
46
47
48     /**
49      *
50      */

51     private static final String JavaDoc ATTRIBUTE_scaleImage = "scaleImage";
52     private static final String JavaDoc ATTRIBUTE_hAlign = "hAlign";
53     private static final String JavaDoc ATTRIBUTE_vAlign = "vAlign";
54     private static final String JavaDoc ATTRIBUTE_isUsingCache = "isUsingCache";
55     private static final String JavaDoc ATTRIBUTE_isLazy = "isLazy";
56     private static final String JavaDoc ATTRIBUTE_onErrorType = "onErrorType";
57     private static final String JavaDoc ATTRIBUTE_evaluationTime = "evaluationTime";
58     private static final String JavaDoc ATTRIBUTE_evaluationGroup = "evaluationGroup";
59     private static final String JavaDoc ATTRIBUTE_hyperlinkType = "hyperlinkType";
60     private static final String JavaDoc ATTRIBUTE_hyperlinkTarget = "hyperlinkTarget";
61     private static final String JavaDoc ATTRIBUTE_bookmarkLevel = "bookmarkLevel";
62
63
64     /**
65      *
66      */

67     public Object JavaDoc createObject(Attributes JavaDoc atts)
68     {
69         JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
70         Collection JavaDoc groupEvaluatedImages = xmlLoader.getGroupEvaluatedImages();
71         JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2);
72
73         JRDesignImage image = new JRDesignImage(jasperDesign);
74
75         Byte JavaDoc scaleImage = (Byte JavaDoc)JRXmlConstants.getScaleImageMap().get(atts.getValue(ATTRIBUTE_scaleImage));
76         if (scaleImage != null)
77         {
78             image.setScaleImage(scaleImage);
79         }
80
81         Byte JavaDoc horizontalAlignment = (Byte JavaDoc)JRXmlConstants.getHorizontalAlignMap().get(atts.getValue(ATTRIBUTE_hAlign));
82         if (horizontalAlignment != null)
83         {
84             image.setHorizontalAlignment(horizontalAlignment);
85         }
86
87         Byte JavaDoc verticalAlignment = (Byte JavaDoc)JRXmlConstants.getVerticalAlignMap().get(atts.getValue(ATTRIBUTE_vAlign));
88         if (verticalAlignment != null)
89         {
90             image.setVerticalAlignment(verticalAlignment);
91         }
92
93         String JavaDoc isUsingCache = atts.getValue(ATTRIBUTE_isUsingCache);
94         if (isUsingCache != null && isUsingCache.length() > 0)
95         {
96             image.setUsingCache(Boolean.valueOf(isUsingCache));
97         }
98
99         String JavaDoc isLazy = atts.getValue(ATTRIBUTE_isLazy);
100         if (isLazy != null && isLazy.length() > 0)
101         {
102             image.setLazy(Boolean.valueOf(isLazy).booleanValue());
103         }
104
105         Byte JavaDoc onErrorType = (Byte JavaDoc)JRXmlConstants.getOnErrorTypeMap().get(atts.getValue(ATTRIBUTE_onErrorType));
106         if (onErrorType != null)
107         {
108             image.setOnErrorType(onErrorType.byteValue());
109         }
110
111         Byte JavaDoc evaluationTime = (Byte JavaDoc)JRXmlConstants.getEvaluationTimeMap().get(atts.getValue(ATTRIBUTE_evaluationTime));
112         if (evaluationTime != null)
113         {
114             image.setEvaluationTime(evaluationTime.byteValue());
115         }
116         if (image.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP)
117         {
118             groupEvaluatedImages.add(image);
119
120             String JavaDoc groupName = atts.getValue(ATTRIBUTE_evaluationGroup);
121             if (groupName != null)
122             {
123                 JRDesignGroup group = new JRDesignGroup();
124                 group.setName(groupName);
125                 image.setEvaluationGroup(group);
126             }
127         }
128
129         String JavaDoc hyperlinkType = atts.getValue(ATTRIBUTE_hyperlinkType);
130         if (hyperlinkType != null)
131         {
132             image.setLinkType(hyperlinkType);
133         }
134
135         Byte JavaDoc hyperlinkTarget = (Byte JavaDoc)JRXmlConstants.getHyperlinkTargetMap().get(atts.getValue(ATTRIBUTE_hyperlinkTarget));
136         if (hyperlinkTarget != null)
137         {
138             image.setHyperlinkTarget(hyperlinkTarget.byteValue());
139         }
140         
141         String JavaDoc bookmarkLevelAttr = atts.getValue(ATTRIBUTE_bookmarkLevel);
142         if (bookmarkLevelAttr != null)
143         {
144             image.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
145         }
146
147         return image;
148     }
149     
150
151 }
152
Popular Tags