| 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 10756 2009-12-02 15:58:24Z 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.xml.sax.Attributes; |
| 44 |
import org.xml.sax.SAXException; |
| 45 |
import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; |
| 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 |
*/ |
| 80 |
protected XmlReadHandler getHandlerForChild(final String uri, |
| 81 |
final String tagName, |
| 82 |
final Attributes atts) |
| 83 |
throws SAXException |
| 84 |
{ |
| 85 |
if (AutoTableModule.AUTOTABLE_NAMESPACE.equals(uri) == false) |
| 86 |
{ |
| 87 |
return super.getHandlerForChild(uri, tagName, atts); |
| 88 |
} |
| 89 |
|
| 90 |
final NodeReadHandlerFactory factory = NodeReadHandlerFactory.getInstance(); |
| 91 |
final NodeReadHandler handler = (NodeReadHandler) factory.getHandler(uri, tagName); |
| 92 |
if (handler == null) |
| 93 |
{ |
| 94 |
return null; |
| 95 |
} |
| 96 |
|
| 97 |
if (tagName.equals("auto-table-header")) |
| 98 |
{ |
| 99 |
headerSections.add(handler); |
| 100 |
return handler; |
| 101 |
} |
| 102 |
|
| 103 |
if (tagName.equals("auto-table-footer")) |
| 104 |
{ |
| 105 |
footerSections.add(handler); |
| 106 |
return handler; |
| 107 |
} |
| 108 |
|
| 109 |
if (tagName.equals("auto-table-cell")) |
| 110 |
{ |
| 111 |
contentSections.add(handler); |
| 112 |
return handler; |
| 113 |
} |
| 114 |
|
| 115 |
return null; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
* Done parsing. |
| 121 |
* |
| 122 |
* @throws org.xml.sax.SAXException if there is a parsing error. |
| 123 |
*/ |
| 124 |
protected void doneParsing() throws SAXException |
| 125 |
{ |
| 126 |
for (int i = 0; i < headerSections.size(); i++) |
| 127 |
{ |
| 128 |
final NodeReadHandler handler = (NodeReadHandler) headerSections.get(i); |
| 129 |
autoTableElement.addHeader((Section) handler.getNode()); |
| 130 |
} |
| 131 |
|
| 132 |
for (int i = 0; i < footerSections.size(); i++) |
| 133 |
{ |
| 134 |
final NodeReadHandler handler = (NodeReadHandler) footerSections.get(i); |
| 135 |
autoTableElement.addFooter((Section) handler.getNode()); |
| 136 |
} |
| 137 |
|
| 138 |
for (int i = 0; i < contentSections.size(); i++) |
| 139 |
{ |
| 140 |
final NodeReadHandler handler = (NodeReadHandler) contentSections.get(i); |
| 141 |
autoTableElement.addContent((Section) handler.getNode()); |
| 142 |
} |
| 143 |
} |
| 144 |
} |