File indexing completed on 2024-06-23 04:03:44
0001 /* 0002 * xmlcommon.h - helper functions for dealing with XML 0003 * Copyright (C) 2001, 2002 Justin Karneges 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * either version 2 0009 of the License, or (at your option) any later version.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0019 * 0020 */ 0021 0022 #ifndef JABBER_XMLCOMMON_H 0023 #define JABBER_XMLCOMMON_H 0024 0025 #include <qdom.h> 0026 #include <QList> 0027 #include <QStringList> 0028 0029 #include "iris_export.h" 0030 0031 class QDateTime; 0032 class QRect; 0033 class QSize; 0034 class QColor; 0035 0036 class IRIS_EXPORT XDomNodeList 0037 { 0038 public: 0039 XDomNodeList(); 0040 XDomNodeList(const XDomNodeList &from); 0041 XDomNodeList(const QDomNodeList &from); 0042 ~XDomNodeList(); 0043 XDomNodeList & operator=(const XDomNodeList &from); 0044 0045 QDomNode at(int index) const { return item(index); } 0046 int count() const { return (int)length(); } 0047 bool isEmpty() const; 0048 QDomNode item(int index) const; 0049 uint length() const; 0050 int size() const { return (int)length(); } 0051 0052 void append(const QDomNode &i); 0053 0054 bool operator==(const XDomNodeList &a) const; 0055 0056 bool operator!=(const XDomNodeList &a) const 0057 { 0058 return !operator==(a); 0059 } 0060 0061 private: 0062 QList<QDomNode> list; 0063 }; 0064 0065 QDateTime IRIS_EXPORT stamp2TS(const QString &ts); 0066 bool IRIS_EXPORT stamp2TS(const QString &ts, QDateTime *d); 0067 QString IRIS_EXPORT TS2stamp(const QDateTime &d); 0068 QDomElement IRIS_EXPORT textTag(QDomDocument *doc, const QString &name, const QString &content); 0069 QString IRIS_EXPORT tagContent(const QDomElement &e); 0070 QDomElement IRIS_EXPORT findSubTag(const QDomElement &e, const QString &name, bool *found); 0071 XDomNodeList IRIS_EXPORT childElementsByTagNameNS(const QDomElement &e, const QString &nsURI, const QString &localName); 0072 QDomElement IRIS_EXPORT createIQ(QDomDocument *doc, const QString &type, const QString &to, const QString &id); 0073 QDomElement IRIS_EXPORT queryTag(const QDomElement &e); 0074 QString IRIS_EXPORT queryNS(const QDomElement &e); 0075 void IRIS_EXPORT getErrorFromElement(const QDomElement &e, const QString &baseNS, int *code, QString *str); 0076 QDomElement IRIS_EXPORT addCorrectNS(const QDomElement &e); 0077 0078 namespace XMLHelper { 0079 //QDomElement findSubTag(const QDomElement &e, const QString &name, bool *found); 0080 bool IRIS_EXPORT hasSubTag(const QDomElement &e, const QString &name); 0081 0082 QDomElement IRIS_EXPORT emptyTag(QDomDocument *doc, const QString &name); 0083 QString IRIS_EXPORT subTagText(const QDomElement &e, const QString &name); 0084 0085 QDomElement IRIS_EXPORT textTag(QDomDocument &doc, const QString &name, const QString &content); 0086 QDomElement IRIS_EXPORT textTag(QDomDocument &doc, const QString &name, int content); 0087 QDomElement IRIS_EXPORT textTag(QDomDocument &doc, const QString &name, bool content); 0088 QDomElement IRIS_EXPORT textTag(QDomDocument &doc, const QString &name, QSize &s); 0089 QDomElement IRIS_EXPORT textTag(QDomDocument &doc, const QString &name, QRect &r); 0090 QDomElement IRIS_EXPORT stringListToXml(QDomDocument &doc, const QString &name, const QStringList &l); 0091 0092 void IRIS_EXPORT readEntry(const QDomElement &e, const QString &name, QString *v); 0093 void IRIS_EXPORT readNumEntry(const QDomElement &e, const QString &name, int *v); 0094 void IRIS_EXPORT readBoolEntry(const QDomElement &e, const QString &name, bool *v); 0095 void IRIS_EXPORT readSizeEntry(const QDomElement &e, const QString &name, QSize *v); 0096 void IRIS_EXPORT readRectEntry(const QDomElement &e, const QString &name, QRect *v); 0097 void IRIS_EXPORT readColorEntry(const QDomElement &e, const QString &name, QColor *v); 0098 0099 void IRIS_EXPORT xmlToStringList(const QDomElement &e, const QString &name, QStringList *v); 0100 0101 void IRIS_EXPORT setBoolAttribute(QDomElement e, const QString &name, bool b); 0102 void IRIS_EXPORT readBoolAttribute(QDomElement e, const QString &name, bool *v); 0103 0104 //QString tagContent(const QDomElement &e); // obsolete; 0105 } 0106 0107 #endif