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