File indexing completed on 2025-01-19 10:49:20
0001 /* 0002 * This file is part of Office 2007 Filters for Calligra 0003 * 0004 * SPDX-FileCopyrightText: 2009-2010 Nokia Corporation and /or its subsidiary(-ies). 0005 * 0006 * Contact: Suresh Chande suresh.chande@nokia.com 0007 * 0008 * SPDX-License-Identifier: LGPL-2.1-only 0009 * 0010 */ 0011 0012 #ifndef MSOOXMLREADER_H 0013 #define MSOOXMLREADER_H 0014 0015 #include "komsooxml_export.h" 0016 0017 #include <QXmlStreamReader> 0018 #include <QStack> 0019 #include <QUrl> 0020 0021 #include "MsooXmlDebug.h" 0022 #include <KoXmlReader.h> 0023 #include <KoFilter.h> 0024 #include <KoOdfExporter.h> 0025 0026 0027 namespace MSOOXML 0028 { 0029 0030 class MsooXmlRelationships; 0031 0032 //! Context for MsooXmlReader::read() 0033 class KOMSOOXML_EXPORT MsooXmlReaderContext 0034 { 0035 protected: 0036 MsooXmlReaderContext(MsooXmlRelationships* _relationships = 0); 0037 public: 0038 virtual ~MsooXmlReaderContext(); 0039 MSOOXML::MsooXmlRelationships* relationships; 0040 QMap<QString, QString> colorMap; 0041 0042 // element:graphic - A frame might contain a graphic object that was 0043 // generated by an external source and needs a container in which to be 0044 // displayed. A graphic object might represent a group of objects. 0045 bool graphicObjectIsGroup; 0046 0047 private: 0048 Q_DISABLE_COPY(MsooXmlReaderContext) 0049 }; 0050 0051 //! A base class reading MSOOXML parts like document.xml or styles.xml. 0052 class KOMSOOXML_EXPORT MsooXmlReader : public QXmlStreamReader, public KoOdfWriters 0053 { 0054 public: 0055 explicit MsooXmlReader(KoOdfWriters *writers); 0056 0057 MsooXmlReader(QIODevice* io, KoOdfWriters *writers); 0058 0059 virtual ~MsooXmlReader(); 0060 0061 //! Reads/parses the file 0062 virtual KoFilter::ConversionStatus read(MsooXmlReaderContext* context = 0) = 0; 0063 0064 //! Sets filename for the document being read. 0065 //! Only for error reporting purposes, used in raiseError(). 0066 void setFileName(const QString &fileName) { 0067 m_fileName = fileName; 0068 } 0069 0070 //! @return filename for the document being read. 0071 //! Only for error reporting purposes, used in raiseError(). 0072 QString fileName() const { 0073 return m_fileName; 0074 } 0075 0076 //! Reimplemented after QXmlStreamReader: adds line, column and filename information 0077 void raiseError(const QString & message = QString()); 0078 0079 // Uncomment if debugging is needed 0080 //! Reimplemented after QXmlStreamReader for supporting undo read and for debugging purposes 0081 //TokenType readNext(); 0082 0083 //! Undoes recent readNext(); only one recent readNext() can be undoed 0084 //void undoReadNext(); 0085 0086 // const strings (for optimization) 0087 static const char constOn[]; 0088 static const char constOff[]; 0089 static const char constTrue[]; 0090 static const char constFalse[]; 0091 static const char constNone[]; 0092 static const char const1[]; 0093 static const char const0[]; 0094 static const char constAuto[]; 0095 static const char constFloat[]; 0096 static const char constPercentage[]; 0097 static const char constCurrency[]; 0098 static const char constDate[]; 0099 static const char constTime[]; 0100 static const char constBoolean[]; 0101 static const char constString[]; 0102 0103 protected: 0104 // -- general 0105 bool expectElName(const char* elementName); 0106 bool expectElNameEnd(const char* elementName); 0107 bool expectEl(const char* qualifiedElementName); 0108 bool expectEl(const QString& qualifiedElementName); 0109 bool expectEl(const QList<QByteArray>& qualifiedElementNames); 0110 bool expectElEnd(const QString& qualifiedElementName); 0111 bool expectElEnd(const char* qualifiedElementName); 0112 bool expectNS(const char* nsName); 0113 void raiseElNotFoundError(const char* elementName); 0114 void raiseAttributeNotFoundError(const char* attrName); 0115 void raiseNSNotFoundError(const char* nsName); 0116 void raiseUnexpectedAttributeValueError(const QString& value, const char* attrName); 0117 void raiseUnexpectedSecondOccurenceOfElError(const char* elementName); 0118 0119 //! Decodes boolean attribute. Used by read_b(), read_i(), etc. 0120 bool readBooleanAttr(const char* attrName, bool defaultValue = false) const; 0121 0122 QString m_defaultNamespace; //!< stores namespace (for optimization) 0123 0124 QStack<QByteArray> m_callsNames; 0125 #ifndef NDEBUG 0126 QStack<QByteArray> m_callsNamesDebug; 0127 #endif 0128 0129 private: 0130 Q_DISABLE_COPY(MsooXmlReader) 0131 0132 QString m_fileName; 0133 bool m_readUndoed; 0134 // QXmlStreamReader::TokenType m_recentType; 0135 0136 void init(); 0137 }; 0138 0139 } // namespace MSOOXML 0140 0141 //! debugMsooXml stream operator. Writes this reader to the debug output in a nicely formatted way. 0142 //! @todo add the same for QXmlStreamWriter 0143 KOMSOOXML_EXPORT QDebug operator<<(QDebug dbg, const QXmlStreamReader& reader); 0144 0145 #endif //MSOOXMLREADER_H