001: /**
002: * ========================================
003: * JFreeReport : a free Java report library
004: * ========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either 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, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * $Id: SubReportReadHandler.java 3525 2007-10-16 11:43:48Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report.modules.factories.report.flow;
031:
032: import java.util.ArrayList;
033:
034: import org.jfree.report.structure.Element;
035: import org.jfree.report.structure.SubReport;
036: import org.jfree.xmlns.parser.StringReadHandler;
037: import org.jfree.xmlns.parser.XmlReadHandler;
038: import org.jfree.xmlns.parser.ParseException;
039: import org.xml.sax.Attributes;
040: import org.xml.sax.SAXException;
041:
042: /**
043: * Creation-Date: 09.04.2006, 14:57:38
044: *
045: * @author Thomas Morgner
046: */
047: public class SubReportReadHandler extends SectionReadHandler {
048: private SubReport subReport;
049: private ArrayList importParameters;
050: private ArrayList exportParameters;
051: private StringReadHandler queryReadHandler;
052:
053: public SubReportReadHandler() {
054: subReport = new SubReport();
055: importParameters = new ArrayList();
056: exportParameters = new ArrayList();
057: }
058:
059: /**
060: * Starts parsing.
061: *
062: * @param attrs the attributes.
063: * @throws org.xml.sax.SAXException if there is a parsing error.
064: */
065: protected void startParsing(final Attributes attrs)
066: throws SAXException {
067: super .startParsing(attrs);
068: final String source = attrs.getValue(getUri(), "href");
069: if (source != null) {
070: // start parsing ..
071: }
072: }
073:
074: /**
075: * Returns the handler for a child element.
076: *
077: * @param tagName the tag name.
078: * @param atts the attributes.
079: * @return the handler or null, if the tagname is invalid.
080: * @throws SAXException if there is a parsing error.
081: */
082: protected XmlReadHandler getHandlerForChild(final String uri,
083: final String tagName, final Attributes atts)
084: throws SAXException {
085: final XmlReadHandler base = super .getHandlerForChild(uri,
086: tagName, atts);
087: if (base != null) {
088: return base;
089: }
090: if (FlowReportFactoryModule.NAMESPACE.equals(uri)) {
091: if ("import-parameter".equals(tagName)) {
092: final ParameterMappingReadHandler handler = new ParameterMappingReadHandler();
093: importParameters.add(handler);
094: return handler;
095: }
096: if ("export-parameter".equals(tagName)) {
097: final ParameterMappingReadHandler handler = new ParameterMappingReadHandler();
098: exportParameters.add(handler);
099: return handler;
100: }
101: if ("query".equals(tagName)) {
102: queryReadHandler = new StringReadHandler();
103: return queryReadHandler;
104: }
105: }
106: return null;
107: }
108:
109: /**
110: * Done parsing.
111: *
112: * @throws SAXException if there is a parsing error.
113: */
114: protected void doneParsing() throws SAXException {
115: super .doneParsing();
116: final SubReport report = (SubReport) getElement();
117: for (int i = 0; i < importParameters.size(); i++) {
118: final ParameterMappingReadHandler handler = (ParameterMappingReadHandler) importParameters
119: .get(i);
120: report.addInputParameter(handler.getName(), handler
121: .getAlias());
122: }
123: for (int i = 0; i < exportParameters.size(); i++) {
124: final ParameterMappingReadHandler handler = (ParameterMappingReadHandler) exportParameters
125: .get(i);
126: report.addExportParameter(handler.getAlias(), handler
127: .getName());
128: }
129: if (queryReadHandler == null) {
130: throw new ParseException("Query is not specified.",
131: getLocator());
132: }
133: final String result = queryReadHandler.getResult();
134: report.setQuery(result);
135: }
136:
137: protected Element getElement() {
138: return subReport;
139: }
140: }
|