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.JRDesignImage;
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: JRImageFactory.java 1581 2007-02-12 14:19:02Z shertage $
042: */
043: public class JRImageFactory extends JRBaseFactory {
044:
045: /**
046: *
047: */
048: public Object createObject(Attributes atts) {
049: JRXmlLoader xmlLoader = (JRXmlLoader) digester.peek(digester
050: .getCount() - 1);
051: Collection groupEvaluatedImages = xmlLoader
052: .getGroupEvaluatedImages();
053: JasperDesign jasperDesign = (JasperDesign) digester
054: .peek(digester.getCount() - 2);
055:
056: JRDesignImage image = new JRDesignImage(jasperDesign);
057:
058: Byte scaleImage = (Byte) JRXmlConstants.getScaleImageMap().get(
059: atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage));
060: if (scaleImage != null) {
061: image.setScaleImage(scaleImage);
062: }
063:
064: Byte horizontalAlignment = (Byte) JRXmlConstants
065: .getHorizontalAlignMap().get(
066: atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign));
067: if (horizontalAlignment != null) {
068: image.setHorizontalAlignment(horizontalAlignment);
069: }
070:
071: Byte verticalAlignment = (Byte) JRXmlConstants
072: .getVerticalAlignMap().get(
073: atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign));
074: if (verticalAlignment != null) {
075: image.setVerticalAlignment(verticalAlignment);
076: }
077:
078: String isUsingCache = atts
079: .getValue(JRXmlConstants.ATTRIBUTE_isUsingCache);
080: if (isUsingCache != null && isUsingCache.length() > 0) {
081: image.setUsingCache(Boolean.valueOf(isUsingCache));
082: }
083:
084: String isLazy = atts.getValue(JRXmlConstants.ATTRIBUTE_isLazy);
085: if (isLazy != null && isLazy.length() > 0) {
086: image.setLazy(Boolean.valueOf(isLazy).booleanValue());
087: }
088:
089: Byte onErrorType = (Byte) JRXmlConstants
090: .getOnErrorTypeMap()
091: .get(
092: atts
093: .getValue(JRXmlConstants.ATTRIBUTE_onErrorType));
094: if (onErrorType != null) {
095: image.setOnErrorType(onErrorType.byteValue());
096: }
097:
098: Byte evaluationTime = (Byte) JRXmlConstants
099: .getEvaluationTimeMap()
100: .get(
101: atts
102: .getValue(JRXmlConstants.ATTRIBUTE_evaluationTime));
103: if (evaluationTime != null) {
104: image.setEvaluationTime(evaluationTime.byteValue());
105: }
106: if (image.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP) {
107: groupEvaluatedImages.add(image);
108:
109: String groupName = atts
110: .getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup);
111: if (groupName != null) {
112: JRDesignGroup group = new JRDesignGroup();
113: group.setName(groupName);
114: image.setEvaluationGroup(group);
115: }
116: }
117:
118: String hyperlinkType = atts
119: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType);
120: if (hyperlinkType != null) {
121: image.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: image.setHyperlinkTarget(hyperlinkTarget.byteValue());
131: }
132:
133: String bookmarkLevelAttr = atts
134: .getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
135: if (bookmarkLevelAttr != null) {
136: image.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
137: }
138:
139: return image;
140: }
141:
142: }
|