1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 package org.libreoffice.report.pentaho.parser.table; 19 20 import org.libreoffice.report.OfficeToken; 21 import org.libreoffice.report.pentaho.OfficeNamespaces; 22 import org.libreoffice.report.pentaho.parser.ElementReadHandler; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 import org.jfree.report.structure.Element; 28 import org.jfree.report.structure.Section; 29 30 import org.pentaho.reporting.libraries.xmlns.parser.XmlReadHandler; 31 32 import org.xml.sax.Attributes; 33 import org.xml.sax.SAXException; 34 35 36 /** 37 * Creation-Date: 03.07.2006, 13:50:41 38 * 39 */ 40 public class TableColumnsReadHandler extends ElementReadHandler 41 { 42 43 private final List<TableColumnReadHandler> columns; 44 private final Section tableColumns; 45 TableColumnsReadHandler()46 public TableColumnsReadHandler() 47 { 48 columns = new ArrayList<TableColumnReadHandler>(); 49 tableColumns = new Section(); 50 } 51 52 /** 53 * Returns the handler for a child element. 54 * 55 * @param tagName the tag name. 56 * @param atts the attributes. 57 * @return the handler or null, if the tagname is invalid. 58 * @throws org.xml.sax.SAXException if there is a parsing error. 59 */ 60 @Override getHandlerForChild(final String uri, final String tagName, final Attributes atts)61 protected XmlReadHandler getHandlerForChild(final String uri, 62 final String tagName, 63 final Attributes atts) 64 throws SAXException 65 { 66 if (OfficeNamespaces.TABLE_NS.equals(uri) && OfficeToken.TABLE_COLUMN.equals(tagName)) 67 { 68 final TableColumnReadHandler readHandler = new TableColumnReadHandler(); 69 columns.add(readHandler); 70 return readHandler; 71 } 72 73 return null; 74 } 75 76 /** 77 * Done parsing. 78 * 79 * @throws org.xml.sax.SAXException if there is a parsing error. 80 */ 81 @Override doneParsing()82 protected void doneParsing() throws SAXException 83 { 84 for (int i = 0; i < columns.size(); i++) 85 { 86 final TableColumnReadHandler handler = columns.get(i); 87 tableColumns.addNode(handler.getElement()); 88 } 89 } 90 91 @Override getElement()92 public Element getElement() 93 { 94 return tableColumns; 95 } 96 } 97