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.Map;
031:
032: import net.sf.jasperreports.engine.JRPrintText;
033: import net.sf.jasperreports.engine.JRReportFont;
034: import net.sf.jasperreports.engine.JasperPrint;
035:
036: import org.xml.sax.Attributes;
037:
038: /**
039: * @author Teodor Danciu (teodord@users.sourceforge.net)
040: * @version $Id: JRPrintFontFactory.java 1581 2007-02-12 14:19:02Z shertage $
041: */
042: public class JRPrintFontFactory extends JRBaseFactory {
043:
044: /**
045: *
046: */
047: public Object createObject(Attributes atts) {
048: JRPrintText element = (JRPrintText) digester.peek();
049: JRPrintXmlLoader printXmlLoader = (JRPrintXmlLoader) digester
050: .peek(digester.getCount() - 1);
051: JasperPrint jasperPrint = (JasperPrint) digester.peek(digester
052: .getCount() - 2);
053:
054: if (atts.getValue(JRXmlConstants.ATTRIBUTE_reportFont) != null) {
055: Map fontsMap = jasperPrint.getFontsMap();
056:
057: if (!fontsMap.containsKey(atts
058: .getValue(JRXmlConstants.ATTRIBUTE_reportFont))) {
059: printXmlLoader
060: .addError(new Exception(
061: "Unknown report font : "
062: + atts
063: .getValue(JRXmlConstants.ATTRIBUTE_reportFont)));
064: }
065:
066: element.setReportFont((JRReportFont) fontsMap.get(atts
067: .getValue(JRXmlConstants.ATTRIBUTE_reportFont)));
068: }
069:
070: if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null)
071: element.setFontName(atts
072: .getValue(JRXmlConstants.ATTRIBUTE_fontName));
073:
074: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null)
075: element.setBold(Boolean.valueOf(atts
076: .getValue(JRXmlConstants.ATTRIBUTE_isBold)));
077:
078: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null)
079: element.setItalic(Boolean.valueOf(atts
080: .getValue(JRXmlConstants.ATTRIBUTE_isItalic)));
081:
082: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null)
083: element.setUnderline(Boolean.valueOf(atts
084: .getValue(JRXmlConstants.ATTRIBUTE_isUnderline)));
085:
086: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null)
087: element
088: .setStrikeThrough(Boolean
089: .valueOf(atts
090: .getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough)));
091:
092: if (atts.getValue(JRXmlConstants.ATTRIBUTE_size) != null)
093: element.setFontSize(Integer.parseInt(atts
094: .getValue(JRXmlConstants.ATTRIBUTE_size)));
095:
096: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null)
097: element.setPdfFontName(atts
098: .getValue(JRXmlConstants.ATTRIBUTE_pdfFontName));
099:
100: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null)
101: element.setPdfEncoding(atts
102: .getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding));
103:
104: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null)
105: element.setPdfEmbedded(Boolean.valueOf(atts
106: .getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded)));
107:
108: return element;
109: }
110:
111: }
|