1 28 package net.sf.jasperreports.engine.xml; 29 30 import java.util.Collection ; 31 32 import net.sf.jasperreports.engine.JRExpression; 33 import net.sf.jasperreports.engine.design.JRDesignGroup; 34 import net.sf.jasperreports.engine.design.JRDesignImage; 35 import net.sf.jasperreports.engine.design.JasperDesign; 36 37 import org.xml.sax.Attributes ; 38 39 40 44 public class JRImageFactory extends JRBaseFactory 45 { 46 47 48 51 private static final String ATTRIBUTE_scaleImage = "scaleImage"; 52 private static final String ATTRIBUTE_hAlign = "hAlign"; 53 private static final String ATTRIBUTE_vAlign = "vAlign"; 54 private static final String ATTRIBUTE_isUsingCache = "isUsingCache"; 55 private static final String ATTRIBUTE_isLazy = "isLazy"; 56 private static final String ATTRIBUTE_onErrorType = "onErrorType"; 57 private static final String ATTRIBUTE_evaluationTime = "evaluationTime"; 58 private static final String ATTRIBUTE_evaluationGroup = "evaluationGroup"; 59 private static final String ATTRIBUTE_hyperlinkType = "hyperlinkType"; 60 private static final String ATTRIBUTE_hyperlinkTarget = "hyperlinkTarget"; 61 private static final String ATTRIBUTE_bookmarkLevel = "bookmarkLevel"; 62 63 64 67 public Object createObject(Attributes atts) 68 { 69 JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1); 70 Collection groupEvaluatedImages = xmlLoader.getGroupEvaluatedImages(); 71 JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); 72 73 JRDesignImage image = new JRDesignImage(jasperDesign); 74 75 Byte scaleImage = (Byte )JRXmlConstants.getScaleImageMap().get(atts.getValue(ATTRIBUTE_scaleImage)); 76 if (scaleImage != null) 77 { 78 image.setScaleImage(scaleImage); 79 } 80 81 Byte horizontalAlignment = (Byte )JRXmlConstants.getHorizontalAlignMap().get(atts.getValue(ATTRIBUTE_hAlign)); 82 if (horizontalAlignment != null) 83 { 84 image.setHorizontalAlignment(horizontalAlignment); 85 } 86 87 Byte verticalAlignment = (Byte )JRXmlConstants.getVerticalAlignMap().get(atts.getValue(ATTRIBUTE_vAlign)); 88 if (verticalAlignment != null) 89 { 90 image.setVerticalAlignment(verticalAlignment); 91 } 92 93 String isUsingCache = atts.getValue(ATTRIBUTE_isUsingCache); 94 if (isUsingCache != null && isUsingCache.length() > 0) 95 { 96 image.setUsingCache(Boolean.valueOf(isUsingCache)); 97 } 98 99 String isLazy = atts.getValue(ATTRIBUTE_isLazy); 100 if (isLazy != null && isLazy.length() > 0) 101 { 102 image.setLazy(Boolean.valueOf(isLazy).booleanValue()); 103 } 104 105 Byte onErrorType = (Byte )JRXmlConstants.getOnErrorTypeMap().get(atts.getValue(ATTRIBUTE_onErrorType)); 106 if (onErrorType != null) 107 { 108 image.setOnErrorType(onErrorType.byteValue()); 109 } 110 111 Byte evaluationTime = (Byte )JRXmlConstants.getEvaluationTimeMap().get(atts.getValue(ATTRIBUTE_evaluationTime)); 112 if (evaluationTime != null) 113 { 114 image.setEvaluationTime(evaluationTime.byteValue()); 115 } 116 if (image.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP) 117 { 118 groupEvaluatedImages.add(image); 119 120 String groupName = atts.getValue(ATTRIBUTE_evaluationGroup); 121 if (groupName != null) 122 { 123 JRDesignGroup group = new JRDesignGroup(); 124 group.setName(groupName); 125 image.setEvaluationGroup(group); 126 } 127 } 128 129 String hyperlinkType = atts.getValue(ATTRIBUTE_hyperlinkType); 130 if (hyperlinkType != null) 131 { 132 image.setLinkType(hyperlinkType); 133 } 134 135 Byte hyperlinkTarget = (Byte )JRXmlConstants.getHyperlinkTargetMap().get(atts.getValue(ATTRIBUTE_hyperlinkTarget)); 136 if (hyperlinkTarget != null) 137 { 138 image.setHyperlinkTarget(hyperlinkTarget.byteValue()); 139 } 140 141 String bookmarkLevelAttr = atts.getValue(ATTRIBUTE_bookmarkLevel); 142 if (bookmarkLevelAttr != null) 143 { 144 image.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr)); 145 } 146 147 return image; 148 } 149 150 151 } 152 | Popular Tags |