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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
  • xml
xmlreader.cpp
1 /*
2  Copyright (c) 2009 Volker Krause <vkrause@kde.org>
3  Copyright (c) 2009 Igor Trindade Oliveira <igor_trindade@yahoo.com.br>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "xmlreader.h"
22 #include "format_p.h"
23 
24 #include <akonadi/attributefactory.h>
25 #include <akonadi/tag.h>
26 
27 #include <QStringList>
28 
29 using namespace Akonadi;
30 
31 Attribute* XmlReader::elementToAttribute(const QDomElement& elem)
32 {
33  if ( elem.isNull() || elem.tagName() != Format::Tag::attribute() )
34  return 0;
35  Attribute *attr = AttributeFactory::createAttribute( elem.attribute( Format::Attr::attributeType() ).toUtf8() );
36  Q_ASSERT( attr );
37  attr->deserialize( elem.text().toUtf8() );
38  return attr;
39 }
40 
41 void XmlReader::readAttributes(const QDomElement& elem, Entity& entity)
42 {
43  if ( elem.isNull() )
44  return;
45  const QDomNodeList children = elem.childNodes();
46  for ( int i = 0; i < children.count(); ++i ) {
47  const QDomElement attrElem = children.at( i ).toElement();
48  Attribute *attr = elementToAttribute( attrElem );
49  if ( attr )
50  entity.addAttribute( attr );
51  }
52 }
53 
54 Collection XmlReader::elementToCollection(const QDomElement& elem)
55 {
56  if ( elem.isNull() || elem.tagName() != Format::Tag::collection() )
57  return Collection();
58 
59  Collection c;
60  c.setRemoteId( elem.attribute( Format::Attr::remoteId() ) );
61  c.setName( elem.attribute( Format::Attr::collectionName() ) );
62  c.setContentMimeTypes( elem.attribute( Format::Attr::collectionContentTypes() ).split( QLatin1Char(',') ) );
63  XmlReader::readAttributes( elem, c );
64 
65  const QDomElement parentElem = elem.parentNode().toElement();
66  if ( !parentElem.isNull() && parentElem.tagName() == Format::Tag::collection() )
67  c.parentCollection().setRemoteId( parentElem.attribute( Format::Attr::remoteId() ) );
68 
69  return c;
70 }
71 
72 Collection::List XmlReader::readCollections(const QDomElement& elem)
73 {
74  Collection::List rv;
75  if ( elem.isNull() )
76  return rv;
77  if ( elem.tagName() == Format::Tag::collection() )
78  rv += elementToCollection( elem );
79  const QDomNodeList children = elem.childNodes();
80  for ( int i = 0; i < children.count(); i++ ) {
81  const QDomElement child = children.at( i ).toElement();
82  if ( child.isNull() || child.tagName() != Format::Tag::collection() )
83  continue;
84  rv += readCollections( child );
85  }
86  return rv;
87 }
88 
89 Tag XmlReader::elementToTag(const QDomElement& elem)
90 {
91  if ( elem.isNull() || elem.tagName() != Format::Tag::tag() )
92  return Tag();
93 
94  Tag t;
95  t.setRemoteId( elem.attribute( Format::Attr::remoteId() ).toUtf8() );
96  t.setName( elem.attribute( Format::Attr::name() ) );
97  t.setGid( elem.attribute( Format::Attr::gid() ).toUtf8() );
98  t.setType( elem.attribute( Format::Attr::type() ).toUtf8() );
99 
100  //TODO Implement rid parent support in TagCreateJob first
101  // const QDomElement parentElem = elem.parentNode().toElement();
102  // if ( !parentElem.isNull() && parentElem.tagName() == Format::Tag::tag() ) {
103  // Tag parent;
104  // parent.setRemoteId( parentElem.attribute( Format::Attr::remoteId() ).toLatin1() );
105  // t.setParent( parent );
106  // }
107 
108  return t;
109 }
110 
111 Tag::List XmlReader::readTags(const QDomElement& elem)
112 {
113  Tag::List rv;
114  if ( elem.isNull() )
115  return rv;
116  if ( elem.tagName() == Format::Tag::tag() )
117  rv += elementToTag( elem );
118  const QDomNodeList children = elem.childNodes();
119  for ( int i = 0; i < children.count(); i++ ) {
120  const QDomElement child = children.at( i ).toElement();
121  if ( child.isNull() || child.tagName() != Format::Tag::tag() )
122  continue;
123  rv += readTags( child );
124  }
125  return rv;
126 }
127 
128 Item XmlReader::elementToItem(const QDomElement& elem, bool includePayload)
129 {
130  Item item( elem.attribute( Format::Attr::itemMimeType(), QLatin1String("application/octet-stream") ) );
131  item.setRemoteId( elem.attribute( Format::Attr::remoteId() ) );
132  XmlReader::readAttributes( elem, item );
133 
134  const QDomNodeList children = elem.childNodes();
135  for ( int i = 0; i < children.count(); ++i ) {
136  const QDomElement subElem = children.at( i ).toElement();
137  if ( subElem.isNull() )
138  continue;
139  if ( subElem.tagName() == Format::Tag::flag() ) {
140  item.setFlag( subElem.text().toUtf8() );
141  } else if ( subElem.tagName() == Format::Tag::tag() ) {
142  Tag tag;
143  tag.setRemoteId( subElem.text().toUtf8() );
144  item.setTag( tag );
145  } else if ( includePayload && subElem.tagName() == Format::Tag::payload() ) {
146  const QByteArray payloadData = subElem.text().toUtf8();
147  item.setPayloadFromData( payloadData );
148  }
149  }
150 
151  return item;
152 }
Akonadi::XmlReader::elementToItem
AKONADI_XML_EXPORT Item elementToItem(const QDomElement &elem, bool includePayload=true)
Converts an item element.
Definition: xmlreader.cpp:128
Akonadi::XmlReader::readAttributes
AKONADI_XML_EXPORT void readAttributes(const QDomElement &elem, Entity &entity)
Reads all attributes that are immediate children of elem and adds them to entity. ...
Definition: xmlreader.cpp:41
QByteArray
QDomElement::attribute
QString attribute(const QString &name, const QString &defValue) const
Akonadi::XmlReader::readCollections
AKONADI_XML_EXPORT Collection::List readCollections(const QDomElement &elem)
Reads recursively all collections starting from the given DOM element.
Definition: xmlreader.cpp:72
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QDomNodeList
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::XmlReader::elementToCollection
AKONADI_XML_EXPORT Collection elementToCollection(const QDomElement &elem)
Converts a collection element.
Definition: xmlreader.cpp:54
Akonadi::Entity::setRemoteId
void setRemoteId(const QString &id)
Sets the remote id of the entity.
Definition: entity.cpp:77
Akonadi::Attribute::deserialize
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
QDomNode::childNodes
QDomNodeList childNodes() const
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:93
QDomNode::toElement
QDomElement toElement() const
QDomNodeList::count
int count() const
QDomElement::text
QString text() const
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:185
Akonadi::Entity::addAttribute
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
Definition: entity.cpp:127
QList
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:59
QLatin1Char
QDomNode::isNull
bool isNull() const
Akonadi::AttributeFactory::createAttribute
static Attribute * createAttribute(const QByteArray &type)
Creates an entity attribute object of the given type.
Definition: attributefactory.cpp:147
QLatin1String
QDomNode::parentNode
QDomNode parentNode() const
Akonadi::XmlReader::elementToAttribute
AKONADI_XML_EXPORT Attribute * elementToAttribute(const QDomElement &elem)
Converts an attribute element.
Definition: xmlreader.cpp:31
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:43
QDomElement::tagName
QString tagName() const
Akonadi::XmlReader::readTags
AKONADI_XML_EXPORT Tag::List readTags(const QDomElement &elem)
Reads recursively all tags starting from the given DOM element.
Definition: xmlreader.cpp:111
QDomElement
Akonadi::Collection::setContentMimeTypes
void setContentMimeTypes(const QStringList &types)
Sets the list of possible content mime types.
Definition: collection.cpp:120
Akonadi::XmlReader::elementToTag
AKONADI_XML_EXPORT Tag elementToTag(const QDomElement &elem)
Converts a tag element.
Definition: xmlreader.cpp:89
QDomNodeList::at
QDomNode at(int index) const
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • 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