2
* JasperReports - Free Java Reporting Library.
3
* Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
4
* http://www.jaspersoft.com
6
* Unless you have purchased a commercial license agreement from Jaspersoft,
7
* the following license terms apply:
9
* This program is part of JasperReports.
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.
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.
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/>.
24
package net.sf.jasperreports.engine.xml;
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;
35
import org.apache.commons.logging.Log;
36
import org.apache.commons.logging.LogFactory;
37
import org.xml.sax.Attributes;
41
* @author Teodor Danciu (teodord@users.sourceforge.net)
42
* @version $Id: JRPrintTextFactory.java 3674 2010-04-02 08:18:15Z shertage $
44
public class JRPrintTextFactory extends JRBaseFactory
46
private static final Log log = LogFactory.getLog(JRPrintTextFactory.class);
51
public Object createObject(Attributes atts)
53
JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2);
55
JRBasePrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
57
HorizontalAlignEnum horizontalAlignment = HorizontalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_textAlignment));
58
if (horizontalAlignment != null)
60
text.setHorizontalAlignment(horizontalAlignment);
63
VerticalAlignEnum verticalAlignment = VerticalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_verticalAlignment));
64
if (verticalAlignment != null)
66
text.setVerticalAlignment(verticalAlignment);
69
RotationEnum rotation = RotationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
72
text.setRotation(rotation);
75
RunDirectionEnum runDirection = RunDirectionEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_runDirection));
76
if (runDirection != null)
78
text.setRunDirection(runDirection);
81
String textHeight = atts.getValue(JRXmlConstants.ATTRIBUTE_textHeight);
82
if (textHeight != null && textHeight.length() > 0)
84
text.setTextHeight(Float.parseFloat(textHeight));
87
LineSpacingEnum lineSpacing = LineSpacingEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
88
if (lineSpacing != null)
90
text.setLineSpacing(lineSpacing);
93
text.setMarkup(atts.getValue(JRXmlConstants.ATTRIBUTE_markup));
95
String isStyledText = atts.getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
96
if (isStyledText != null && isStyledText.length() > 0)
98
if (log.isWarnEnabled())
100
log.warn("The 'isStyledText' attribute is deprecated. Use the 'markup' attribute instead.");
103
text.setMarkup(Boolean.valueOf(isStyledText) ? JRCommonText.MARKUP_STYLED_TEXT : JRCommonText.MARKUP_NONE);
106
String lineSpacingFactor = atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacingFactor);
107
if (lineSpacingFactor != null && lineSpacingFactor.length() > 0)
109
text.setLineSpacingFactor(Float.parseFloat(lineSpacingFactor));
112
String leadingOffset = atts.getValue(JRXmlConstants.ATTRIBUTE_leadingOffset);
113
if (leadingOffset != null && leadingOffset.length() > 0)
115
text.setLeadingOffset(Float.parseFloat(leadingOffset));
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));
124
String hyperlinkPage = atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkPage);
125
if (hyperlinkPage != null)
127
text.setHyperlinkPage(Integer.valueOf(hyperlinkPage));
130
text.setHyperlinkTooltip(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTooltip));
132
String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
133
if (bookmarkLevelAttr != null)
135
text.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
138
String valueClass = atts.getValue(JRXmlConstants.ATTRIBUTE_valueClass);
139
if (valueClass != null)
141
text.setValueClassName(valueClass);
144
String pattern = atts.getValue(JRXmlConstants.ATTRIBUTE_pattern);
147
text.setPattern(pattern);
150
String formatFactoryClass = atts.getValue(JRXmlConstants.ATTRIBUTE_formatFactoryClass);
151
if (formatFactoryClass != null)
153
text.setFormatFactoryClass(formatFactoryClass);
156
String locale = atts.getValue(JRXmlConstants.ATTRIBUTE_locale);
159
text.setLocaleCode(locale);
162
String timezone = atts.getValue(JRXmlConstants.ATTRIBUTE_timezone);
163
if (timezone != null)
165
text.setTimeZoneId(timezone);