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

Syndication Library

  • syndication
documentsource.cpp
1/*
2 * This file is part of the syndication library
3 *
4 * Copyright (C) 2005 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 "documentsource.h"
24#include "tools.h"
25
26#include <QtCore/QByteArray>
27#include <QtXml/QDomDocument>
28#include <QtXml/QXmlSimpleReader>
29
30namespace Syndication {
31
32class DocumentSource::DocumentSourcePrivate
33{
34 public:
35 QByteArray array;
36 QString url;
37 mutable QDomDocument domDoc;
38 mutable bool parsed;
39 mutable unsigned int hash;
40 mutable bool calculatedHash;
41};
42
43DocumentSource::DocumentSource() : d(new DocumentSourcePrivate)
44{
45 d->parsed = true;
46 d->calculatedHash = true;
47 d->hash = 0;
48}
49
50
51DocumentSource::DocumentSource(const QByteArray& source, const QString& url) : d(new DocumentSourcePrivate)
52{
53 d->array = source;
54 d->url = url;
55 d->calculatedHash = false;
56 d->parsed = false;
57}
58
59DocumentSource::DocumentSource(const DocumentSource& other) : d()
60{
61 *this = other;
62}
63
64DocumentSource::~DocumentSource()
65{
66}
67
68DocumentSource& DocumentSource::operator=(const DocumentSource& other)
69{
70 d = other.d;
71 return *this;
72}
73
74QByteArray DocumentSource::asByteArray() const
75{
76 return d->array;
77}
78
79QDomDocument DocumentSource::asDomDocument() const
80{
81 if (!d->parsed)
82 {
83 QXmlInputSource source;
84 source.setData(d->array);
85
86 QXmlSimpleReader reader;
87 reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), true);
88
89 if (!d->domDoc.setContent(&source, &reader))
90 d->domDoc.clear();
91
92 d->parsed = true;
93 }
94
95 return d->domDoc;
96}
97
98unsigned int DocumentSource::size() const
99{
100 return d->array.size();
101}
102
103unsigned int DocumentSource::hash() const
104{
105 if (!d->calculatedHash)
106 {
107 d->hash = calcHash(d->array);
108 d->calculatedHash = true;
109 }
110
111 return d->hash;
112}
113
114QString DocumentSource::url() const
115{
116 return d->url;
117}
118
119} // namespace Syndication
Syndication::DocumentSource
Represents the source of a syndication document, as read from the downloaded file.
Definition: documentsource.h:51
Syndication::DocumentSource::asByteArray
QByteArray asByteArray() const
Returns the feed source as byte array.
Definition: documentsource.cpp:74
Syndication::DocumentSource::asDomDocument
QDomDocument asDomDocument() const
Returns the feed source as DOM document.
Definition: documentsource.cpp:79
Syndication::DocumentSource::url
QString url() const
returns the URL the document source was loaded from
Definition: documentsource.cpp:114
Syndication::DocumentSource::DocumentSource
DocumentSource()
Creates an empty document source.
Definition: documentsource.cpp:43
Syndication::DocumentSource::hash
unsigned int hash() const
calculates a hash value for the source array.
Definition: documentsource.cpp:103
Syndication::DocumentSource::~DocumentSource
~DocumentSource()
destructor
Definition: documentsource.cpp:64
Syndication::DocumentSource::size
unsigned int size() const
returns the size the source array in bytes.
Definition: documentsource.cpp:98
Syndication::DocumentSource::operator=
DocumentSource & operator=(const DocumentSource &other)
Assignment operator.
Definition: documentsource.cpp:68
Syndication
TODO.
Definition: abstractparser.cpp:25
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Syndication Library

Skip menu "Syndication Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

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