File indexing completed on 2025-01-19 10:49:28

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