2 * Copyright (c) 2010 Mani Chandrasekar <maninc@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "googledocumentlist.h"
22 #include "googledocument.h"
23 #include "googlecontenthandler.h"
25 GoogleContentHandler::GoogleContentHandler()
29 m_docList = new GoogleDocumentList();
32 bool GoogleContentHandler::characters ( const QString & ch )
35 if (QString::compare(m_nodeStack.top(), "title", Qt::CaseInsensitive) == 0) {
36 if (m_nodeStack.count() == 2)
37 m_docList->setTitle(ch);
39 else if (QString::compare(m_nodeStack.top(), "name", Qt::CaseInsensitive) == 0) {
40 if (m_nodeStack.count() == 3)
41 m_docList->setAuthor(ch);
43 else if (QString::compare(m_nodeStack.top(), "email", Qt::CaseInsensitive) == 0) {
44 if (m_nodeStack.count() == 3)
45 m_docList->setEmail(ch);
53 if (QString::compare(m_nodeStack.top(), "title", Qt::CaseInsensitive) == 0) {
54 m_docEntry->setTitle(ch);
56 else if (QString::compare(m_nodeStack.top(), "name", Qt::CaseInsensitive) == 0) {
57 m_docEntry->setAuthor(ch);
59 else if (QString::compare(m_nodeStack.top(), "resourceId", Qt::CaseInsensitive) == 0) {
60 m_docEntry->setId(ch);
66 bool GoogleContentHandler::endDocument ()
68 //qDebug() << "GoogleContentHandler::endDocument()";
72 bool GoogleContentHandler::endElement ( const QString & namespaceURI, const QString & localName, const QString & qName )
74 //printName(localName);
75 QString element = m_nodeStack.pop();
76 if (QString::compare(element, "entry") == 0) {
78 m_docList->append(m_docEntry);
84 bool GoogleContentHandler::endPrefixMapping ( const QString & prefix )
89 QString GoogleContentHandler::errorString () const
94 bool GoogleContentHandler::ignorableWhitespace ( const QString & ch )
99 bool GoogleContentHandler::processingInstruction ( const QString & target, const QString & data )
104 void GoogleContentHandler::setDocumentLocator ( QXmlLocator * locator )
108 bool GoogleContentHandler::skippedEntity ( const QString & name )
113 bool GoogleContentHandler::startDocument ()
118 bool GoogleContentHandler::startElement ( const QString & namespaceURI, const QString & localName,
119 const QString & qName, const QXmlAttributes & atts )
121 m_nodeStack.push(localName);
123 if ((m_nodeStack.count() == 1) && (m_docList != 0)) { //Feed element
124 m_docList->setEtag(atts.value("gd:etag"));
127 if (QString::compare(localName, "entry", Qt::CaseInsensitive) == 0 ) {
128 m_docEntry = new GoogleDocument();
129 m_docEntry->setEtag(atts.value("gd:etag"));
132 if ( insideEntry && (QString::compare(localName, "content", Qt::CaseInsensitive) == 0 ) && (m_docEntry != 0)) {
133 m_docEntry->setDocumentUrl(atts.value("src"));
136 //printName(localName);
141 bool GoogleContentHandler::startPrefixMapping ( const QString & prefix, const QString & uri )
143 //qDebug() << "GoogleContentHandler::startPrefixMapping() " << prefix << uri;
147 void GoogleContentHandler::printName(const QString & name)
149 int count = m_nodeStack.count();
151 for (int i=0; i < count; i++)
156 // qDebug() << indent;