Warning, file /office/calligra/filters/libmsooxml/MsooXmlReader.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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