• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

Syndication Library

documentsource.cpp

00001 /*
00002  * This file is part of the syndication library
00003  *
00004  * Copyright (C) 2005 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 "documentsource.h"
00024 #include "tools.h"
00025 
00026 #include <QtCore/QByteArray>
00027 #include <QtXml/QDomDocument>
00028 #include <QtXml/QXmlSimpleReader>
00029 
00030 namespace Syndication {
00031 
00032 class DocumentSource::DocumentSourcePrivate
00033 {
00034     public:
00035     QByteArray array;
00036     QString url;
00037     mutable QDomDocument domDoc;
00038     mutable bool parsed;
00039     mutable unsigned int hash;
00040     mutable bool calculatedHash;
00041 };
00042 
00043 DocumentSource::DocumentSource() : d(new DocumentSourcePrivate)
00044 {
00045     d->parsed = true;
00046     d->calculatedHash = true;
00047     d->hash = 0;
00048 }
00049 
00050 
00051 DocumentSource::DocumentSource(const QByteArray& source, const QString& url) : d(new DocumentSourcePrivate)
00052 {
00053     d->array = source;
00054     d->url = url;
00055     d->calculatedHash = false;
00056     d->parsed = false;
00057 }
00058 
00059 DocumentSource::DocumentSource(const DocumentSource& other) : d()
00060 {
00061      *this = other;
00062 }
00063 
00064 DocumentSource::~DocumentSource()
00065 {
00066 }
00067 
00068 DocumentSource& DocumentSource::operator=(const DocumentSource& other)
00069 {
00070     d = other.d;
00071     return *this;
00072 }
00073 
00074 QByteArray DocumentSource::asByteArray() const
00075 {
00076     return d->array;
00077 }
00078 
00079 QDomDocument DocumentSource::asDomDocument() const
00080 {
00081     if (!d->parsed)
00082     {
00083         QXmlInputSource source;
00084         source.setData(d->array);
00085         
00086         QXmlSimpleReader reader;
00087         reader.setFeature("http://xml.org/sax/features/namespaces", true);
00088         
00089         if (!d->domDoc.setContent(&source, &reader))
00090             d->domDoc.clear();
00091 
00092         d->parsed = true;
00093     }
00094 
00095     return d->domDoc;
00096 }
00097 
00098 unsigned int DocumentSource::size() const
00099 {
00100     return d->array.size();
00101 }
00102 
00103 unsigned int DocumentSource::hash() const
00104 {
00105     if (!d->calculatedHash)
00106     {
00107         d->hash = calcHash(d->array);
00108         d->calculatedHash = true;
00109     }
00110     
00111     return d->hash;
00112 }
00113 
00114 QString DocumentSource::url() const
00115 {
00116     return d->url;
00117 }
00118 
00119 } // namespace Syndication

Syndication Library

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
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