1 /* This file is part of the KDE project 2 3 Copyright (C) 2012-2014 Inge Wallin <inge@lysator.liu.se> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef ODFREADER_H 22 #define ODFREADER_H 23 24 // Qt 25 #include <QHash> 26 #include <QString> 27 28 // Calligra 29 #include <KoXmlStreamReader.h> 30 31 // this library 32 #include "koodfreader_export.h" 33 #include "OdfReaderInternals.h" 34 35 36 class QSizeF; 37 38 class KoXmlWriter; 39 class KoStore; 40 41 class OdfReaderBackend; 42 class OdfReaderContext; 43 44 class OdfTextReader; 45 class OdfDrawReader; 46 47 48 /** @brief Read the XML tree of the content of an ODF file. 49 * 50 * The OdfReader is used to traverse (read) the contents of an ODF file using 51 * an XML stream reader. For reading a specific type of ODF, e.g. a text 52 * document, you should create a new class, OdtReader that inherits this 53 * class. 54 * 55 * For every XML element that the reading process comes across it will call a 56 * specific function in a backend class: @see OdfReaderBackend. 57 * 58 * Before the reading process is started the ODF file will be 59 * analyzed to collect some data that may be needed during the 60 * read: metadata, manifest and styles are examples of this. This 61 * data is stored in the so called reading context, which is kept in 62 * an instance of the OdfReaderContext class. 63 * 64 * The context will be passed around to the backend in every call to a 65 * backend callback function. 66 * 67 * In addition to the pre-analyzed data from the ODF file, the context 68 * can be used to keep track of data that is used in the backend 69 * processing such as internal links, lists of embedded data such as 70 * pictures. 71 */ 72 class KOODFREADER_EXPORT OdfReader 73 { 74 public: 75 OdfReader(); 76 virtual ~OdfReader(); 77 78 OdfTextReader *textReader() const; 79 void setTextReader(OdfTextReader *textReader); 80 81 OdfDrawReader *drawReader() const; 82 void setDrawReader(OdfDrawReader *drawReader); 83 84 bool analyzeContent(OdfReaderContext *context); 85 86 bool readContent(OdfReaderBackend *backend, OdfReaderContext *context); 87 88 protected: 89 // All readElement*() are named after the full qualifiedName of 90 // the element in ODF that they handle. 91 92 // ODF document level functions 93 DECLARE_READER_FUNCTION(OfficeBody); 94 95 // ONE of these should be reimplemented by each subclass, respectively. 96 virtual DECLARE_READER_FUNCTION(OfficeText); 97 virtual DECLARE_READER_FUNCTION(OfficeSpreadsheet); 98 virtual DECLARE_READER_FUNCTION(OfficePresentation); 99 100 // ---------------------------------------------------------------- 101 // Other functions 102 103 void readUnknownElement(KoXmlStreamReader &reader); 104 105 106 protected: 107 OdfReaderBackend *m_backend; 108 OdfReaderContext *m_context; 109 110 // Helper readers 111 OdfTextReader *m_textReader; 112 OdfDrawReader *m_drawReader; 113 }; 114 115 #endif // ODFREADER_H 116