1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.report.pentaho.parser.chart; 24 25 import com.sun.star.report.pentaho.OfficeNamespaces; 26 import com.sun.star.report.pentaho.parser.ElementReadHandler; 27 import com.sun.star.report.pentaho.parser.rpt.DetailRootTableReadHandler; 28 import com.sun.star.report.pentaho.parser.rpt.ReportReadHandler; 29 import com.sun.star.report.pentaho.parser.text.TextContentReadHandler; 30 31 import java.lang.Object; 32 33 import java.util.ArrayList; 34 import java.util.List; 35 36 import org.jfree.report.structure.Element; 37 import org.jfree.report.structure.Section; 38 39 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 40 41 import org.xml.sax.Attributes; 42 import org.xml.sax.SAXException; 43 44 45 /** 46 * 47 * @author Ocke Janssen 48 */ 49 public class ChartReadHandler extends ElementReadHandler 50 { 51 52 private final Section element; 53 private final List children; 54 private final ReportReadHandler reportHandler; 55 ChartReadHandler(ReportReadHandler reportHandler)56 public ChartReadHandler(ReportReadHandler reportHandler) 57 { 58 this.reportHandler = reportHandler; 59 children = new ArrayList(); 60 element = new Section(); 61 } 62 63 /** 64 * Returns the handler for a child element. 65 * 66 * @param tagName the tag name. 67 * @param atts the attributes. 68 * @return the handler or null, if the tagname is invalid. 69 * @throws org.xml.sax.SAXException if there is a parsing error. 70 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)71 protected XmlReadHandler getHandlerForChild(final String uri, 72 final String tagName, 73 final Attributes atts) 74 throws SAXException 75 { 76 if ("detail".equals(tagName)) 77 { 78 final DetailRootTableReadHandler detail = new DetailRootTableReadHandler(); 79 reportHandler.setDetail(detail); 80 return detail; 81 } 82 else if ("p".equals(tagName) && OfficeNamespaces.TEXT_NS.equals(uri)) 83 { 84 final TextContentReadHandler readHandler = new TextContentReadHandler(); 85 children.add(readHandler); 86 return readHandler; 87 } 88 final ChartReadHandler erh = new ChartReadHandler(reportHandler); 89 children.add(erh); 90 return erh; 91 } 92 93 /** 94 * Done parsing. 95 * 96 * @throws org.xml.sax.SAXException if there is a parsing error. 97 */ doneParsing()98 protected void doneParsing() throws SAXException 99 { 100 for (Object aChildren : children) 101 { 102 final ElementReadHandler handler = (ElementReadHandler) aChildren; 103 element.addNode(handler.getElement()); 104 } 105 } 106 getElement()107 public Element getElement() 108 { 109 return element; 110 } 111 } 112