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.office; 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.ReportReadHandler; 28 29 import org.jfree.report.structure.Element; 30 import org.jfree.report.structure.Section; 31 32 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 33 34 import org.xml.sax.Attributes; 35 import org.xml.sax.SAXException; 36 37 public class BodyReadHandler extends ElementReadHandler 38 { 39 40 private ElementReadHandler reportReadHandler; 41 private final Section body; 42 BodyReadHandler()43 public BodyReadHandler() 44 { 45 body = new Section(); 46 } 47 48 /** 49 * Returns the handler for a child element. 50 * 51 * @param tagName the tag name. 52 * @param atts the attributes. 53 * @return the handler or null, if the tagname is invalid. 54 * 55 * @throws org.xml.sax.SAXException if there is a parsing error. 56 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)57 protected XmlReadHandler getHandlerForChild(final String uri, final String tagName, 58 final Attributes atts) 59 throws SAXException 60 { 61 if (OfficeNamespaces.OFFICE_NS.equals(uri) && "report".equals(tagName)) 62 { 63 reportReadHandler = new ReportReadHandler(); 64 return reportReadHandler; 65 } 66 67 return null; 68 } 69 70 /** 71 * Done parsing. 72 * 73 * @throws org.xml.sax.SAXException if there is a parsing error. 74 */ doneParsing()75 protected void doneParsing() throws SAXException 76 { 77 if (reportReadHandler != null) 78 { 79 body.addNode(reportReadHandler.getElement()); 80 } 81 } 82 getElement()83 public Element getElement() 84 { 85 return body; 86 } 87 } 88