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 net.sf.jasperreports.engine.design.JasperDesign;
031:
032: import org.xml.sax.Attributes;
033:
034: /**
035: * @author Teodor Danciu (teodord@users.sourceforge.net)
036: * @version $Id: JasperDesignFactory.java 1581 2007-02-12 14:19:02Z shertage $
037: */
038: public class JasperDesignFactory extends JRBaseFactory {
039:
040: /**
041: *
042: */
043: public Object createObject(Attributes atts) {
044: JasperDesign jasperDesign = new JasperDesign();
045:
046: jasperDesign.setName(atts
047: .getValue(JRXmlConstants.ATTRIBUTE_name));
048:
049: jasperDesign.setLanguage(atts
050: .getValue(JRXmlConstants.ATTRIBUTE_language));
051:
052: String columnCount = atts
053: .getValue(JRXmlConstants.ATTRIBUTE_columnCount);
054: if (columnCount != null && columnCount.length() > 0) {
055: jasperDesign.setColumnCount(Integer.parseInt(columnCount));
056: }
057:
058: Byte printOrder = (Byte) JRXmlConstants.getPrintOrderMap().get(
059: atts.getValue(JRXmlConstants.ATTRIBUTE_printOrder));
060: if (printOrder != null) {
061: jasperDesign.setPrintOrder(printOrder.byteValue());
062: }
063:
064: String pageWidth = atts
065: .getValue(JRXmlConstants.ATTRIBUTE_pageWidth);
066: if (pageWidth != null && pageWidth.length() > 0) {
067: jasperDesign.setPageWidth(Integer.parseInt(pageWidth));
068: }
069:
070: String pageHeight = atts
071: .getValue(JRXmlConstants.ATTRIBUTE_pageHeight);
072: if (pageHeight != null && pageHeight.length() > 0) {
073: jasperDesign.setPageHeight(Integer.parseInt(pageHeight));
074: }
075:
076: Byte orientation = (Byte) JRXmlConstants
077: .getOrientationMap()
078: .get(
079: atts
080: .getValue(JRXmlConstants.ATTRIBUTE_orientation));
081: if (orientation != null) {
082: jasperDesign.setOrientation(orientation.byteValue());
083: }
084:
085: Byte whenNoDataType = (Byte) JRXmlConstants
086: .getWhenNoDataTypeMap()
087: .get(
088: atts
089: .getValue(JRXmlConstants.ATTRIBUTE_whenNoDataType));
090: if (whenNoDataType != null) {
091: jasperDesign.setWhenNoDataType(whenNoDataType.byteValue());
092: }
093:
094: String columnWidth = atts
095: .getValue(JRXmlConstants.ATTRIBUTE_columnWidth);
096: if (columnWidth != null && columnWidth.length() > 0) {
097: jasperDesign.setColumnWidth(Integer.parseInt(columnWidth));
098: }
099:
100: String columnSpacing = atts
101: .getValue(JRXmlConstants.ATTRIBUTE_columnSpacing);
102: if (columnSpacing != null && columnSpacing.length() > 0) {
103: jasperDesign.setColumnSpacing(Integer
104: .parseInt(columnSpacing));
105: }
106:
107: String leftMargin = atts
108: .getValue(JRXmlConstants.ATTRIBUTE_leftMargin);
109: if (leftMargin != null && leftMargin.length() > 0) {
110: jasperDesign.setLeftMargin(Integer.parseInt(leftMargin));
111: }
112:
113: String rightMargin = atts
114: .getValue(JRXmlConstants.ATTRIBUTE_rightMargin);
115: if (rightMargin != null && rightMargin.length() > 0) {
116: jasperDesign.setRightMargin(Integer.parseInt(rightMargin));
117: }
118:
119: String topMargin = atts
120: .getValue(JRXmlConstants.ATTRIBUTE_topMargin);
121: if (topMargin != null && topMargin.length() > 0) {
122: jasperDesign.setTopMargin(Integer.parseInt(topMargin));
123: }
124:
125: String bottomMargin = atts
126: .getValue(JRXmlConstants.ATTRIBUTE_bottomMargin);
127: if (bottomMargin != null && bottomMargin.length() > 0) {
128: jasperDesign
129: .setBottomMargin(Integer.parseInt(bottomMargin));
130: }
131:
132: String isTitleNewPage = atts
133: .getValue(JRXmlConstants.ATTRIBUTE_isTitleNewPage);
134: if (isTitleNewPage != null && isTitleNewPage.length() > 0) {
135: jasperDesign.setTitleNewPage(Boolean
136: .valueOf(isTitleNewPage).booleanValue());
137: }
138:
139: String isSummaryNewPage = atts
140: .getValue(JRXmlConstants.ATTRIBUTE_isSummaryNewPage);
141: if (isSummaryNewPage != null && isSummaryNewPage.length() > 0) {
142: jasperDesign.setSummaryNewPage(Boolean.valueOf(
143: isSummaryNewPage).booleanValue());
144: }
145:
146: String isFloatColumnFooter = atts
147: .getValue(JRXmlConstants.ATTRIBUTE_isFloatColumnFooter);
148: if (isFloatColumnFooter != null
149: && isFloatColumnFooter.length() > 0) {
150: jasperDesign.setFloatColumnFooter(Boolean.valueOf(
151: isFloatColumnFooter).booleanValue());
152: }
153:
154: jasperDesign.setScriptletClass(atts
155: .getValue(JRXmlConstants.ATTRIBUTE_scriptletClass));
156: jasperDesign.setFormatFactoryClass(atts
157: .getValue(JRXmlConstants.ATTRIBUTE_formatFactoryClass));
158: jasperDesign.setResourceBundle(atts
159: .getValue(JRXmlConstants.ATTRIBUTE_resourceBundle));
160:
161: Byte whenResourceMissingType = (Byte) JRXmlConstants
162: .getWhenResourceMissingTypeMap()
163: .get(
164: atts
165: .getValue(JRXmlConstants.ATTRIBUTE_whenResourceMissingType));
166: if (whenResourceMissingType != null) {
167: jasperDesign
168: .setWhenResourceMissingType(whenResourceMissingType
169: .byteValue());
170: }
171:
172: String isIgnorePagination = atts
173: .getValue(JRXmlConstants.ATTRIBUTE_isIgnorePagination);
174: if (isIgnorePagination != null
175: && isIgnorePagination.length() > 0) {
176: jasperDesign.setIgnorePagination(Boolean.valueOf(
177: isIgnorePagination).booleanValue());
178: }
179:
180: return jasperDesign;
181: }
182:
183: }
|