• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

syndication/rdf

  • syndication
  • rdf
document.cpp
1/*
2 * This file is part of the syndication library
3 *
4 * Copyright (C) 2006 Frank Osterfeld <osterfeld@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "document.h"
24#include "dublincore.h"
25#include "image.h"
26#include "item.h"
27#include "model.h"
28#include "model_p.h"
29#include "resource.h"
30#include "rssvocab.h"
31#include "sequence.h"
32#include "statement.h"
33#include "syndicationinfo.h"
34#include "textinput.h"
35
36#include <documentvisitor.h>
37#include <tools.h>
38
39#include <QtCore/QList>
40#include <QtCore/QString>
41#include <QtCore/QStringList>
42#include <QtCore/QVector>
43
44using namespace boost;
45
46namespace Syndication {
47namespace RDF {
48
49class Document::Private
50{
51 public:
52 Private() : itemTitleContainsMarkup(false),
53 itemTitlesGuessed(false),
54 itemDescriptionContainsMarkup(false),
55 itemDescGuessed(false)
56 {}
57 mutable bool itemTitleContainsMarkup;
58 mutable bool itemTitlesGuessed;
59 mutable bool itemDescriptionContainsMarkup;
60 mutable bool itemDescGuessed;
61 shared_ptr<Model::ModelPrivate> modelPrivate;
62};
63
64Document::Document() : Syndication::SpecificDocument(),
65 ResourceWrapper(),
66 d(new Private)
67{
68 d->modelPrivate = resource()->model().d;
69}
70
71Document::Document(ResourcePtr resource) : Syndication::SpecificDocument(),
72 ResourceWrapper(resource),
73 d(new Private)
74{
75 d->modelPrivate = resource->model().d;
76}
77
78Document::Document(const Document& other) : SpecificDocument(other), ResourceWrapper(other),
79 d(new Private)
80{
81 *d = *(other.d);
82}
83
84Document::~Document()
85{
86 delete d;
87}
88
89
90bool Document::operator==(const Document& other) const
91{
92 return ResourceWrapper::operator==(other);
93}
94
95
96Document& Document::operator=(const Document& other)
97{
98 ResourceWrapper::operator=(other);
99 *d = *(other.d);
100
101 return *this;
102}
103
104
105bool Document::accept(DocumentVisitor* visitor)
106{
107 return visitor->visitRDFDocument(this);
108}
109
110bool Document::isValid() const
111{
112 return !isNull();
113}
114
115QString Document::title() const
116{
117 QString str = resource()->property(RSSVocab::self()->title())->asString();
118 return normalize(str);
119
120}
121
122QString Document::description() const
123{
124 QString str = resource()->property(RSSVocab::self()->description())->asString();
125 return normalize(str);
126}
127
128QString Document::link() const
129{
130 return resource()->property(RSSVocab::self()->link())->asString();
131}
132
133DublinCore Document::dc() const
134{
135 return DublinCore(resource());
136}
137
138SyndicationInfo Document::syn() const
139{
140 return SyndicationInfo(resource());
141}
142
143
144struct SortItem {
145 Item item;
146 int index;
147};
148
149struct LessThanByIndex {
150 bool operator()(const SortItem& lhs, const SortItem& rhs) const {
151 return lhs.index < rhs.index;
152 }
153};
154
155static QList<Item> sortListToMatchSequence(QList<Item> items, const QStringList& uriSequence) {
156 QVector<SortItem> toSort;
157 toSort.reserve(items.size());
158 Q_FOREACH(const Item& i, items) {
159 SortItem item;
160 item.item = i;
161 item.index = uriSequence.indexOf(i.resource()->uri());
162 toSort.append(item);
163 }
164 qSort(toSort.begin(), toSort.end(), LessThanByIndex());
165
166 int i = 0;
167 Q_FOREACH(const SortItem& sortItem, toSort) {
168 items[i] = sortItem.item;
169 i++;
170 }
171
172 return items;
173}
174
175QList<Item> Document::items() const
176{
177 QList<Item> list;
178
179 const QList<ResourcePtr> items = resource()->model().resourcesWithType(RSSVocab::self()->item());
180 DocumentPtr doccpy(new Document(*this));
181 Q_FOREACH (const ResourcePtr& i, items)
182 list.append(Item(i, doccpy));
183
184 if (resource()->hasProperty(RSSVocab::self()->items())) {
185 NodePtr n = resource()->property(RSSVocab::self()->items())->object();
186 if (n->isSequence())
187 {
188 Sequence* seq = static_cast<Sequence*>(n.get());
189
190 const QList<NodePtr> seqItems = seq->items();
191
192 QStringList uriSequence;
193 uriSequence.reserve(seqItems.size());
194
195 Q_FOREACH(const NodePtr& i, seqItems)
196 if (i->isResource())
197 uriSequence.append(static_cast<Resource*>(i.get())->uri());
198 list = sortListToMatchSequence(list, uriSequence);
199 }
200 }
201
202 return list;
203}
204
205Image Document::image() const
206{
207 ResourcePtr img = resource()->property(RSSVocab::self()->image())->asResource();
208
209 return img ? Image(img) : Image();
210}
211
212TextInput Document::textInput() const
213{
214 ResourcePtr ti = resource()->property(RSSVocab::self()->textinput())->asResource();
215
216 return ti ? TextInput(ti) : TextInput();
217}
218
219void Document::getItemTitleFormatInfo(bool* containsMarkup) const
220{
221 if (!d->itemTitlesGuessed)
222 {
223 QString titles;
224 QList<Item> litems = items();
225
226 if (litems.isEmpty())
227 {
228 d->itemTitlesGuessed = true;
229 return;
230 }
231
232 int nmax = litems.size() < 10 ? litems.size() : 10; // we check a maximum of 10 items
233 int i = 0;
234
235 QList<Item>::ConstIterator it = litems.constBegin();
236
237 while (i < nmax)
238 {
239 titles += (*it).originalTitle();
240 ++it;
241 ++i;
242 }
243
244 d->itemTitleContainsMarkup = stringContainsMarkup(titles);
245 d->itemTitlesGuessed = true;
246 }
247 if (containsMarkup != 0L)
248 *containsMarkup = d->itemTitleContainsMarkup;
249}
250
251void Document::getItemDescriptionFormatInfo(bool* containsMarkup) const
252{
253 if (!d->itemDescGuessed)
254 {
255 QString desc;
256 QList<Item> litems = items();
257
258
259 if (litems.isEmpty())
260 {
261 d->itemDescGuessed = true;
262 return;
263 }
264
265 int nmax = litems.size() < 10 ? litems.size() : 10; // we check a maximum of 10 items
266 int i = 0;
267
268 QList<Item>::ConstIterator it = litems.constBegin();
269
270 while (i < nmax)
271 {
272 desc += (*it).originalDescription();
273 ++it;
274 ++i;
275 }
276
277 d->itemDescriptionContainsMarkup = stringContainsMarkup(desc);
278 d->itemDescGuessed = true;
279 }
280
281 if (containsMarkup != 0L)
282 *containsMarkup = d->itemDescriptionContainsMarkup;
283}
284
285QString Document::debugInfo() const
286{
287 QString info;
288 info += QLatin1String("### Document: ###################\n");
289 info += QLatin1String("title: #") + title() + QLatin1String("#\n");
290 info += QLatin1String("link: #") + link() + QLatin1String("#\n");
291 info += QLatin1String("description: #") + description() + QLatin1String("#\n");
292 info += dc().debugInfo();
293 info += syn().debugInfo();
294 Image img = image();
295 if (!img.resource() == 0L)
296 info += img.debugInfo();
297 TextInput input = textInput();
298 if (!input.isNull())
299 info += input.debugInfo();
300
301 QList<Item> itlist = items();
302 QList<Item>::ConstIterator it = itlist.constBegin();
303 QList<Item>::ConstIterator end = itlist.constEnd();
304 for ( ; it != end; ++it)
305 info += (*it).debugInfo();
306
307
308 info += QLatin1String("### Document end ################\n");
309 return info;
310}
311
312} // namespace RDF
313} // namespace Syndication
Syndication::RDF::Document
Document implementation for RDF, representing an RSS 1.0 feed.
Definition document.h:52
Syndication::RDF::Document::Document
Document()
creates a wrapper wrapping a null resource
Definition document.cpp:64
Syndication::RDF::Document::items
QList< Item > items() const
list of items contained in this feed
Definition document.cpp:175
Syndication::RDF::Document::description
QString description() const
A brief description of the channel's content, function, source, etc.
Definition document.cpp:122
Syndication::RDF::Document::isValid
bool isValid() const
returns whether this document is valid or not.
Definition document.cpp:110
Syndication::RDF::Document::debugInfo
virtual QString debugInfo() const
PRIVATE.
Definition document.cpp:285
Syndication::RDF::Document::dc
DublinCore dc() const
returns a dublin core description of the document.
Definition document.cpp:133
Syndication::RDF::Document::textInput
TextInput textInput() const
An optional text input element associated with the channel.
Definition document.cpp:212
Syndication::RDF::Document::link
QString link() const
The URL to which an HTML rendering of the channel title will link, commonly the parent site's home or...
Definition document.cpp:128
Syndication::RDF::Document::title
QString title() const
title of the feed (required)
Definition document.cpp:115
Syndication::RDF::Document::operator=
Document & operator=(const Document &other)
assigns another document
Definition document.cpp:96
Syndication::RDF::Document::operator==
bool operator==(const Document &other) const
compares two documents.
Definition document.cpp:90
Syndication::RDF::Document::accept
virtual bool accept(DocumentVisitor *visitor)
Used by visitors for double dispatch.
Definition document.cpp:105
Syndication::RDF::Document::~Document
virtual ~Document()
destructor
Definition document.cpp:84
Syndication::RDF::Document::image
Image image() const
An image to be associated with an HTML rendering of the channel.
Definition document.cpp:205
Syndication::RDF::Document::syn
SyndicationInfo syn() const
returns syndication information describing how often this feed is updated.
Definition document.cpp:138
Syndication::RDF::DublinCore
A resource wrapper providing convenient access to Dublin Core metadata.
Definition dublincore.h:49
Syndication::RDF::DublinCore::debugInfo
QString debugInfo() const
returns a debug string describing the available DC metadata for debugging purposes
Definition dublincore.cpp:169
Syndication::RDF::Image
An image to be associated with an HTML rendering of the channel.
Definition image.h:42
Syndication::RDF::Image::debugInfo
QString debugInfo() const
Returns a description of the image for debugging purposes.
Definition image.cpp:59
Syndication::RDF::Item
An RSS 1.0 item.
Definition item.h:49
Syndication::RDF::RSSVocab::self
static RSSVocab * self()
returns the singleton instance
Definition rssvocab.cpp:81
Syndication::RDF::ResourceWrapper
A wrapper for RDF resources.
Definition resourcewrapper.h:41
Syndication::RDF::ResourceWrapper::operator=
ResourceWrapper & operator=(const ResourceWrapper &other)
Assignment oeprator Due to the shared d pointer, this is a cheap operation.
Definition resourcewrapper.cpp:59
Syndication::RDF::ResourceWrapper::isNull
bool isNull() const
returns whether the wrapped resource is a null resource
Definition resourcewrapper.cpp:70
Syndication::RDF::ResourceWrapper::operator==
bool operator==(const ResourceWrapper &other) const
compares two resource wrapper instances.
Definition resourcewrapper.cpp:65
Syndication::RDF::ResourceWrapper::resource
ResourcePtr resource() const
returns the wrapped resource.
Definition resourcewrapper.cpp:75
Syndication::RDF::Resource
Resources are the entities in the RDF graph.
Definition resource.h:52
Syndication::RDF::Resource::uri
virtual QString uri() const
returns the URI of the resource
Definition resource.cpp:217
Syndication::RDF::Sequence
Sequence container, a sequence contains an ordered list of RDF nodes.
Definition sequence.h:46
Syndication::RDF::Sequence::items
virtual QList< NodePtr > items() const
the list of the list items in the sequence, in the specified order
Definition sequence.cpp:82
Syndication::RDF::SyndicationInfo
Wrapper to access syndication information for a feed.
Definition syndicationinfo.h:45
Syndication::RDF::SyndicationInfo::debugInfo
QString debugInfo() const
description of the syndication information for debugging purposes
Definition syndicationinfo.cpp:71
Syndication::RDF::TextInput
"The textinput element affords a method for submitting form data to an arbitrary URL - usually locate...
Definition textinput.h:39
Syndication::RDF::TextInput::debugInfo
QString debugInfo() const
Returns a description of the text input for debugging purposes.
Definition textinput.cpp:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

syndication/rdf

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

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal