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.rpt; 24 25 import com.sun.star.report.pentaho.OfficeNamespaces; 26 import com.sun.star.report.pentaho.model.ObjectOleElement; 27 import com.sun.star.report.pentaho.parser.ElementReadHandler; 28 29 import org.jfree.report.structure.Element; 30 31 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 32 33 import org.xml.sax.Attributes; 34 import org.xml.sax.SAXException; 35 36 /** 37 * 38 * @author Ocke Janssen 39 */ 40 public class MasterDetailReadHandler extends ElementReadHandler 41 { 42 43 private final ObjectOleElement element; 44 private final boolean parseMasterDetail; 45 MasterDetailReadHandler(final ObjectOleElement element)46 public MasterDetailReadHandler(final ObjectOleElement element) 47 { 48 this.element = element; 49 parseMasterDetail = false; 50 } 51 MasterDetailReadHandler(final ObjectOleElement element, final boolean parseMasterDetail)52 public MasterDetailReadHandler(final ObjectOleElement element, final boolean parseMasterDetail) 53 { 54 this.element = element; 55 this.parseMasterDetail = parseMasterDetail; 56 } 57 58 /** 59 * Starts parsing. 60 * 61 * @param attrs the attributes. 62 * @throws org.xml.sax.SAXException if there is a parsing error. 63 */ startParsing(final Attributes attrs)64 protected void startParsing(final Attributes attrs) throws SAXException 65 { 66 super.startParsing(attrs); 67 if (parseMasterDetail) 68 { 69 final String master = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "master"); 70 if (master != null && master.length() > 0) 71 { 72 final String detail = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "detail"); 73 element.addMasterDetailFields(master, detail); 74 } 75 } 76 } 77 78 /** 79 * Returns the handler for a child element. 80 * 81 * @param tagName the tag name. 82 * @param atts the attributes. 83 * @return the handler or null, if the tagname is invalid. 84 * @throws org.xml.sax.SAXException if there is a parsing error. 85 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)86 protected XmlReadHandler getHandlerForChild(final String uri, 87 final String tagName, 88 final Attributes atts) 89 throws SAXException 90 { 91 if (OfficeNamespaces.OOREPORT_NS.equals(uri) && "master-detail-field".equals(tagName)) 92 { 93 // expect a report control. The control will modifiy the current 94 // element (as we do not separate the elements that strictly ..) 95 return new MasterDetailReadHandler(element, true); 96 } 97 98 return null; 99 } 100 getElement()101 public Element getElement() 102 { 103 return element; 104 } 105 } 106