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.OfficeToken; 26 import com.sun.star.report.pentaho.OfficeNamespaces; 27 import com.sun.star.report.pentaho.model.ReportElement; 28 import com.sun.star.report.pentaho.parser.ElementReadHandler; 29 30 import org.jfree.report.structure.Element; 31 32 import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; 33 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 34 35 import org.xml.sax.Attributes; 36 import org.xml.sax.SAXException; 37 38 public class ReportElementReadHandler extends ElementReadHandler 39 { 40 41 private final ReportElement element; 42 ReportElementReadHandler(final ReportElement element)43 public ReportElementReadHandler(final ReportElement element) 44 { 45 if (element == null) 46 { 47 throw new NullPointerException(); 48 } 49 50 this.element = element; 51 } 52 getElement()53 public Element getElement() 54 { 55 return element; 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) 65 throws SAXException 66 { 67 super.startParsing(attrs); 68 final String printWhenGroupChanges = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "print-when-group-changes"); 69 element.setPrintWhenGroupChanges(OfficeToken.TRUE.equals(printWhenGroupChanges)); 70 final String printRepeatingValues = attrs.getValue(OfficeNamespaces.OOREPORT_NS, "print-repeated-values"); 71 element.setPrintRepeatedValues(printRepeatingValues == null || OfficeToken.TRUE.equals(printRepeatingValues)); 72 } 73 74 /** 75 * Returns the handler for a child element. 76 * 77 * @param tagName the tag name. 78 * @param atts the attributes. 79 * @return the handler or null, if the tagname is invalid. 80 * @throws org.xml.sax.SAXException if there is a parsing error. 81 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)82 protected XmlReadHandler getHandlerForChild(final String uri, 83 final String tagName, 84 final Attributes atts) 85 throws SAXException 86 { 87 if (!OfficeNamespaces.OOREPORT_NS.equals(uri)) 88 { 89 return null; 90 } 91 if ("conditional-print-expression".equals(tagName)) 92 { 93 return new ConditionalPrintExpressionReadHandler(element); 94 } 95 if ("format-condition".equals(tagName)) 96 { 97 return new FormatConditionReadHandler(element); 98 } 99 if ("report-component".equals(tagName)) 100 { 101 return new IgnoreAnyChildReadHandler(); 102 } 103 return null; 104 } 105 } 106