syndication/atom
entry.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "entry.h"
00023 #include "category.h"
00024 #include "constants.h"
00025 #include "content.h"
00026 #include "link.h"
00027 #include "person.h"
00028 #include "source.h"
00029 #include "atomtools.h"
00030
00031 #include <specificitemvisitor.h>
00032 #include <tools.h>
00033
00034 #include <QtXml/QDomElement>
00035 #include <QtCore/QList>
00036 #include <QtCore/QString>
00037
00038 namespace Syndication {
00039 namespace Atom {
00040
00041 Entry::Entry() : ElementWrapper()
00042 {
00043 }
00044
00045 Entry::Entry(const QDomElement& element) : ElementWrapper(element)
00046 {
00047 }
00048
00049 QList<Person> Entry::authors() const
00050 {
00051 QList<QDomElement> a =
00052 elementsByTagNameNS(atom1Namespace(),
00053 QString::fromUtf8("author"));
00054 QList<Person> list;
00055
00056 QList<QDomElement>::ConstIterator it = a.begin();
00057 QList<QDomElement>::ConstIterator end = a.end();
00058
00059
00060 for ( ; it != end; ++it)
00061 {
00062 list.append(Person(*it));
00063 }
00064
00065 return list;
00066 }
00067
00068 QList<Person> Entry::contributors() const
00069 {
00070 QList<QDomElement> a =
00071 elementsByTagNameNS(atom1Namespace(),
00072 QString::fromUtf8("contributor"));
00073 QList<Person> list;
00074
00075 QList<QDomElement>::ConstIterator it = a.begin();
00076 QList<QDomElement>::ConstIterator end = a.end();
00077
00078
00079 for ( ; it != end; ++it)
00080 {
00081 list.append(Person(*it));
00082 }
00083
00084 return list;
00085 }
00086
00087 QList<Category> Entry::categories() const
00088 {
00089 QList<QDomElement> a =
00090 elementsByTagNameNS(atom1Namespace(),
00091 QString::fromUtf8("category"));
00092 QList<Category> list;
00093
00094 QList<QDomElement>::ConstIterator it = a.begin();
00095 QList<QDomElement>::ConstIterator end = a.end();
00096
00097
00098 for ( ; it != end; ++it)
00099 {
00100 list.append(Category(*it));
00101 }
00102
00103 return list;
00104 }
00105
00106 QString Entry::id() const
00107 {
00108 return extractElementTextNS(atom1Namespace(),
00109 QString::fromUtf8("id"));
00110
00111 }
00112
00113 QList<Link> Entry::links() const
00114 {
00115 QList<QDomElement> a =
00116 elementsByTagNameNS(atom1Namespace(),
00117 QString::fromUtf8("link"));
00118 QList<Link> list;
00119
00120 QList<QDomElement>::ConstIterator it = a.begin();
00121 QList<QDomElement>::ConstIterator end = a.end();
00122
00123
00124 for ( ; it != end; ++it)
00125 {
00126 list.append(Link(*it));
00127 }
00128
00129 return list;
00130 }
00131
00132 QString Entry::rights() const
00133 {
00134 return extractAtomText(*this, QString::fromUtf8("rights"));
00135 }
00136
00137 Source Entry::source() const
00138 {
00139 return Source(firstElementByTagNameNS(atom1Namespace(),
00140 QString::fromUtf8("source")));
00141 }
00142
00143 time_t Entry::published() const
00144 {
00145 QString pub = extractElementTextNS(atom1Namespace(),
00146 QString::fromUtf8("published"));
00147 return parseDate(pub, ISODate);
00148 }
00149
00150 time_t Entry::updated() const
00151 {
00152 QString upd = extractElementTextNS(atom1Namespace(),
00153 QString::fromUtf8("updated"));
00154 return parseDate(upd, ISODate);
00155 }
00156
00157 QString Entry::summary() const
00158 {
00159 return extractAtomText(*this, QString::fromUtf8("summary"));
00160 }
00161
00162 QString Entry::title() const
00163 {
00164 return extractAtomText(*this, QString::fromUtf8("title"));
00165 }
00166
00167 Content Entry::content() const
00168 {
00169 return Content(firstElementByTagNameNS(atom1Namespace(),
00170 QString::fromUtf8("content")));
00171 }
00172
00173 QList<QDomElement> Entry::unhandledElements() const
00174 {
00175
00176 QList<ElementType> handled;
00177 handled.append(ElementType(QString::fromUtf8("author"), atom1Namespace()));
00178 handled.append(ElementType(QString::fromUtf8("contributor"), atom1Namespace()));
00179 handled.append(ElementType(QString::fromUtf8("category"), atom1Namespace()));
00180 handled.append(ElementType(QString::fromUtf8("id"), atom1Namespace()));
00181 handled.append(ElementType(QString::fromUtf8("link"), atom1Namespace()));
00182 handled.append(ElementType(QString::fromUtf8("rights"), atom1Namespace()));
00183 handled.append(ElementType(QString::fromUtf8("source"), atom1Namespace()));
00184 handled.append(ElementType(QString::fromUtf8("published"), atom1Namespace()));
00185 handled.append(ElementType(QString::fromUtf8("updated"), atom1Namespace()));
00186 handled.append(ElementType(QString::fromUtf8("summary"), atom1Namespace()));
00187 handled.append(ElementType(QString::fromUtf8("title"), atom1Namespace()));
00188 handled.append(ElementType(QString::fromUtf8("content"), atom1Namespace()));
00189
00190 QList<QDomElement> notHandled;
00191
00192 QDomNodeList children = element().childNodes();
00193 for (int i = 0; i < children.size(); ++i)
00194 {
00195 QDomElement el = children.at(i).toElement();
00196 if (!el.isNull()
00197 && !handled.contains(ElementType(el.localName(), el.namespaceURI())))
00198 {
00199 notHandled.append(el);
00200 }
00201 }
00202
00203 return notHandled;
00204 }
00205
00206 QString Entry::debugInfo() const
00207 {
00208 QString info;
00209 info += "### Entry: ###################\n";
00210 if (!title().isEmpty())
00211 info += "title: #" + title() + "#\n";
00212 if (!summary().isEmpty())
00213 info += "summary: #" + summary() + "#\n";
00214 if (!id().isEmpty())
00215 info += "id: #" + id() + "#\n";
00216 if (!content().isNull())
00217 info += content().debugInfo();
00218
00219 if (!rights().isEmpty())
00220 info += "rights: #" + rights() + "#\n";
00221
00222
00223 QString dupdated = dateTimeToString(updated());
00224 if (!dupdated.isNull())
00225 info += "updated: #" + dupdated + "#\n";
00226
00227 QString dpublished = dateTimeToString(published());
00228 if (!dpublished.isNull())
00229 info += "published: #" + dpublished + "#\n";
00230
00231 QList<Link> dlinks = links();
00232 QList<Link>::ConstIterator endlinks = dlinks.end();
00233 for (QList<Link>::ConstIterator it = dlinks.begin(); it != endlinks; ++it)
00234 info += (*it).debugInfo();
00235
00236 QList<Category> dcats = categories();
00237 QList<Category>::ConstIterator endcats = dcats.end();
00238 for (QList<Category>::ConstIterator it = dcats.begin(); it != endcats; ++it)
00239 info += (*it).debugInfo();
00240
00241 info += "### Authors: ###################\n";
00242
00243 QList<Person> dauthors = authors();
00244 QList<Person>::ConstIterator endauthors = dauthors.end();
00245 for (QList<Person>::ConstIterator it = dauthors.begin(); it != endauthors; ++it)
00246 info += (*it).debugInfo();
00247
00248 info += "### Contributors: ###################\n";
00249
00250 QList<Person> dcontri = contributors();
00251 QList<Person>::ConstIterator endcontri = dcontri.end();
00252 for (QList<Person>::ConstIterator it = dcontri.begin(); it != endcontri; ++it)
00253 info += (*it).debugInfo();
00254
00255 if (!source().isNull())
00256 info += source().debugInfo();
00257
00258 info += "### Entry end ################\n";
00259
00260 return info;
00261 }
00262
00263 bool Entry::accept(SpecificItemVisitor* visitor)
00264 {
00265 return visitor->visitAtomEntry(this);
00266 }
00267
00268 }
00269 }
00270