00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "source.h"
00024 #include "category.h"
00025 #include "constants.h"
00026 #include "generator.h"
00027 #include "link.h"
00028 #include "person.h"
00029 #include "atomtools.h"
00030
00031 #include <tools.h>
00032
00033 #include <QtXml/QDomElement>
00034 #include <QtCore/QList>
00035 #include <QtCore/QString>
00036
00037 namespace Syndication {
00038 namespace Atom {
00039
00040 Source::Source() : ElementWrapper()
00041 {
00042 }
00043
00044 Source::Source(const QDomElement& element) : ElementWrapper(element)
00045 {
00046 }
00047
00048 QList<Person> Source::authors() const
00049 {
00050 QList<QDomElement> a =
00051 elementsByTagNameNS(atom1Namespace(),
00052 QString::fromUtf8("author"));
00053 QList<Person> list;
00054
00055 QList<QDomElement>::ConstIterator it = a.constBegin();
00056 QList<QDomElement>::ConstIterator end = a.constEnd();
00057
00058
00059 for ( ; it != end; ++it)
00060 {
00061 list.append(Person(*it));
00062 }
00063
00064 return list;
00065 }
00066
00067 QList<Person> Source::contributors() const
00068 {
00069 QList<QDomElement> a =
00070 elementsByTagNameNS(atom1Namespace(),
00071 QString::fromUtf8("contributor"));
00072 QList<Person> list;
00073
00074 QList<QDomElement>::ConstIterator it = a.constBegin();
00075 QList<QDomElement>::ConstIterator end = a.constEnd();
00076
00077
00078 for ( ; it != end; ++it)
00079 {
00080 list.append(Person(*it));
00081 }
00082
00083 return list;
00084 }
00085
00086 QList<Category> Source::categories() const
00087 {
00088 QList<QDomElement> a =
00089 elementsByTagNameNS(atom1Namespace(),
00090 QString::fromUtf8("category"));
00091 QList<Category> list;
00092
00093 QList<QDomElement>::ConstIterator it = a.constBegin();
00094 QList<QDomElement>::ConstIterator end = a.constEnd();
00095
00096
00097 for ( ; it != end; ++it)
00098 {
00099 list.append(Category(*it));
00100 }
00101
00102 return list;
00103 }
00104
00105 Generator Source::generator() const
00106 {
00107 return Generator(firstElementByTagNameNS(atom1Namespace(),
00108 QString::fromUtf8("generator")));
00109 }
00110
00111 QString Source::icon() const
00112 {
00113 return extractElementTextNS(atom1Namespace(),
00114 QString::fromUtf8("icon"));
00115 }
00116
00117 QString Source::id() const
00118 {
00119 return extractElementTextNS(atom1Namespace(),
00120 QString::fromUtf8("id"));
00121 }
00122
00123 QList<Link> Source::links() const
00124 {
00125 QList<QDomElement> a =
00126 elementsByTagNameNS(atom1Namespace(),
00127 QString::fromUtf8("link"));
00128 QList<Link> list;
00129
00130 QList<QDomElement>::ConstIterator it = a.constBegin();
00131 QList<QDomElement>::ConstIterator end = a.constEnd();
00132
00133
00134 for ( ; it != end; ++it)
00135 {
00136 list.append(Link(*it));
00137 }
00138
00139 return list;
00140 }
00141
00142 QString Source::logo() const
00143 {
00144 return extractElementTextNS(atom1Namespace(),
00145 QString::fromUtf8("logo"));
00146 }
00147
00148 QString Source::rights() const
00149 {
00150 return extractAtomText(*this, QString::fromUtf8("rights"));
00151 }
00152
00153 QString Source::subtitle() const
00154 {
00155 return extractAtomText(*this, QString::fromUtf8("subtitle"));
00156 }
00157
00158 QString Source::title() const
00159 {
00160 return extractAtomText(*this, QString::fromUtf8("title"));
00161 }
00162
00163 time_t Source::updated() const
00164 {
00165 QString upd = extractElementTextNS(atom1Namespace(),
00166 QString::fromUtf8("updated"));
00167 return parseDate(upd, ISODate);
00168 }
00169
00170 QString Source::debugInfo() const
00171 {
00172 QString info;
00173 info += "### Source: ###################\n";
00174 if (!title().isEmpty())
00175 info += "title: #" + title() + "#\n";
00176 if (!subtitle().isEmpty())
00177 info += "subtitle: #" + subtitle() + "#\n";
00178 if (!id().isEmpty())
00179 info += "id: #" + id() + "#\n";
00180
00181 if (!rights().isEmpty())
00182 info += "rights: #" + rights() + "#\n";
00183 if (!icon().isEmpty())
00184 info += "icon: #" + icon() + "#\n";
00185 if (!logo().isEmpty())
00186 info += "logo: #" + logo() + "#\n";
00187 if (!generator().isNull())
00188 info += generator().debugInfo();
00189
00190
00191 QString dupdated = dateTimeToString(updated());
00192 if (!dupdated.isNull())
00193 info += "updated: #" + dupdated + "#\n";
00194
00195 QList<Link> dlinks = links();
00196 QList<Link>::ConstIterator endlinks = dlinks.constEnd();
00197 for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it)
00198 info += (*it).debugInfo();
00199
00200 QList<Category> dcats = categories();
00201 QList<Category>::ConstIterator endcats = dcats.constEnd();
00202 for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it)
00203 info += (*it).debugInfo();
00204
00205 info += "### Authors: ###################\n";
00206
00207 QList<Person> dauthors = authors();
00208 QList<Person>::ConstIterator endauthors = dauthors.constEnd();
00209 for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it)
00210 info += (*it).debugInfo();
00211
00212 info += "### Contributors: ###################\n";
00213
00214 QList<Person> dcontri = contributors();
00215 QList<Person>::ConstIterator endcontri = dcontri.constEnd();
00216 for (QList<Person>::ConstIterator it = dcontri.constBegin(); it != endcontri; ++it)
00217 info += (*it).debugInfo();
00218
00219 info += "### Source end ################\n";
00220
00221 return info;
00222 }
00223
00224 }
00225 }