1 /*************************************************************************** 2 * This file is part of the Lime Report project * 3 * Copyright (C) 2015 by Alexander Arin * 4 * arin_a@bk.ru * 5 * * 6 ** GNU General Public License Usage ** 7 * * 8 * This library is free software: you can redistribute it and/or modify * 9 * it under the terms of the GNU General Public License as published by * 10 * the Free Software Foundation, either version 3 of the License, or * 11 * (at your option) any later version. * 12 * You should have received a copy of the GNU General Public License * 13 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 14 * * 15 ** GNU Lesser General Public License ** 16 * * 17 * This library is free software: you can redistribute it and/or modify * 18 * it under the terms of the GNU Lesser General Public License as * 19 * published by the Free Software Foundation, either version 3 of the * 20 * License, or (at your option) any later version. * 21 * You should have received a copy of the GNU Lesser General Public * 22 * License along with this library. * 23 * If not, see <http://www.gnu.org/licenses/>. * 24 * * 25 * This library is distributed in the hope that it will be useful, * 26 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 28 * GNU General Public License for more details. * 29 ****************************************************************************/ 30 #ifndef LRXMLREADER_H 31 #define LRXMLREADER_H 32 33 #include <QString> 34 #include <QtXml> 35 36 #include "serializators/lrxmlwriter.h" 37 #include "lrdesignelementsfactory.h" 38 39 namespace LimeReport{ 40 41 class XMLReader : public ItemsReaderIntf 42 { 43 public: 44 XMLReader(); 45 XMLReader(QSharedPointer<QDomDocument> doc); 46 protected: 47 //ItemsReaderIntf interface 48 bool first(); 49 bool next(); 50 bool prior(); 51 QString itemType(); 52 QString itemClassName(); 53 bool readItem(QObject *item); 54 int firstLevelItemsCount(); 55 QString lastError(); 56 void setPassPhrase(const QString &passPhrase); 57 58 virtual bool prepareReader(QDomDocument *doc); 59 60 void readItemFromNode(QObject *item, QDomElement *node); 61 void readProperty(QObject *item, QDomElement *node); 62 void readQObject(QObject *item, QDomElement *node); 63 void readCollection(QObject *item, QDomElement *node); 64 void readTranslation(QObject *item, QDomElement *node); 65 QVariant getValue(QDomElement *node); 66 67 protected: 68 bool extractFirstNode(); 69 QString m_error; 70 private: 71 QSharedPointer<QDomDocument> m_doc; 72 QDomElement m_curNode; 73 QDomElement m_firstNode; 74 QString m_passPhrase; 75 }; 76 77 class FileXMLReader : public XMLReader{ 78 public: create(QString fileName)79 static ItemsReaderIntf::Ptr create(QString fileName){ return ItemsReaderIntf::Ptr(new FileXMLReader(fileName));} 80 protected: 81 virtual bool prepareReader(QDomDocument *doc); 82 private: 83 FileXMLReader(QString fileName); 84 QString m_fileName; 85 }; 86 87 class StringXMLreader : public XMLReader{ 88 public: create(QString content)89 static ItemsReaderIntf::Ptr create(QString content){ return ItemsReaderIntf::Ptr(new StringXMLreader(content));} 90 protected: 91 virtual bool prepareReader(QDomDocument *doc); 92 private: StringXMLreader(QString content)93 StringXMLreader(QString content) : m_content(content){} 94 QString m_content; 95 }; 96 97 class ByteArrayXMLReader : public XMLReader{ 98 public: create(QByteArray * content)99 static ItemsReaderIntf::Ptr create(QByteArray* content){ return ItemsReaderIntf::Ptr(new ByteArrayXMLReader(content));} 100 protected: 101 virtual bool prepareReader(QDomDocument *doc); 102 private: ByteArrayXMLReader(QByteArray * content)103 ByteArrayXMLReader(QByteArray* content): m_content(content){} 104 QByteArray* m_content; 105 }; 106 107 } 108 #endif // LRXMLREADER_H 109