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.FixedTextElement; 28 import com.sun.star.report.pentaho.parser.ElementReadHandler; 29 import com.sun.star.report.pentaho.parser.text.TextContentReadHandler; 30 31 import org.jfree.report.structure.Element; 32 33 import org.pentaho.reporting.libraries.xmlns.parser.IgnoreAnyChildReadHandler; 34 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 35 36 import org.xml.sax.Attributes; 37 import org.xml.sax.SAXException; 38 39 /** 40 * Creation-Date: 01.10.2006, 18:48:11 41 * 42 * @author Thomas Morgner 43 */ 44 public class FixedContentReadHandler extends ElementReadHandler 45 { 46 47 private final FixedTextElement element; 48 FixedContentReadHandler()49 public FixedContentReadHandler() 50 { 51 element = new FixedTextElement(); 52 } 53 54 /** 55 * Returns the handler for a child element. 56 * 57 * @param tagName the tag name. 58 * @param atts the attributes. 59 * @return the handler or null, if the tagname is invalid. 60 * @throws org.xml.sax.SAXException if there is a parsing error. 61 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)62 protected XmlReadHandler getHandlerForChild(final String uri, 63 final String tagName, 64 final Attributes atts) 65 throws SAXException 66 { 67 if (OfficeNamespaces.TEXT_NS.equals(uri) && OfficeToken.P.equals(tagName)) 68 { 69 // expect a paragraph (which will be ignored; it is a structural 70 // component that needs not to be printed at all. 71 return new TextContentReadHandler(element.getContent()); 72 } 73 74 if (OfficeNamespaces.OOREPORT_NS.equals(uri)) 75 { 76 // expect a report control. The control will modifiy the current 77 // element (as we do not separate the elements that strictly ..) 78 if ("report-control".equals(tagName)) 79 { 80 return new IgnoreAnyChildReadHandler(); 81 } 82 if ("report-element".equals(tagName)) 83 { 84 return new ReportElementReadHandler(element); 85 } 86 } 87 return null; 88 } 89 getElement()90 public Element getElement() 91 { 92 return element; 93 } 94 } 95