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

Syndication Library

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
30 namespace Syndication {
31 
32 class 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 
43 DocumentSource::DocumentSource() : d(new DocumentSourcePrivate)
44 {
45  d->parsed = true;
46  d->calculatedHash = true;
47  d->hash = 0;
48 }
49 
50 
51 DocumentSource::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 
59 DocumentSource::DocumentSource(const DocumentSource& other) : d()
60 {
61  *this = other;
62 }
63 
64 DocumentSource::~DocumentSource()
65 {
66 }
67 
68 DocumentSource& DocumentSource::operator=(const DocumentSource& other)
69 {
70  d = other.d;
71  return *this;
72 }
73 
74 QByteArray DocumentSource::asByteArray() const
75 {
76  return d->array;
77 }
78 
79 QDomDocument 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 
98 unsigned int DocumentSource::size() const
99 {
100  return d->array.size();
101 }
102 
103 unsigned 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 
114 QString DocumentSource::url() const
115 {
116  return d->url;
117 }
118 
119 } // namespace Syndication
QXmlSimpleReader
Syndication::DocumentSource::asByteArray
QByteArray asByteArray() const
Returns the feed source as byte array.
Definition: documentsource.cpp:74
QByteArray
QXmlInputSource::setData
virtual void setData(const QString &dat)
Syndication::DocumentSource::asDomDocument
QDomDocument asDomDocument() const
Returns the feed source as DOM document.
Definition: documentsource.cpp:79
Syndication::DocumentSource::DocumentSource
DocumentSource()
Creates an empty document source.
Definition: documentsource.cpp:43
Syndication::DocumentSource
Represents the source of a syndication document, as read from the downloaded file.
Definition: documentsource.h:50
Syndication::DocumentSource::hash
unsigned int hash() const
calculates a hash value for the source array.
Definition: documentsource.cpp:103
QXmlSimpleReader::setFeature
virtual void setFeature(const QString &name, bool enable)
QString
Syndication::DocumentSource::~DocumentSource
~DocumentSource()
destructor
Definition: documentsource.cpp:64
QDomDocument
Syndication::DocumentSource::url
QString url() const
returns the URL the document source was loaded from
Definition: documentsource.cpp:114
Syndication::DocumentSource::size
unsigned int size() const
returns the size the source array in bytes.
Definition: documentsource.cpp:98
QXmlInputSource
QLatin1String
Syndication::DocumentSource::operator=
DocumentSource & operator=(const DocumentSource &other)
Assignment operator.
Definition: documentsource.cpp:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:32 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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