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: AutoTableElementReadHandler.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.misc.autotable.xml;
031:
032: import java.util.ArrayList;
033:
034: import org.jfree.report.modules.factories.report.flow.AbstractElementReadHandler;
035: import org.jfree.report.modules.factories.report.base.NodeReadHandlerFactory;
036: import org.jfree.report.modules.factories.report.base.NodeReadHandler;
037: import org.jfree.report.modules.misc.autotable.AutoTableElement;
038: import org.jfree.report.modules.misc.autotable.AutoTableModule;
039: import org.jfree.report.structure.Element;
040: import org.jfree.report.structure.Section;
041: import org.jfree.xmlns.parser.XmlReadHandler;
042: import org.xml.sax.Attributes;
043: import org.xml.sax.SAXException;
044:
045: /**
046: * Creation-Date: Dec 9, 2006, 5:47:25 PM
047: *
048: * @author Thomas Morgner
049: */
050: public class AutoTableElementReadHandler extends
051: AbstractElementReadHandler {
052: private AutoTableElement autoTableElement;
053: private ArrayList headerSections;
054: private ArrayList footerSections;
055: private ArrayList contentSections;
056:
057: public AutoTableElementReadHandler() {
058: autoTableElement = new AutoTableElement();
059: headerSections = new ArrayList();
060: contentSections = new ArrayList();
061: footerSections = new ArrayList();
062: }
063:
064: protected Element getElement() {
065: return autoTableElement;
066: }
067:
068: /**
069: * Returns the handler for a child element.
070: *
071: * @param tagName the tag name.
072: * @param atts the attributes.
073: * @return the handler or null, if the tagname is invalid.
074: * @throws org.xml.sax.SAXException if there is a parsing error.
075: * @throws XmlReaderException if there is a reader error.
076: */
077: protected XmlReadHandler getHandlerForChild(final String uri,
078: final String tagName, final Attributes atts)
079: throws SAXException {
080: if (AutoTableModule.AUTOTABLE_NAMESPACE.equals(uri) == false) {
081: return super .getHandlerForChild(uri, tagName, atts);
082: }
083:
084: final NodeReadHandlerFactory factory = NodeReadHandlerFactory
085: .getInstance();
086: final NodeReadHandler handler = (NodeReadHandler) factory
087: .getHandler(uri, tagName);
088: if (handler == null) {
089: return null;
090: }
091:
092: if ("auto-table-header".equals(tagName)) {
093: headerSections.add(handler);
094: return handler;
095: }
096:
097: if ("auto-table-footer".equals(tagName)) {
098: footerSections.add(handler);
099: return handler;
100: }
101:
102: if ("auto-table-cell".equals(tagName)) {
103: contentSections.add(handler);
104: return handler;
105: }
106:
107: return null;
108: }
109:
110: /**
111: * Done parsing.
112: *
113: * @throws org.xml.sax.SAXException if there is a parsing error.
114: */
115: protected void doneParsing() throws SAXException {
116: for (int i = 0; i < headerSections.size(); i++) {
117: final NodeReadHandler handler = (NodeReadHandler) headerSections
118: .get(i);
119: autoTableElement.addHeader((Section) handler.getNode());
120: }
121:
122: for (int i = 0; i < footerSections.size(); i++) {
123: final NodeReadHandler handler = (NodeReadHandler) footerSections
124: .get(i);
125: autoTableElement.addFooter((Section) handler.getNode());
126: }
127:
128: for (int i = 0; i < contentSections.size(); i++) {
129: final NodeReadHandler handler = (NodeReadHandler) contentSections
130: .get(i);
131: autoTableElement.addContent((Section) handler.getNode());
132: }
133: }
134: }
|