~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/engine/xml/JRPrintTextFactory.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.JRCommonText;
 
27
import net.sf.jasperreports.engine.JasperPrint;
 
28
import net.sf.jasperreports.engine.base.JRBasePrintText;
 
29
import net.sf.jasperreports.engine.type.HorizontalAlignEnum;
 
30
import net.sf.jasperreports.engine.type.LineSpacingEnum;
 
31
import net.sf.jasperreports.engine.type.RotationEnum;
 
32
import net.sf.jasperreports.engine.type.RunDirectionEnum;
 
33
import net.sf.jasperreports.engine.type.VerticalAlignEnum;
 
34
 
 
35
import org.apache.commons.logging.Log;
 
36
import org.apache.commons.logging.LogFactory;
 
37
import org.xml.sax.Attributes;
 
38
 
 
39
 
 
40
/**
 
41
 * @author Teodor Danciu (teodord@users.sourceforge.net)
 
42
 * @version $Id: JRPrintTextFactory.java 3674 2010-04-02 08:18:15Z shertage $
 
43
 */
 
44
public class JRPrintTextFactory extends JRBaseFactory
 
45
{
 
46
        private static final Log log = LogFactory.getLog(JRPrintTextFactory.class);
 
47
 
 
48
        /**
 
49
         *
 
50
         */
 
51
        public Object createObject(Attributes atts)
 
52
        {
 
53
                JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2);
 
54
 
 
55
                JRBasePrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
 
56
 
 
57
                HorizontalAlignEnum horizontalAlignment = HorizontalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_textAlignment));
 
58
                if (horizontalAlignment != null)
 
59
                {
 
60
                        text.setHorizontalAlignment(horizontalAlignment);
 
61
                }
 
62
 
 
63
                VerticalAlignEnum verticalAlignment = VerticalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_verticalAlignment));
 
64
                if (verticalAlignment != null)
 
65
                {
 
66
                        text.setVerticalAlignment(verticalAlignment);
 
67
                }
 
68
 
 
69
                RotationEnum rotation = RotationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
 
70
                if (rotation != null)
 
71
                {
 
72
                        text.setRotation(rotation);
 
73
                }
 
74
 
 
75
                RunDirectionEnum runDirection = RunDirectionEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_runDirection));
 
76
                if (runDirection != null)
 
77
                {
 
78
                        text.setRunDirection(runDirection);
 
79
                }
 
80
 
 
81
                String textHeight = atts.getValue(JRXmlConstants.ATTRIBUTE_textHeight);
 
82
                if (textHeight != null && textHeight.length() > 0)
 
83
                {
 
84
                        text.setTextHeight(Float.parseFloat(textHeight));
 
85
                }
 
86
 
 
87
                LineSpacingEnum lineSpacing = LineSpacingEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
 
88
                if (lineSpacing != null)
 
89
                {
 
90
                        text.setLineSpacing(lineSpacing);
 
91
                }
 
92
 
 
93
                text.setMarkup(atts.getValue(JRXmlConstants.ATTRIBUTE_markup));
 
94
 
 
95
                String isStyledText = atts.getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
 
96
                if (isStyledText != null && isStyledText.length() > 0)
 
97
                {
 
98
                        if (log.isWarnEnabled())
 
99
                        {
 
100
                                log.warn("The 'isStyledText' attribute is deprecated. Use the 'markup' attribute instead.");
 
101
                        }
 
102
                                
 
103
                        text.setMarkup(Boolean.valueOf(isStyledText) ? JRCommonText.MARKUP_STYLED_TEXT : JRCommonText.MARKUP_NONE);
 
104
                }
 
105
 
 
106
                String lineSpacingFactor = atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacingFactor);
 
107
                if (lineSpacingFactor != null && lineSpacingFactor.length() > 0)
 
108
                {
 
109
                        text.setLineSpacingFactor(Float.parseFloat(lineSpacingFactor));
 
110
                }
 
111
 
 
112
                String leadingOffset = atts.getValue(JRXmlConstants.ATTRIBUTE_leadingOffset);
 
113
                if (leadingOffset != null && leadingOffset.length() > 0)
 
114
                {
 
115
                        text.setLeadingOffset(Float.parseFloat(leadingOffset));
 
116
                }
 
117
 
 
118
                text.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType));
 
119
                text.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
 
120
                text.setAnchorName(atts.getValue(JRXmlConstants.ATTRIBUTE_anchorName));
 
121
                text.setHyperlinkReference(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkReference));
 
122
                text.setHyperlinkAnchor(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkAnchor));
 
123
                
 
124
                String hyperlinkPage = atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkPage);
 
125
                if (hyperlinkPage != null)
 
126
                {
 
127
                        text.setHyperlinkPage(Integer.valueOf(hyperlinkPage));
 
128
                }
 
129
                
 
130
                text.setHyperlinkTooltip(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTooltip));
 
131
 
 
132
                String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
 
133
                if (bookmarkLevelAttr != null)
 
134
                {
 
135
                        text.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
 
136
                }
 
137
                
 
138
                String valueClass = atts.getValue(JRXmlConstants.ATTRIBUTE_valueClass);
 
139
                if (valueClass != null)
 
140
                {
 
141
                        text.setValueClassName(valueClass);
 
142
                }
 
143
                
 
144
                String pattern = atts.getValue(JRXmlConstants.ATTRIBUTE_pattern);
 
145
                if (pattern != null)
 
146
                {
 
147
                        text.setPattern(pattern);
 
148
                }
 
149
                
 
150
                String formatFactoryClass = atts.getValue(JRXmlConstants.ATTRIBUTE_formatFactoryClass);
 
151
                if (formatFactoryClass != null)
 
152
                {
 
153
                        text.setFormatFactoryClass(formatFactoryClass);
 
154
                }
 
155
                
 
156
                String locale = atts.getValue(JRXmlConstants.ATTRIBUTE_locale);
 
157
                if (locale != null)
 
158
                {
 
159
                        text.setLocaleCode(locale);
 
160
                }
 
161
                
 
162
                String timezone = atts.getValue(JRXmlConstants.ATTRIBUTE_timezone);
 
163
                if (timezone != null)
 
164
                {
 
165
                        text.setTimeZoneId(timezone);
 
166
                }
 
167
                
 
168
                return text;
 
169
        }
 
170
        
 
171
 
 
172
}