~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/engine/xml/JRImageFactory.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:51:16 UTC
  • Revision ID: brian.thomason@canonical.com-20111220175116-apwo6unuaedvgzo3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JasperReports - Free Java Reporting Library.
 
3
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
 
4
 * http://www.jaspersoft.com
 
5
 *
 
6
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 
7
 * the following license terms apply:
 
8
 *
 
9
 * This program is part of JasperReports.
 
10
 *
 
11
 * JasperReports is free software: you can redistribute it and/or modify
 
12
 * it under the terms of the GNU Lesser General Public License as published by
 
13
 * the Free Software Foundation, either version 3 of the License, or
 
14
 * (at your option) any later version.
 
15
 *
 
16
 * JasperReports is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
19
 * GNU Lesser General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU Lesser General Public License
 
22
 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
 
23
 */
 
24
package net.sf.jasperreports.engine.xml;
 
25
 
 
26
import net.sf.jasperreports.engine.design.JRDesignGroup;
 
27
import net.sf.jasperreports.engine.design.JRDesignImage;
 
28
import net.sf.jasperreports.engine.design.JasperDesign;
 
29
import net.sf.jasperreports.engine.type.EvaluationTimeEnum;
 
30
import net.sf.jasperreports.engine.type.HorizontalAlignEnum;
 
31
import net.sf.jasperreports.engine.type.OnErrorTypeEnum;
 
32
import net.sf.jasperreports.engine.type.ScaleImageEnum;
 
33
import net.sf.jasperreports.engine.type.VerticalAlignEnum;
 
34
 
 
35
import org.xml.sax.Attributes;
 
36
 
 
37
 
 
38
/**
 
39
 * @author Teodor Danciu (teodord@users.sourceforge.net)
 
40
 * @version $Id: JRImageFactory.java 3701 2010-04-07 11:09:35Z lucianc $
 
41
 */
 
42
public class JRImageFactory extends JRBaseFactory
 
43
{
 
44
 
 
45
        /**
 
46
         *
 
47
         */
 
48
        public Object createObject(Attributes atts)
 
49
        {
 
50
                JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
 
51
                JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2);
 
52
 
 
53
                JRDesignImage image = new JRDesignImage(jasperDesign);
 
54
 
 
55
                // get image attributes
 
56
                ScaleImageEnum scaleImage = ScaleImageEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage));
 
57
                if (scaleImage != null)
 
58
                {
 
59
                        image.setScaleImage(scaleImage);
 
60
                }
 
61
 
 
62
                HorizontalAlignEnum horizontalAlignment = HorizontalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign));
 
63
                if (horizontalAlignment != null)
 
64
                {
 
65
                        image.setHorizontalAlignment(horizontalAlignment);
 
66
                }
 
67
 
 
68
                VerticalAlignEnum verticalAlignment = VerticalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign));
 
69
                if (verticalAlignment != null)
 
70
                {
 
71
                        image.setVerticalAlignment(verticalAlignment);
 
72
                }
 
73
 
 
74
                String isUsingCache = atts.getValue(JRXmlConstants.ATTRIBUTE_isUsingCache);
 
75
                if (isUsingCache != null && isUsingCache.length() > 0)
 
76
                {
 
77
                        image.setUsingCache(Boolean.valueOf(isUsingCache));
 
78
                }
 
79
 
 
80
                String isLazy = atts.getValue(JRXmlConstants.ATTRIBUTE_isLazy);
 
81
                if (isLazy != null && isLazy.length() > 0)
 
82
                {
 
83
                        image.setLazy(Boolean.valueOf(isLazy).booleanValue());
 
84
                }
 
85
 
 
86
                OnErrorTypeEnum onErrorType = OnErrorTypeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_onErrorType));
 
87
                if (onErrorType != null)
 
88
                {
 
89
                        image.setOnErrorType(onErrorType);
 
90
                }
 
91
 
 
92
                EvaluationTimeEnum evaluationTime = EvaluationTimeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_evaluationTime));
 
93
                if (evaluationTime != null)
 
94
                {
 
95
                        image.setEvaluationTime(evaluationTime);
 
96
                }
 
97
                if (image.getEvaluationTimeValue() == EvaluationTimeEnum.GROUP)
 
98
                {
 
99
                        xmlLoader.addGroupEvaluatedImage(image);
 
100
 
 
101
                        String groupName = atts.getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup);
 
102
                        if (groupName != null)
 
103
                        {
 
104
                                JRDesignGroup group = new JRDesignGroup();
 
105
                                group.setName(groupName);
 
106
                                image.setEvaluationGroup(group);
 
107
                        }
 
108
                }
 
109
 
 
110
                image.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType));
 
111
                image.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
 
112
                
 
113
                String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
 
114
                if (bookmarkLevelAttr != null)
 
115
                {
 
116
                        image.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
 
117
                }               
 
118
 
 
119
                return image;
 
120
        }
 
121
        
 
122
 
 
123
}