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

syndication/rdf

document.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 
00023 #include "document.h"
00024 #include "dublincore.h"
00025 #include "image.h"
00026 #include "item.h"
00027 #include "model.h"
00028 #include "resource.h"
00029 #include "rssvocab.h"
00030 #include "sequence.h"
00031 #include "statement.h"
00032 #include "syndicationinfo.h"
00033 #include "textinput.h"
00034 
00035 #include <documentvisitor.h>
00036 #include <tools.h>
00037 
00038 #include <QtCore/QList>
00039 #include <QtCore/QString>
00040 
00041 namespace Syndication {
00042 namespace RDF {
00043 
00044 class Document::Private
00045 {
00046     public:
00047     Private() : itemTitleContainsMarkup(false),
00048                 itemTitlesGuessed(false),
00049                 itemDescriptionContainsMarkup(false),
00050                 itemDescGuessed(false)
00051     {}
00052     mutable bool itemTitleContainsMarkup;
00053     mutable bool itemTitlesGuessed;
00054     mutable bool itemDescriptionContainsMarkup;
00055     mutable bool itemDescGuessed;
00056 };
00057 
00058 Document::Document() : Syndication::SpecificDocument(), 
00059                        ResourceWrapper(),
00060                        d(new Private)
00061 {
00062 }
00063 
00064 Document::Document(ResourcePtr resource) : Syndication::SpecificDocument(),
00065                                            ResourceWrapper(resource),
00066                                            d(new Private)
00067 {
00068 }
00069 
00070 Document::Document(const Document& other) : SpecificDocument(other),                                                      ResourceWrapper(other),
00071                                             d(new Private)
00072 {
00073     *d = *(other.d);
00074 }
00075 
00076 Document::~Document()
00077 {
00078     delete d;
00079     d = 0;
00080 }
00081 
00082 
00083 bool Document::operator==(const Document& other) const
00084 {
00085     return ResourceWrapper::operator==(other);
00086 }
00087 
00088 
00089 Document& Document::operator=(const Document& other)
00090 {
00091     ResourceWrapper::operator=(other);
00092     *d = *(other.d);
00093     
00094     return *this;
00095 }
00096 
00097         
00098 bool Document::accept(DocumentVisitor* visitor)
00099 {
00100     return visitor->visitRDFDocument(this);
00101 }
00102 
00103 bool Document::isValid() const
00104 {
00105     return !isNull();
00106 }
00107         
00108 QString Document::title() const
00109 {
00110     QString str = resource()->property(RSSVocab::self()->title())->asString();
00111     return normalize(str);
00112 
00113 }
00114 
00115 QString Document::description() const
00116 {
00117     QString str = resource()->property(RSSVocab::self()->description())->asString();
00118     return normalize(str);
00119 }
00120 
00121 QString Document::link() const
00122 {
00123     return resource()->property(RSSVocab::self()->link())->asString();
00124 }
00125 
00126 DublinCore Document::dc() const
00127 {
00128     return DublinCore(resource());
00129 }
00130 
00131 SyndicationInfo Document::syn() const
00132 {
00133     return SyndicationInfo(resource());
00134 }
00135 
00136 QList<Item> Document::items() const
00137 {
00138     QList<Item> list;
00139     if (!resource()->hasProperty(RSSVocab::self()->items()))
00140         return list;
00141     
00142     NodePtr n = resource()->property(RSSVocab::self()->items())->object();
00143     if (n->isSequence())
00144     {
00145         Sequence* seq = static_cast<Sequence*>(n.get());
00146         
00147         QList<NodePtr> items = seq->items();
00148         QList<NodePtr>::Iterator it = items.begin();
00149         QList<NodePtr>::Iterator end = items.end();
00150         
00151         DocumentPtr doccpy(new Document(*this));
00152         
00153         for ( ; it != end; ++it)
00154         {
00155             if ((*it)->isResource())
00156             {
00157                 // well, we need it as ResourcePtr
00158                 // maybe this should go to the node
00159                 // interface ResourcePtr asResource()?
00160                 ResourcePtr ptr = resource()->model().createResource((static_cast<Resource*>((*it).get()))->uri());
00161                 
00162                 list.append(Item(ptr, doccpy));
00163             }
00164         }
00165     
00166     }
00167     return list;
00168 }
00169 
00170 Image Document::image() const
00171 {
00172     ResourcePtr img = resource()->property(RSSVocab::self()->image())->asResource();
00173     
00174     return img ? Image(img) : Image();
00175 }
00176 
00177 TextInput Document::textInput() const
00178 {
00179     ResourcePtr ti = resource()->property(RSSVocab::self()->textinput())->asResource();
00180     
00181     return ti ? TextInput(ti) : TextInput();
00182 }
00183 
00184 void Document::getItemTitleFormatInfo(bool* containsMarkup) const
00185 {
00186     if (!d->itemTitlesGuessed)
00187     {
00188         QString titles;
00189         QList<Item> litems = items();
00190         
00191         if (litems.isEmpty())
00192         {
00193             d->itemTitlesGuessed = true;
00194             return;
00195         }
00196         
00197         int nmax = litems.size() < 10 ? litems.size() : 10; // we check a maximum of 10 items
00198         int i = 0;
00199         
00200         QList<Item>::ConstIterator it = litems.begin(); 
00201         
00202         while (i < nmax)
00203         {
00204             titles += (*it).originalTitle();
00205             ++it;
00206             ++i;
00207         }
00208         
00209         d->itemTitleContainsMarkup = stringContainsMarkup(titles);
00210         d->itemTitlesGuessed = true;
00211     }
00212     if (containsMarkup != 0L)
00213         *containsMarkup = d->itemTitleContainsMarkup;
00214 }
00215         
00216 void Document::getItemDescriptionFormatInfo(bool* containsMarkup) const
00217 {
00218     if (!d->itemDescGuessed)
00219     {
00220         QString desc;
00221         QList<Item> litems = items();
00222         
00223         
00224         if (litems.isEmpty())
00225         {
00226             d->itemDescGuessed = true;
00227             return;
00228         }
00229         
00230         int nmax = litems.size() < 10 ? litems.size() : 10; // we check a maximum of 10 items
00231         int i = 0;
00232 
00233         QList<Item>::ConstIterator it = litems.begin(); 
00234 
00235         while (i < nmax)
00236         {
00237             desc += (*it).originalDescription();
00238             ++it;
00239             ++i;
00240         }
00241 
00242         d->itemDescriptionContainsMarkup = stringContainsMarkup(desc);
00243         d->itemDescGuessed = true;
00244     }
00245     
00246     if (containsMarkup != 0L)
00247         *containsMarkup = d->itemDescriptionContainsMarkup;
00248 }
00249 
00250 QString Document::debugInfo() const
00251 {
00252     QString info;
00253     info += "### Document: ###################\n";
00254     info += "title: #" + title() + "#\n";
00255     info += "link: #" + link() + "#\n";
00256     info += "description: #" + description() + "#\n";
00257     info += dc().debugInfo();
00258     info += syn().debugInfo();
00259     Image img = image();
00260     if (!img.resource() == 0L)
00261         info += img.debugInfo();
00262     TextInput input = textInput();
00263     if (!input.isNull())
00264         info += input.debugInfo();
00265 
00266     QList<Item> itlist = items();
00267     QList<Item>::ConstIterator it = itlist.begin();
00268     QList<Item>::ConstIterator end = itlist.end();
00269     for ( ; it != end; ++it)
00270         info += (*it).debugInfo();
00271     
00272     
00273     info += "### Document end ################\n";
00274     return info;
00275 }
00276 
00277 } // namespace RDF
00278 } // namespace Syndication

syndication/rdf

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
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