• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

syndication/atom

entry.cpp

00001 /*
00002  * This file is part of the syndication library
00003  *
00004  * Copyright (C) 2006 Frank Osterfeld <osterfeld@kde.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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.constBegin();
00057     QList<QDomElement>::ConstIterator end = a.constEnd();
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.constBegin();
00076     QList<QDomElement>::ConstIterator end = a.constEnd();
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.constBegin();
00095     QList<QDomElement>::ConstIterator end = a.constEnd();
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.constBegin();
00121     QList<QDomElement>::ConstIterator end = a.constEnd();
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     // TODO: do not hardcode this list here
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.constEnd();
00233     for (QList<Link>::ConstIterator it = dlinks.constBegin(); it != endlinks; ++it)
00234         info += (*it).debugInfo();
00235     
00236     QList<Category> dcats = categories();
00237     QList<Category>::ConstIterator endcats = dcats.constEnd();
00238     for (QList<Category>::ConstIterator it = dcats.constBegin(); it != endcats; ++it)
00239         info += (*it).debugInfo();
00240 
00241     info += "### Authors: ###################\n";
00242     
00243     QList<Person> dauthors = authors();
00244     QList<Person>::ConstIterator endauthors = dauthors.constEnd();
00245     for (QList<Person>::ConstIterator it = dauthors.constBegin(); it != endauthors; ++it)
00246         info += (*it).debugInfo();
00247 
00248     info += "### Contributors: ###################\n";
00249     
00250     QList<Person> dcontri = contributors();
00251     QList<Person>::ConstIterator endcontri = dcontri.constEnd();
00252     for (QList<Person>::ConstIterator it = dcontri.constBegin(); 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 } // namespace Atom
00269 } //namespace Syndication
00270 

syndication/atom

Skip menu "syndication/atom"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal