1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package com.sun.star.report.pentaho.parser.rpt; 28 29 import com.sun.star.report.pentaho.OfficeNamespaces; 30 import com.sun.star.report.pentaho.model.ObjectOleElement; 31 import com.sun.star.report.pentaho.parser.ElementReadHandler; 32 33 import org.jfree.report.structure.Element; 34 35 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 36 37 import org.xml.sax.Attributes; 38 import org.xml.sax.SAXException; 39 40 /** 41 * 42 * @author Ocke Janssen 43 */ 44 public class MasterDetailReadHandler extends ElementReadHandler 45 { 46 47 private final ObjectOleElement element; 48 private final boolean parseMasterDetail; 49 50 public MasterDetailReadHandler(final ObjectOleElement element) 51 { 52 this.element = element; 53 parseMasterDetail = false; 54 } 55 56 public MasterDetailReadHandler(final ObjectOleElement element, final boolean parseMasterDetail) 57 { 58 this.element = element; 59 this.parseMasterDetail = parseMasterDetail; 60 } 61 62 /** 63 * Starts parsing. 64 * 65 * @param attrs the attributes. 66 * @throws org.xml.sax.SAXException if there is a parsing error. 67 */ 68 protected void startParsing(final Attributes attrs) throws SAXException 69 { 70 super.startParsing(attrs); 71 if (parseMasterDetail) 72 { 73 final String master = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "master"); 74 if (master != null && master.length() > 0) 75 { 76 final String detail = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "detail"); 77 element.addMasterDetailFields(master, detail); 78 } 79 } 80 } 81 82 /** 83 * Returns the handler for a child element. 84 * 85 * @param tagName the tag name. 86 * @param atts the attributes. 87 * @return the handler or null, if the tagname is invalid. 88 * @throws org.xml.sax.SAXException if there is a parsing error. 89 */ 90 protected XmlReadHandler getHandlerForChild(final String uri, 91 final String tagName, 92 final Attributes atts) 93 throws SAXException 94 { 95 if (OfficeNamespaces.OOREPORT_NS.equals(uri) && "master-detail-field".equals(tagName)) 96 { 97 // expect a report control. The control will modifiy the current 98 // element (as we do not separate the elements that strictly ..) 99 return new MasterDetailReadHandler(element, true); 100 } 101 102 return null; 103 } 104 105 public Element getElement() 106 { 107 return element; 108 } 109 } 110