Frames | No Frames |
1: /** 2: * ======================================== 3: * JFreeReport : a free Java report library 4: * ======================================== 5: * 6: * Project Info: http://reporting.pentaho.org/ 7: * 8: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. 9: * 10: * This library is free software; you can redistribute it and/or modify it under the terms 11: * of the GNU Lesser General Public License as published by the Free Software Foundation; 12: * either version 2.1 of the License, or (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16: * See the GNU Lesser General Public License for more details. 17: * 18: * You should have received a copy of the GNU Lesser General Public License along with this 19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20: * Boston, MA 02111-1307, USA. 21: * 22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 23: * in the United States and other countries.] 24: * 25: * ------------ 26: * $Id: AutoTableElementReadHandler.java 3525 2007-10-16 11:43:48Z tmorgner $ 27: * ------------ 28: * (C) Copyright 2000-2005, by Object Refinery Limited. 29: * (C) Copyright 2005-2007, by Pentaho Corporation. 30: */ 31: 32: package org.jfree.report.modules.misc.autotable.xml; 33: 34: import java.util.ArrayList; 35: 36: import org.jfree.report.modules.factories.report.flow.AbstractElementReadHandler; 37: import org.jfree.report.modules.factories.report.base.NodeReadHandlerFactory; 38: import org.jfree.report.modules.factories.report.base.NodeReadHandler; 39: import org.jfree.report.modules.misc.autotable.AutoTableElement; 40: import org.jfree.report.modules.misc.autotable.AutoTableModule; 41: import org.jfree.report.structure.Element; 42: import org.jfree.report.structure.Section; 43: import org.jfree.xmlns.parser.XmlReadHandler; 44: import org.xml.sax.Attributes; 45: import org.xml.sax.SAXException; 46: 47: /** 48: * Creation-Date: Dec 9, 2006, 5:47:25 PM 49: * 50: * @author Thomas Morgner 51: */ 52: public class AutoTableElementReadHandler extends AbstractElementReadHandler 53: { 54: private AutoTableElement autoTableElement; 55: private ArrayList headerSections; 56: private ArrayList footerSections; 57: private ArrayList contentSections; 58: 59: public AutoTableElementReadHandler() 60: { 61: autoTableElement = new AutoTableElement(); 62: headerSections = new ArrayList(); 63: contentSections = new ArrayList(); 64: footerSections = new ArrayList(); 65: } 66: 67: protected Element getElement() 68: { 69: return autoTableElement; 70: } 71: 72: /** 73: * Returns the handler for a child element. 74: * 75: * @param tagName the tag name. 76: * @param atts the attributes. 77: * @return the handler or null, if the tagname is invalid. 78: * @throws org.xml.sax.SAXException if there is a parsing error. 79: * @throws XmlReaderException if there is a reader error. 80: */ 81: protected XmlReadHandler getHandlerForChild(final String uri, 82: final String tagName, 83: final Attributes atts) 84: throws SAXException 85: { 86: if (AutoTableModule.AUTOTABLE_NAMESPACE.equals(uri) == false) 87: { 88: return super.getHandlerForChild(uri, tagName, atts); 89: } 90: 91: final NodeReadHandlerFactory factory = NodeReadHandlerFactory.getInstance(); 92: final NodeReadHandler handler = (NodeReadHandler) factory.getHandler(uri, tagName); 93: if (handler == null) 94: { 95: return null; 96: } 97: 98: if ("auto-table-header".equals(tagName)) 99: { 100: headerSections.add(handler); 101: return handler; 102: } 103: 104: if ("auto-table-footer".equals(tagName)) 105: { 106: footerSections.add(handler); 107: return handler; 108: } 109: 110: if ("auto-table-cell".equals(tagName)) 111: { 112: contentSections.add(handler); 113: return handler; 114: } 115: 116: return null; 117: } 118: 119: 120: /** 121: * Done parsing. 122: * 123: * @throws org.xml.sax.SAXException if there is a parsing error. 124: */ 125: protected void doneParsing() throws SAXException 126: { 127: for (int i = 0; i < headerSections.size(); i++) 128: { 129: final NodeReadHandler handler = (NodeReadHandler) headerSections.get(i); 130: autoTableElement.addHeader((Section) handler.getNode()); 131: } 132: 133: for (int i = 0; i < footerSections.size(); i++) 134: { 135: final NodeReadHandler handler = (NodeReadHandler) footerSections.get(i); 136: autoTableElement.addFooter((Section) handler.getNode()); 137: } 138: 139: for (int i = 0; i < contentSections.size(); i++) 140: { 141: final NodeReadHandler handler = (NodeReadHandler) contentSections.get(i); 142: autoTableElement.addContent((Section) handler.getNode()); 143: } 144: } 145: }