1 28 package net.sf.jasperreports.engine.xml; 29 30 import net.sf.jasperreports.engine.design.JasperDesign; 31 32 import org.xml.sax.Attributes ; 33 34 35 39 public class JasperDesignFactory extends JRBaseFactory 40 { 41 42 43 46 public static final String ELEMENT_jasperReport = "jasperReport"; 47 public static final String ATTRIBUTE_name = "name"; 48 public static final String ATTRIBUTE_language = "language"; 49 public static final String ATTRIBUTE_columnCount = "columnCount"; 50 public static final String ATTRIBUTE_printOrder = "printOrder"; 51 public static final String ATTRIBUTE_pageWidth = "pageWidth"; 52 public static final String ATTRIBUTE_pageHeight = "pageHeight"; 53 public static final String ATTRIBUTE_orientation = "orientation"; 54 public static final String ATTRIBUTE_whenNoDataType = "whenNoDataType"; 55 public static final String ATTRIBUTE_columnWidth = "columnWidth"; 56 public static final String ATTRIBUTE_columnSpacing = "columnSpacing"; 57 public static final String ATTRIBUTE_leftMargin = "leftMargin"; 58 public static final String ATTRIBUTE_rightMargin = "rightMargin"; 59 public static final String ATTRIBUTE_topMargin = "topMargin"; 60 public static final String ATTRIBUTE_bottomMargin = "bottomMargin"; 61 public static final String ATTRIBUTE_isTitleNewPage = "isTitleNewPage"; 62 public static final String ATTRIBUTE_isSummaryNewPage = "isSummaryNewPage"; 63 public static final String ATTRIBUTE_isFloatColumnFooter = "isFloatColumnFooter"; 64 public static final String ATTRIBUTE_scriptletClass = "scriptletClass"; 65 public static final String ATTRIBUTE_formatFactoryClass = "formatFactoryClass"; 66 public static final String ATTRIBUTE_resourceBundle = "resourceBundle"; 67 public static final String ATTRIBUTE_whenResourceMissingType = "whenResourceMissingType"; 68 public static final String ATTRIBUTE_isIgnorePagination = "isIgnorePagination"; 69 70 71 74 public Object createObject(Attributes atts) 75 { 76 JasperDesign jasperDesign = new JasperDesign(); 77 78 jasperDesign.setName(atts.getValue(ATTRIBUTE_name)); 79 80 jasperDesign.setLanguage(atts.getValue(ATTRIBUTE_language)); 81 82 String columnCount = atts.getValue(ATTRIBUTE_columnCount); 83 if (columnCount != null && columnCount.length() > 0) 84 { 85 jasperDesign.setColumnCount(Integer.parseInt(columnCount)); 86 } 87 88 Byte printOrder = (Byte )JRXmlConstants.getPrintOrderMap().get(atts.getValue(ATTRIBUTE_printOrder)); 89 if (printOrder != null) 90 { 91 jasperDesign.setPrintOrder(printOrder.byteValue()); 92 } 93 94 String pageWidth = atts.getValue(ATTRIBUTE_pageWidth); 95 if (pageWidth != null && pageWidth.length() > 0) 96 { 97 jasperDesign.setPageWidth(Integer.parseInt(pageWidth)); 98 } 99 100 String pageHeight = atts.getValue(ATTRIBUTE_pageHeight); 101 if (pageHeight != null && pageHeight.length() > 0) 102 { 103 jasperDesign.setPageHeight(Integer.parseInt(pageHeight)); 104 } 105 106 Byte orientation = (Byte )JRXmlConstants.getOrientationMap().get(atts.getValue(ATTRIBUTE_orientation)); 107 if (orientation != null) 108 { 109 jasperDesign.setOrientation(orientation.byteValue()); 110 } 111 112 Byte whenNoDataType = (Byte )JRXmlConstants.getWhenNoDataTypeMap().get(atts.getValue(ATTRIBUTE_whenNoDataType)); 113 if (whenNoDataType != null) 114 { 115 jasperDesign.setWhenNoDataType(whenNoDataType.byteValue()); 116 } 117 118 String columnWidth = atts.getValue(ATTRIBUTE_columnWidth); 119 if (columnWidth != null && columnWidth.length() > 0) 120 { 121 jasperDesign.setColumnWidth(Integer.parseInt(columnWidth)); 122 } 123 124 String columnSpacing = atts.getValue(ATTRIBUTE_columnSpacing); 125 if (columnSpacing != null && columnSpacing.length() > 0) 126 { 127 jasperDesign.setColumnSpacing(Integer.parseInt(columnSpacing)); 128 } 129 130 String leftMargin = atts.getValue(ATTRIBUTE_leftMargin); 131 if (leftMargin != null && leftMargin.length() > 0) 132 { 133 jasperDesign.setLeftMargin(Integer.parseInt(leftMargin)); 134 } 135 136 String rightMargin = atts.getValue(ATTRIBUTE_rightMargin); 137 if (rightMargin != null && rightMargin.length() > 0) 138 { 139 jasperDesign.setRightMargin(Integer.parseInt(rightMargin)); 140 } 141 142 String topMargin = atts.getValue(ATTRIBUTE_topMargin); 143 if (topMargin != null && topMargin.length() > 0) 144 { 145 jasperDesign.setTopMargin(Integer.parseInt(topMargin)); 146 } 147 148 String bottomMargin = atts.getValue(ATTRIBUTE_bottomMargin); 149 if (bottomMargin != null && bottomMargin.length() > 0) 150 { 151 jasperDesign.setBottomMargin(Integer.parseInt(bottomMargin)); 152 } 153 154 String isTitleNewPage = atts.getValue(ATTRIBUTE_isTitleNewPage); 155 if (isTitleNewPage != null && isTitleNewPage.length() > 0) 156 { 157 jasperDesign.setTitleNewPage(Boolean.valueOf(isTitleNewPage).booleanValue()); 158 } 159 160 String isSummaryNewPage = atts.getValue(ATTRIBUTE_isSummaryNewPage); 161 if (isSummaryNewPage != null && isSummaryNewPage.length() > 0) 162 { 163 jasperDesign.setSummaryNewPage(Boolean.valueOf(isSummaryNewPage).booleanValue()); 164 } 165 166 String isFloatColumnFooter = atts.getValue(ATTRIBUTE_isFloatColumnFooter); 167 if (isFloatColumnFooter != null && isFloatColumnFooter.length() > 0) 168 { 169 jasperDesign.setFloatColumnFooter(Boolean.valueOf(isFloatColumnFooter).booleanValue()); 170 } 171 172 jasperDesign.setScriptletClass(atts.getValue(ATTRIBUTE_scriptletClass)); 173 jasperDesign.setFormatFactoryClass(atts.getValue(ATTRIBUTE_formatFactoryClass)); 174 jasperDesign.setResourceBundle(atts.getValue(ATTRIBUTE_resourceBundle)); 175 176 Byte whenResourceMissingType = (Byte )JRXmlConstants.getWhenResourceMissingTypeMap().get(atts.getValue(ATTRIBUTE_whenResourceMissingType)); 177 if (whenResourceMissingType != null) 178 { 179 jasperDesign.setWhenResourceMissingType(whenResourceMissingType.byteValue()); 180 } 181 182 String isIgnorePagination = atts.getValue(ATTRIBUTE_isIgnorePagination); 183 if (isIgnorePagination != null && isIgnorePagination.length() > 0) 184 { 185 jasperDesign.setIgnorePagination(Boolean.valueOf(isIgnorePagination).booleanValue()); 186 } 187 188 return jasperDesign; 189 } 190 191 192 } 193 | Popular Tags |