001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.xml;
029:
030: import net.sf.jasperreports.engine.JasperPrint;
031: import net.sf.jasperreports.engine.base.JRBasePrintText;
032:
033: import org.xml.sax.Attributes;
034:
035: /**
036: * @author Teodor Danciu (teodord@users.sourceforge.net)
037: * @version $Id: JRPrintTextFactory.java 1581 2007-02-12 14:19:02Z shertage $
038: */
039: public class JRPrintTextFactory extends JRBaseFactory {
040:
041: /**
042: *
043: */
044: public Object createObject(Attributes atts) {
045: JasperPrint jasperPrint = (JasperPrint) digester.peek(digester
046: .getCount() - 2);
047:
048: JRBasePrintText text = new JRBasePrintText(jasperPrint
049: .getDefaultStyleProvider());
050:
051: Byte horizontalAlignment = (Byte) JRXmlConstants
052: .getHorizontalAlignMap()
053: .get(
054: atts
055: .getValue(JRXmlConstants.ATTRIBUTE_textAlignment));
056: if (horizontalAlignment != null) {
057: text.setHorizontalAlignment(horizontalAlignment);
058: }
059:
060: Byte verticalAlignment = (Byte) JRXmlConstants
061: .getVerticalAlignMap()
062: .get(
063: atts
064: .getValue(JRXmlConstants.ATTRIBUTE_verticalAlignment));
065: if (verticalAlignment != null) {
066: text.setVerticalAlignment(verticalAlignment);
067: }
068:
069: Byte rotation = (Byte) JRXmlConstants.getRotationMap().get(
070: atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
071: if (rotation != null) {
072: text.setRotation(rotation);
073: }
074:
075: Byte runDirection = (Byte) JRXmlConstants
076: .getRunDirectionMap()
077: .get(
078: atts
079: .getValue(JRXmlConstants.ATTRIBUTE_runDirection));
080: if (runDirection != null) {
081: text.setRunDirection(runDirection.byteValue());
082: }
083:
084: String textHeight = atts
085: .getValue(JRXmlConstants.ATTRIBUTE_textHeight);
086: if (textHeight != null && textHeight.length() > 0) {
087: text.setTextHeight(Float.parseFloat(textHeight));
088: }
089:
090: Byte lineSpacing = (Byte) JRXmlConstants
091: .getLineSpacingMap()
092: .get(
093: atts
094: .getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
095: if (lineSpacing != null) {
096: text.setLineSpacing(lineSpacing);
097: }
098:
099: String isStyledText = atts
100: .getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
101: if (isStyledText != null && isStyledText.length() > 0) {
102: text.setStyledText(Boolean.valueOf(isStyledText));
103: }
104:
105: String lineSpacingFactor = atts
106: .getValue(JRXmlConstants.ATTRIBUTE_lineSpacingFactor);
107: if (lineSpacingFactor != null && lineSpacingFactor.length() > 0) {
108: text.setLineSpacingFactor(Float
109: .parseFloat(lineSpacingFactor));
110: }
111:
112: String leadingOffset = atts
113: .getValue(JRXmlConstants.ATTRIBUTE_leadingOffset);
114: if (leadingOffset != null && leadingOffset.length() > 0) {
115: text.setLeadingOffset(Float.parseFloat(leadingOffset));
116: }
117:
118: String hyperlinkType = atts
119: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType);
120: if (hyperlinkType != null) {
121: text.setLinkType(hyperlinkType);
122: }
123:
124: Byte hyperlinkTarget = (Byte) JRXmlConstants
125: .getHyperlinkTargetMap()
126: .get(
127: atts
128: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
129: if (hyperlinkTarget != null) {
130: text.setHyperlinkTarget(hyperlinkTarget.byteValue());
131: }
132:
133: text.setAnchorName(atts
134: .getValue(JRXmlConstants.ATTRIBUTE_anchorName));
135: text.setHyperlinkReference(atts
136: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkReference));
137: text.setHyperlinkAnchor(atts
138: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkAnchor));
139:
140: String hyperlinkPage = atts
141: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkPage);
142: if (hyperlinkPage != null) {
143: text.setHyperlinkPage(new Integer(hyperlinkPage));
144: }
145:
146: text.setHyperlinkTooltip(atts
147: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTooltip));
148:
149: String bookmarkLevelAttr = atts
150: .getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
151: if (bookmarkLevelAttr != null) {
152: text.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
153: }
154:
155: String valueClass = atts
156: .getValue(JRXmlConstants.ATTRIBUTE_valueClass);
157: if (valueClass != null) {
158: text.setValueClassName(valueClass);
159: }
160:
161: String pattern = atts
162: .getValue(JRXmlConstants.ATTRIBUTE_pattern);
163: if (pattern != null) {
164: text.setPattern(pattern);
165: }
166:
167: String formatFactoryClass = atts
168: .getValue(JRXmlConstants.ATTRIBUTE_formatFactoryClass);
169: if (formatFactoryClass != null) {
170: text.setFormatFactoryClass(formatFactoryClass);
171: }
172:
173: String locale = atts.getValue(JRXmlConstants.ATTRIBUTE_locale);
174: if (locale != null) {
175: text.setLocaleCode(locale);
176: }
177:
178: String timezone = atts
179: .getValue(JRXmlConstants.ATTRIBUTE_timezone);
180: if (timezone != null) {
181: text.setTimeZoneId(timezone);
182: }
183:
184: return text;
185: }
186:
187: }
|