1 28 package net.sf.jasperreports.engine.xml; 29 30 import java.awt.Color ; 31 import java.util.Map ; 32 33 import net.sf.jasperreports.engine.JRStyle; 34 import net.sf.jasperreports.engine.JasperPrint; 35 import net.sf.jasperreports.engine.base.JRBasePrintElement; 36 37 import org.xml.sax.Attributes ; 38 39 40 44 public class JRPrintElementFactory extends JRBaseFactory 45 { 46 47 48 public static final String ATTRIBUTE_key = "key"; 49 50 53 private static final String ATTRIBUTE_mode = "mode"; 54 private static final String ATTRIBUTE_x = "x"; 55 private static final String ATTRIBUTE_y = "y"; 56 private static final String ATTRIBUTE_width = "width"; 57 private static final String ATTRIBUTE_height = "height"; 58 private static final String ATTRIBUTE_forecolor = "forecolor"; 59 private static final String ATTRIBUTE_backcolor = "backcolor"; 60 private static final String ATTRIBUTE_style = "style"; 61 62 63 66 public Object createObject(Attributes atts) 67 { 68 JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader)digester.peek(digester.getCount() - 1); 69 JasperPrint jasperPrint = (JasperPrint)digester.peek(digester.getCount() - 2); 70 JRBasePrintElement element = (JRBasePrintElement)digester.peek(); 71 72 String key = atts.getValue(ATTRIBUTE_key); 73 if (key != null) 74 { 75 element.setKey(key); 76 } 77 78 Byte mode = (Byte )JRXmlConstants.getModeMap().get(atts.getValue(ATTRIBUTE_mode)); 79 if (mode != null) 80 { 81 element.setMode(mode); 82 } 83 84 String x = atts.getValue(ATTRIBUTE_x); 85 if (x != null && x.length() > 0) 86 { 87 element.setX(Integer.parseInt(x)); 88 } 89 90 String y = atts.getValue(ATTRIBUTE_y); 91 if (y != null && y.length() > 0) 92 { 93 element.setY(Integer.parseInt(y)); 94 } 95 96 String width = atts.getValue(ATTRIBUTE_width); 97 if (width != null && width.length() > 0) 98 { 99 element.setWidth(Integer.parseInt(width)); 100 } 101 102 String height = atts.getValue(ATTRIBUTE_height); 103 if (height != null && height.length() > 0) 104 { 105 element.setHeight(Integer.parseInt(height)); 106 } 107 108 String forecolor = atts.getValue(ATTRIBUTE_forecolor); 109 if (forecolor != null) 110 { 111 if (forecolor.startsWith("#")) 112 { 113 element.setForecolor(new Color (Integer.parseInt(forecolor.substring(1), 16))); 114 } 115 else 116 { 117 element.setForecolor(new Color (Integer.parseInt(forecolor))); 118 } 119 } 120 121 String backcolor = atts.getValue(ATTRIBUTE_backcolor); 122 if (backcolor != null) 123 { 124 if (backcolor.startsWith("#")) 125 { 126 element.setBackcolor(new Color (Integer.parseInt(backcolor.substring(1), 16))); 127 } 128 else 129 { 130 element.setBackcolor(new Color (Integer.parseInt(backcolor))); 131 } 132 } 133 134 if (atts.getValue(ATTRIBUTE_style) != null) 135 { 136 Map stylesMap = jasperPrint.getStylesMap(); 137 138 if ( !stylesMap.containsKey(atts.getValue(ATTRIBUTE_style)) ) 139 { 140 printXmlLoader.addError(new Exception ("Unknown report style : " + atts.getValue(ATTRIBUTE_style))); 141 } 142 143 element.setStyle((JRStyle) stylesMap.get(atts.getValue(ATTRIBUTE_style))); 144 } 145 146 return element; 147 } 148 149 150 } 151 | Popular Tags |