KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.jasperreports.engine.JasperPrint;
31 import net.sf.jasperreports.engine.base.JRBasePrintText;
32
33 import org.xml.sax.Attributes JavaDoc;
34
35
36 /**
37  * @author Teodor Danciu (teodord@users.sourceforge.net)
38  * @version $Id: JRPrintTextFactory.java 1485 2006-11-14 20:23:17 +0200 (Tue, 14 Nov 2006) teodord $
39  */

40 public class JRPrintTextFactory extends JRBaseFactory
41 {
42
43
44     /**
45      *
46      */

47     private static final String JavaDoc ATTRIBUTE_textAlignment = "textAlignment";
48     private static final String JavaDoc ATTRIBUTE_verticalAlignment = "verticalAlignment";
49     private static final String JavaDoc ATTRIBUTE_rotation = "rotation";
50     private static final String JavaDoc ATTRIBUTE_runDirection = "runDirection";
51     private static final String JavaDoc ATTRIBUTE_textHeight = "textHeight";
52     private static final String JavaDoc ATTRIBUTE_lineSpacing = "lineSpacing";
53     private static final String JavaDoc ATTRIBUTE_isStyledText = "isStyledText";
54     private static final String JavaDoc ATTRIBUTE_lineSpacingFactor = "lineSpacingFactor";
55     private static final String JavaDoc ATTRIBUTE_leadingOffset = "leadingOffset";
56     private static final String JavaDoc ATTRIBUTE_hyperlinkType = "hyperlinkType";
57     private static final String JavaDoc ATTRIBUTE_hyperlinkTarget = "hyperlinkTarget";
58     private static final String JavaDoc ATTRIBUTE_anchorName = "anchorName";
59     private static final String JavaDoc ATTRIBUTE_hyperlinkReference = "hyperlinkReference";
60     private static final String JavaDoc ATTRIBUTE_hyperlinkAnchor = "hyperlinkAnchor";
61     private static final String JavaDoc ATTRIBUTE_hyperlinkPage = "hyperlinkPage";
62     public static final String JavaDoc ATTRIBUTE_hyperlinkTooltip = "hyperlinkTooltip";
63     private static final String JavaDoc ATTRIBUTE_bookmarkLevel = "bookmarkLevel";
64     public static final String JavaDoc ATTRIBUTE_valueClass = "valueClass";
65     public static final String JavaDoc ATTRIBUTE_pattern = "pattern";
66     public static final String JavaDoc ATTRIBUTE_formatFactoryClass = "formatFactoryClass";
67     public static final String JavaDoc ATTRIBUTE_locale = "locale";
68     public static final String JavaDoc ATTRIBUTE_timezone = "timezone";
69
70
71     /**
72      *
73      */

74     public Object JavaDoc createObject(Attributes JavaDoc atts)
75     {
76         JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2);
77
78         JRBasePrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
79
80         Byte JavaDoc horizontalAlignment = (Byte JavaDoc)JRXmlConstants.getHorizontalAlignMap().get(atts.getValue(ATTRIBUTE_textAlignment));
81         if (horizontalAlignment != null)
82         {
83             text.setHorizontalAlignment(horizontalAlignment);
84         }
85
86         Byte JavaDoc verticalAlignment = (Byte JavaDoc)JRXmlConstants.getVerticalAlignMap().get(atts.getValue(ATTRIBUTE_verticalAlignment));
87         if (verticalAlignment != null)
88         {
89             text.setVerticalAlignment(verticalAlignment);
90         }
91
92         Byte JavaDoc rotation = (Byte JavaDoc)JRXmlConstants.getRotationMap().get(atts.getValue(ATTRIBUTE_rotation));
93         if (rotation != null)
94         {
95             text.setRotation(rotation);
96         }
97
98         Byte JavaDoc runDirection = (Byte JavaDoc)JRXmlConstants.getRunDirectionMap().get(atts.getValue(ATTRIBUTE_runDirection));
99         if (runDirection != null)
100         {
101             text.setRunDirection(runDirection.byteValue());
102         }
103
104         String JavaDoc textHeight = atts.getValue(ATTRIBUTE_textHeight);
105         if (textHeight != null && textHeight.length() > 0)
106         {
107             text.setTextHeight(Float.parseFloat(textHeight));
108         }
109
110         Byte JavaDoc lineSpacing = (Byte JavaDoc)JRXmlConstants.getLineSpacingMap().get(atts.getValue(ATTRIBUTE_lineSpacing));
111         if (lineSpacing != null)
112         {
113             text.setLineSpacing(lineSpacing);
114         }
115
116         String JavaDoc isStyledText = atts.getValue(ATTRIBUTE_isStyledText);
117         if (isStyledText != null && isStyledText.length() > 0)
118         {
119             text.setStyledText(Boolean.valueOf(isStyledText));
120         }
121
122         String JavaDoc lineSpacingFactor = atts.getValue(ATTRIBUTE_lineSpacingFactor);
123         if (lineSpacingFactor != null && lineSpacingFactor.length() > 0)
124         {
125             text.setLineSpacingFactor(Float.parseFloat(lineSpacingFactor));
126         }
127
128         String JavaDoc leadingOffset = atts.getValue(ATTRIBUTE_leadingOffset);
129         if (leadingOffset != null && leadingOffset.length() > 0)
130         {
131             text.setLeadingOffset(Float.parseFloat(leadingOffset));
132         }
133
134         String JavaDoc hyperlinkType = atts.getValue(ATTRIBUTE_hyperlinkType);
135         if (hyperlinkType != null)
136         {
137             text.setLinkType(hyperlinkType);
138         }
139
140         Byte JavaDoc hyperlinkTarget = (Byte JavaDoc)JRXmlConstants.getHyperlinkTargetMap().get(atts.getValue(ATTRIBUTE_hyperlinkTarget));
141         if (hyperlinkTarget != null)
142         {
143             text.setHyperlinkTarget(hyperlinkTarget.byteValue());
144         }
145
146         text.setAnchorName(atts.getValue(ATTRIBUTE_anchorName));
147         text.setHyperlinkReference(atts.getValue(ATTRIBUTE_hyperlinkReference));
148         text.setHyperlinkAnchor(atts.getValue(ATTRIBUTE_hyperlinkAnchor));
149         
150         String JavaDoc hyperlinkPage = atts.getValue(ATTRIBUTE_hyperlinkPage);
151         if (hyperlinkPage != null)
152         {
153             text.setHyperlinkPage(new Integer JavaDoc(hyperlinkPage));
154         }
155         
156         text.setHyperlinkTooltip(atts.getValue(ATTRIBUTE_hyperlinkTooltip));
157
158         String JavaDoc bookmarkLevelAttr = atts.getValue(ATTRIBUTE_bookmarkLevel);
159         if (bookmarkLevelAttr != null)
160         {
161             text.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
162         }
163         
164         String JavaDoc valueClass = atts.getValue(ATTRIBUTE_valueClass);
165         if (valueClass != null)
166         {
167             text.setValueClassName(valueClass);
168         }
169         
170         String JavaDoc pattern = atts.getValue(ATTRIBUTE_pattern);
171         if (pattern != null)
172         {
173             text.setPattern(pattern);
174         }
175         
176         String JavaDoc formatFactoryClass = atts.getValue(ATTRIBUTE_formatFactoryClass);
177         if (formatFactoryClass != null)
178         {
179             text.setFormatFactoryClass(formatFactoryClass);
180         }
181         
182         String JavaDoc locale = atts.getValue(ATTRIBUTE_locale);
183         if (locale != null)
184         {
185             text.setLocaleCode(locale);
186         }
187         
188         String JavaDoc timezone = atts.getValue(ATTRIBUTE_timezone);
189         if (timezone != null)
190         {
191             text.setTimeZoneId(timezone);
192         }
193         
194         return text;
195     }
196     
197
198 }
199
Popular Tags