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.style; 24 25 import com.sun.star.report.pentaho.model.OfficeMasterPage; 26 import com.sun.star.report.pentaho.parser.ElementReadHandler; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 import org.jfree.report.structure.Element; 32 33 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 34 35 import org.xml.sax.Attributes; 36 import org.xml.sax.SAXException; 37 38 39 /** 40 * Todo: Document me! 41 * 42 * @author Thomas Morgner 43 * @since 13.03.2007 44 */ 45 public class MasterPageReadHandler extends ElementReadHandler 46 { 47 48 private final OfficeMasterPage masterPage; 49 private final List otherHandlers; 50 MasterPageReadHandler()51 public MasterPageReadHandler() 52 { 53 masterPage = new OfficeMasterPage(); 54 this.otherHandlers = new ArrayList(); 55 } 56 getMasterPage()57 public OfficeMasterPage getMasterPage() 58 { 59 return masterPage; 60 } 61 62 /** 63 * Returns the handler for a child element. 64 * 65 * @param tagName the tag name. 66 * @param atts the attributes. 67 * @return the handler or null, if the tagname is invalid. 68 * 69 * @throws org.xml.sax.SAXException if there is a parsing error. 70 */ getHandlerForChild(final String uri, final String tagName, final Attributes atts)71 protected XmlReadHandler getHandlerForChild(final String uri, 72 final String tagName, 73 final Attributes atts) 74 throws SAXException 75 { 76 final StyleDefinitionReadHandler readHandler = 77 new StyleDefinitionReadHandler(); 78 otherHandlers.add(readHandler); 79 return readHandler; 80 } 81 82 /** 83 * Done parsing. 84 * 85 * @throws org.xml.sax.SAXException if there is a parsing error. 86 */ doneParsing()87 protected void doneParsing() 88 throws SAXException 89 { 90 for (int i = 0; i < otherHandlers.size(); i++) 91 { 92 final ElementReadHandler handler = 93 (ElementReadHandler) otherHandlers.get(i); 94 masterPage.addNode(handler.getElement()); 95 } 96 } 97 getElement()98 public Element getElement() 99 { 100 return masterPage; 101 } 102 } 103