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 java.util.Collection;
031:
032: import net.sf.jasperreports.engine.JRExpression;
033: import net.sf.jasperreports.engine.design.JRDesignGroup;
034: import net.sf.jasperreports.engine.design.JRDesignTextField;
035: import net.sf.jasperreports.engine.design.JasperDesign;
036:
037: import org.xml.sax.Attributes;
038:
039: /**
040: * @author Teodor Danciu (teodord@users.sourceforge.net)
041: * @version $Id: JRTextFieldFactory.java 1581 2007-02-12 14:19:02Z shertage $
042: */
043: public class JRTextFieldFactory extends JRBaseFactory {
044:
045: /**
046: *
047: */
048: public Object createObject(Attributes atts) {
049: JRXmlLoader xmlLoader = (JRXmlLoader) digester.peek(digester
050: .getCount() - 1);
051: Collection groupEvaluatedTextFields = xmlLoader
052: .getGroupEvaluatedTextFields();
053: JasperDesign jasperDesign = (JasperDesign) digester
054: .peek(digester.getCount() - 2);
055:
056: JRDesignTextField textField = new JRDesignTextField(
057: jasperDesign);
058:
059: String isStretchWithOverflow = atts
060: .getValue(JRXmlConstants.ATTRIBUTE_isStretchWithOverflow);
061: if (isStretchWithOverflow != null
062: && isStretchWithOverflow.length() > 0) {
063: textField.setStretchWithOverflow(Boolean.valueOf(
064: isStretchWithOverflow).booleanValue());
065: }
066:
067: Byte evaluationTime = (Byte) JRXmlConstants
068: .getEvaluationTimeMap()
069: .get(
070: atts
071: .getValue(JRXmlConstants.ATTRIBUTE_evaluationTime));
072: if (evaluationTime != null) {
073: textField.setEvaluationTime(evaluationTime.byteValue());
074: }
075: if (textField.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP) {
076: groupEvaluatedTextFields.add(textField);
077:
078: String groupName = atts
079: .getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup);
080: if (groupName != null) {
081: JRDesignGroup group = new JRDesignGroup();
082: group.setName(groupName);
083: textField.setEvaluationGroup(group);
084: }
085: }
086:
087: textField.setPattern(atts
088: .getValue(JRXmlConstants.ATTRIBUTE_pattern));
089:
090: String isBlankWhenNull = atts
091: .getValue(JRXmlConstants.ATTRIBUTE_isBlankWhenNull);
092: if (isBlankWhenNull != null && isBlankWhenNull.length() > 0) {
093: textField
094: .setBlankWhenNull(Boolean.valueOf(isBlankWhenNull));
095: }
096:
097: String hyperlinkType = atts
098: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType);
099: if (hyperlinkType != null) {
100: textField.setLinkType(hyperlinkType);
101: }
102:
103: Byte hyperlinkTarget = (Byte) JRXmlConstants
104: .getHyperlinkTargetMap()
105: .get(
106: atts
107: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
108: if (hyperlinkTarget != null) {
109: textField.setHyperlinkTarget(hyperlinkTarget.byteValue());
110: }
111:
112: String bookmarkLevelAttr = atts
113: .getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
114: if (bookmarkLevelAttr != null) {
115: textField.setBookmarkLevel(Integer
116: .parseInt(bookmarkLevelAttr));
117: }
118:
119: return textField;
120: }
121:
122: }
|