File indexing completed on 2024-12-01 13:11:46
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2012-2014 Inge Wallin <inge@lysator.liu.se> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 0022 // Own 0023 #include "OdtReader.h" 0024 0025 // Qt 0026 #include <QStringList> 0027 #include <QBuffer> 0028 0029 // KF5 0030 #include <klocalizedstring.h> 0031 0032 // Calligra 0033 #include <KoStore.h> 0034 #include <KoXmlStreamReader.h> 0035 #include <KoXmlNS.h> 0036 0037 // Reader library 0038 #include "OdtReaderBackend.h" 0039 #include "OdfReaderContext.h" 0040 #include "OdfTextReader.h" 0041 #include "OdfReaderDebug.h" 0042 0043 0044 #if 0 0045 static int debugIndent = 0; 0046 #define DEBUGSTART() \ 0047 ++debugIndent; \ 0048 DEBUG_READING("entering") 0049 #define DEBUGEND() \ 0050 DEBUG_READING("exiting"); \ 0051 --debugIndent 0052 #define DEBUG_READING(param) \ 0053 debugOdfReader << QString("%1").arg(" ", debugIndent * 2) << param << ": " \ 0054 << (reader.isStartElement() ? "start": (reader.isEndElement() ? "end" : "other")) \ 0055 << reader.qualifiedName().toString() 0056 #else 0057 #define DEBUGSTART() \ 0058 // NOTHING 0059 #define DEBUGEND() \ 0060 // NOTHING 0061 #define DEBUG_READING(param) \ 0062 // NOTHING 0063 #endif 0064 0065 0066 OdtReader::OdtReader() 0067 : OdfReader() 0068 { 0069 } 0070 0071 OdtReader::~OdtReader() 0072 { 0073 } 0074 0075 #if 0 0076 // This is a template function for the reader library. 0077 // Copy this one and change the name and fill in the code. 0078 void OdtReader::readElementNamespaceTagname(KoXmlStreamReader &reader) 0079 { 0080 DEBUGSTART(); 0081 0082 // <namespace:tagname> has the following children in ODF 1.2: 0083 // FILL IN THE CHILDREN LIKE THIS EXAMPLE (taken from office:document-content): 0084 // <office:automatic-styles> 3.15.3 0085 // <office:body> 3.3 0086 // <office:font-face-decls> 3.14 0087 // <office:scripts> 3.12. 0088 while (reader.readNextStartElement()) { 0089 QString tagName = reader.qualifiedName().toString(); 0090 0091 if (tagName == "office:automatic-styles") { 0092 // FIXME: NYI 0093 } 0094 else if (tagName == "office:body") { 0095 readElementOfficeBody(reader); 0096 } 0097 ... MORE else if () HERE 0098 else { 0099 reader.skipCurrentElement(); 0100 } 0101 } 0102 0103 m_backend->elementNamespaceTagname(reader, m_context); 0104 DEBUGEND(); 0105 } 0106 #endif 0107 0108 // Reimplemented from OdfReader 0109 void OdtReader::readElementOfficeText(KoXmlStreamReader &reader) 0110 { 0111 DEBUGSTART(); 0112 OdtReaderBackend *backend = dynamic_cast<OdtReaderBackend *>(m_backend); 0113 backend->elementOfficeText(reader, m_context); 0114 0115 // <office:text> has the following children in ODF 1.2: 0116 // 0117 // In addition to the text level tags like <text:p> etc that can 0118 // be found in any textbox, table cell or similar, it has the 0119 // following text document children: 0120 // 0121 // <office:forms> 13.2 0122 // <table:calculation-settings> 9.4.1 0123 // <table:consolidation> 9.7 0124 // <table:content-validations> 9.4.4 0125 // <table:database-ranges> 9.4.14 0126 // <table:data-pilot-tables> 9.6.2 0127 // <table:dde-links> 9.8 0128 // <table:label-ranges> 9.4.10 0129 // <table:named-expressions> 9.4.11 0130 // <text:alphabetical-index-auto-mark-file> 8.8.3 0131 // <text:dde-connection-decls> 14.6.2 0132 // <text:page-sequence> 5.2 0133 // <text:sequence-decls> 7.4.11 0134 // <text:tracked-changes> 5.5.1 0135 // <text:user-field-decls> 7.4.7 0136 // <text:variable-decls> 7.4.2 0137 // 0138 // FIXME: For now, none of these are handled 0139 while (reader.readNextStartElement()) { 0140 DEBUG_READING("loop-start"); 0141 0142 QString tagName = reader.qualifiedName().toString(); 0143 if (tagName == "office:forms") { 0144 // FIXME: NYI 0145 reader.skipCurrentElement(); 0146 } 0147 else if (tagName == "table:calculation-settings") { 0148 reader.skipCurrentElement(); 0149 } 0150 else if (tagName == "table:consolidation") { 0151 reader.skipCurrentElement(); 0152 } 0153 else if (tagName == "table:content-validation") { 0154 reader.skipCurrentElement(); 0155 } 0156 else if (tagName == "table:database-ranges") { 0157 reader.skipCurrentElement(); 0158 } 0159 else if (tagName == "table:data-pilot-tables") { 0160 reader.skipCurrentElement(); 0161 } 0162 else if (tagName == "table:dde-links") { 0163 reader.skipCurrentElement(); 0164 } 0165 else if (tagName == "table:label-ranges") { 0166 reader.skipCurrentElement(); 0167 } 0168 else if (tagName == "table:named-expressions") { 0169 reader.skipCurrentElement(); 0170 } 0171 else if (tagName == "text:alphabetical-index-auto-mark-file") { 0172 reader.skipCurrentElement(); 0173 } 0174 else if (tagName == "text:dde-connection-decls") { 0175 reader.skipCurrentElement(); 0176 } 0177 else if (tagName == "text:page-sequence") { 0178 reader.skipCurrentElement(); 0179 } 0180 else if (tagName == "text:sequence-decls") { 0181 reader.skipCurrentElement(); 0182 } 0183 else if (tagName == "text:tracked-changes") { 0184 reader.skipCurrentElement(); 0185 } 0186 else if (tagName == "text:user-field-decls") { 0187 reader.skipCurrentElement(); 0188 } 0189 else if (tagName == "text:variable-decls") { 0190 reader.skipCurrentElement(); 0191 } 0192 else { 0193 if (m_textReader) { 0194 m_textReader->readTextLevelElement(reader); 0195 } 0196 else { 0197 reader.skipCurrentElement(); 0198 } 0199 } 0200 DEBUG_READING("loop-end"); 0201 } 0202 0203 backend->elementOfficeText(reader, m_context); 0204 DEBUGEND(); 0205 } 0206 0207 0208 // ---------------------------------------------------------------- 0209 // Other functions