diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index c3a9f8892..1bf5ac571 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -54,10 +54,10 @@ QString FeedsModelFeed::typeToString(FeedsModelFeed::Type type) { return QObject::tr("ATOM 1.0"); case StandardRdf: - return QObject::tr("RDF 1.0"); + return QObject::tr("RDF"); case StandardRss0X: - return QObject::tr("RSS 0.90/0.91/0.92"); + return QObject::tr("RSS 0.91/0.92/0.93"); case StandardRss2X: default: diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp index c9ae5c45e..b200b858b 100755 --- a/src/core/feedsmodelstandardfeed.cpp +++ b/src/core/feedsmodelstandardfeed.cpp @@ -186,6 +186,10 @@ void FeedsModelStandardFeed::update() { messages = ParsingFactory::parseAsRSS20(formatted_feed_contents); break; + case FeedsModelFeed::StandardRdf: + messages = ParsingFactory::parseAsRDF(formatted_feed_contents); + break; + // TODO: Add support for other standard formats. default: diff --git a/src/core/parsingfactory.cpp b/src/core/parsingfactory.cpp index 0e5d28f71..d4e50efa1 100644 --- a/src/core/parsingfactory.cpp +++ b/src/core/parsingfactory.cpp @@ -14,6 +14,70 @@ QList ParsingFactory::parseAsATOM10(const QString &data) { return QList(); } +QList ParsingFactory::parseAsRDF(const QString &data) { + QList messages; + QDomDocument xml_file; + QDateTime current_time = QDateTime::currentDateTime(); + + xml_file.setContent(data, true); + + // Pull out all messages. + QDomNodeList messages_in_xml = xml_file.elementsByTagName("item"); + + for (int i = 0; i < messages_in_xml.size(); i++) { + QDomNode message_item = messages_in_xml.item(i); + Message new_message; + + // Deal with title and description. + QString elem_title = message_item.namedItem("title").toElement().text().simplified(); + QString elem_description = message_item.namedItem("description").toElement().text(); + + // Now we obtained maximum of informations for title & description. + if (elem_title.isEmpty()) { + if (elem_description.isEmpty()) { + // BOTH title and description are empty, skip this message. + continue; + } + else { + // Title is empty but description is not. + new_message.m_title = TextFactory::stripTags(elem_description.simplified()); + new_message.m_contents = elem_description; + } + } + else { + // Title is really not empty, description does not matter. + new_message.m_title = TextFactory::stripTags(elem_title); + new_message.m_contents = elem_description; + } + + + // Deal with link and author. + new_message.m_url = message_item.namedItem("link").toElement().text(); + new_message.m_author = message_item.namedItem("creator").toElement().text(); + + // Deal with creation date. + QString elem_updated = message_item.namedItem("date").toElement().text(); + + if (elem_updated.isEmpty()) { + elem_updated = message_item.namedItem("dc:date").toElement().text(); + } + + // Deal with creation date. + new_message.m_created = TextFactory::parseDateTime(elem_updated); + new_message.m_createdFromFeed = !new_message.m_created.isNull(); + + if (!new_message.m_createdFromFeed) { + // Date was NOT obtained from the feed, + // set current date as creation date for the message. + new_message.m_created = current_time; + } + + messages.append(new_message); + } + + return messages; +} + QList ParsingFactory::parseAsRSS20(const QString &data) { QList messages; QDomDocument xml_file; @@ -44,21 +108,14 @@ QList ParsingFactory::parseAsRSS20(const QString &data) { } else { // Title is empty but description is not. - new_message.m_title = TextFactory::stripTags(elem_description); + new_message.m_title = TextFactory::stripTags(elem_description.simplified()); new_message.m_contents = elem_description; } } else { - if (elem_description.isEmpty()) { - // Title is not empty but description is empty. - new_message.m_title = TextFactory::stripTags(elem_title); - new_message.m_contents = QObject::tr("This message has not contents."); - } - else { - // Both description and title are not empty. - new_message.m_title = TextFactory::stripTags(elem_title); - new_message.m_contents = elem_description; - } + // Title is really not empty, description does not matter. + new_message.m_title = TextFactory::stripTags(elem_title); + new_message.m_contents = elem_description; } // Deal with link and author. diff --git a/src/core/parsingfactory.h b/src/core/parsingfactory.h index b1fc0ffce..c2a826ade 100644 --- a/src/core/parsingfactory.h +++ b/src/core/parsingfactory.h @@ -23,6 +23,7 @@ class ParsingFactory { // Parses input textual data into Message objects. // NOTE: Input is correctly encoded in Unicode. static QList parseAsATOM10(const QString &data); + static QList parseAsRDF(const QString &data); static QList parseAsRSS20(const QString &data); };