Syndication

documentsource.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "documentsource.h"
9#include "tools.h"
10
11#include <QByteArray>
12#include <QDebug>
13#include <QDomDocument>
14
15namespace Syndication
16{
17class SYNDICATION_NO_EXPORT DocumentSource::DocumentSourcePrivate
18{
19public:
20 QByteArray array;
21 QString url;
22 mutable QDomDocument domDoc;
23 mutable bool parsed;
24 mutable unsigned int hash;
25 mutable bool calculatedHash;
26};
27
29 : d(new DocumentSourcePrivate)
30{
31 d->parsed = true;
32 d->calculatedHash = true;
33 d->hash = 0;
34}
35
37 : d(new DocumentSourcePrivate)
38{
39 d->array = source;
40 d->url = url;
41 d->calculatedHash = false;
42 d->parsed = false;
43}
44
46 : d()
47{
48 *this = other;
49}
50
54
56{
57 d = other.d;
58 return *this;
59}
60
62{
63 return d->array;
64}
65
67{
68 if (!d->parsed) {
69 const auto result = d->domDoc.setContent(d->array, QDomDocument::ParseOption::UseNamespaceProcessing);
70 if (!result) {
71 qWarning() << result.errorMessage << "on line" << result.errorLine;
72 d->domDoc.clear();
73 }
74
75 d->parsed = true;
76 }
77
78 return d->domDoc;
79}
80
81unsigned int DocumentSource::size() const
82{
83 return d->array.size();
84}
85
86unsigned int DocumentSource::hash() const
87{
88 if (!d->calculatedHash) {
89 d->hash = calcHash(d->array);
90 d->calculatedHash = true;
91 }
92
93 return d->hash;
94}
95
97{
98 return d->url;
99}
100
101} // namespace Syndication
Represents the source of a syndication document, as read from the downloaded file.
QByteArray asByteArray() const
Returns the feed source as byte array.
QDomDocument asDomDocument() const
Returns the feed source as DOM document.
QString url() const
returns the URL the document source was loaded from
DocumentSource()
Creates an empty document source.
unsigned int hash() const
calculates a hash value for the source array.
unsigned int size() const
returns the size the source array in bytes.
DocumentSource & operator=(const DocumentSource &other)
Assignment operator.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.