Git commit 503d2e94d8fdd357bf723441035d4b0c49a20ec4 by Frank Osterfeld. Committed on 27/03/2012 at 20:11. Pushed by osterfeld into branch 'master'. In proper RSS 1.0, the items in the feed must be listed in the "items" sequ= ence, with the same URIs used in the item descriptions afterwards. If the U= RIs don't match, the sequence and items are not linked in the RDF, thus no item descr= iptions are found. This is a common error RDF feeds out there and W3C's feed validator doesn'= t complain. Nobody groks RDF anyway, so don't rely on matching URIs. Instead, just igno= re and get all item resources by type as they occur in the feed. BUG:295354 M +52 -22 syndication/rdf/document.cpp M +6 -0 syndication/rdf/parser.cpp A +102 -0 syndication/tests/rdf/javaworld.xml A +86 -0 syndication/tests/rdf/javaworld.xml.expected M +2 -2 syndication/tests/rdf/tagesschau.de.xml http://commits.kde.org/kdepimlibs/503d2e94d8fdd357bf723441035d4b0c49a20ec4 diff --git a/syndication/rdf/document.cpp b/syndication/rdf/document.cpp index e336955..997e3c9 100644 --- a/syndication/rdf/document.cpp +++ b/syndication/rdf/document.cpp @@ -38,6 +38,8 @@ = #include #include +#include +#include = using namespace boost; = @@ -138,37 +140,65 @@ SyndicationInfo Document::syn() const return SyndicationInfo(resource()); } = + +struct SortItem { + Item item; + int index; +}; + +struct LessThanByIndex { + bool operator()(const SortItem& lhs, const SortItem& rhs) const { + return lhs.index < rhs.index; + } +}; + +static QList sortListToMatchSequence(QList items, const QStrin= gList& uriSequence) { + QVector toSort; + toSort.reserve(items.size()); + Q_FOREACH(const Item& i, items) { + SortItem item; + item.item =3D i; + item.index =3D uriSequence.indexOf(i.resource()->uri()); + toSort.append(item); + } + qSort(toSort.begin(), toSort.end(), LessThanByIndex()); + + int i =3D 0; + Q_FOREACH(const SortItem& sortItem, toSort) { + items[i] =3D sortItem.item; + i++; + } + + return items; +} + QList Document::items() const { QList list; - if (!resource()->hasProperty(RSSVocab::self()->items())) - return list; = - NodePtr n =3D resource()->property(RSSVocab::self()->items())->object(= ); - if (n->isSequence()) - { - Sequence* seq =3D static_cast(n.get()); + const QList items =3D resource()->model().resourcesWithTy= pe(RSSVocab::self()->item()); + DocumentPtr doccpy(new Document(*this)); + Q_FOREACH (const ResourcePtr& i, items) + list.append(Item(i, doccpy)); = - const QList items =3D seq->items(); - QList::ConstIterator it =3D items.begin(); - QList::ConstIterator end =3D items.end(); + if (resource()->hasProperty(RSSVocab::self()->items())) { + NodePtr n =3D resource()->property(RSSVocab::self()->items())->obj= ect(); + if (n->isSequence()) + { + Sequence* seq =3D static_cast(n.get()); = - DocumentPtr doccpy(new Document(*this)); + const QList seqItems =3D seq->items(); = - for ( ; it !=3D end; ++it) - { - if ((*it)->isResource()) - { - // well, we need it as ResourcePtr - // maybe this should go to the node - // interface ResourcePtr asResource()? - ResourcePtr ptr =3D resource()->model().createResource((st= atic_cast((*it).get()))->uri()); - - list.append(Item(ptr, doccpy)); - } - } + QStringList uriSequence; + uriSequence.reserve(seqItems.size()); = + Q_FOREACH(const NodePtr& i, seqItems) + if (i->isResource()) + uriSequence.append(static_cast(i.get())->ur= i()); + list =3D sortListToMatchSequence(list, uriSequence); + } } + return list; } = diff --git a/syndication/rdf/parser.cpp b/syndication/rdf/parser.cpp index 12b4c1c..f675236 100644 --- a/syndication/rdf/parser.cpp +++ b/syndication/rdf/parser.cpp @@ -164,6 +164,8 @@ void Parser::ParserPrivate::map09to10(Model model) = void Parser::ParserPrivate::addSequenceFor09(Model model) { + //RDF 0.9 doesn't contain an item sequence, and the items don't have r= df:about, so add both + const QList items =3D model.resourcesWithType(RSS09Vocab:= :self()->item()); = if (items.isEmpty()) @@ -196,6 +198,10 @@ void Parser::ParserPrivate::addSequenceFor09(Model mod= el) foreach (const ResourcePtr &i, sorted) { seq->append(i); + // add rdf:about (type) + model.addStatement(i, RDFVocab::self()->type(), RSSVocab::self()->= item()); + + //add to items sequence model.addStatement(seq, RDFVocab::self()->li(), i); } } diff --git a/syndication/tests/rdf/javaworld.xml b/syndication/tests/rdf/ja= vaworld.xml new file mode 100644 index 0000000..dbbc6b0 --- /dev/null +++ b/syndication/tests/rdf/javaworld.xml @@ -0,0 +1,102 @@ + + + + + + + + Featured Articles + http://www.javaworld.com/features/index.html + JW RSS feed for Featured Articles + Javaworld + Copyright(C) 1994 - 2012 Javaworld + + + + + + + + + + + + + + + + + Electric Cloud CEO: We automate agile development + http://www.javaworld.com/javaworld/jw-02-2012/120228-modernizin= g-it.html + An explosion of tools and platforms is making app dev mu= ch more complex. Mike Maciag, CEO of Electric Cloud, offers cross-platform = workflow and automation to rationalize it all. + + 2012-02-28T00:00:00Z + + + Stroustrup reveals what's new in C++ 11 + http://www.javaworld.com/javaworld/jw-02-2012/120224-bjarne-str= oustrup-interview.html + Latest version of language isn't a major overhaul, = but offers many small upgrades to appeal to different areas of development.= + + 2012-02-24T00:00:00Z + + + Node.js tools: Server-side JavaScript comes of age + http://www.javaworld.com/javaworld/jw-02-2012/120222-node-js-to= ols-remake-server-side.html + Node's ecosystem is growing at an exponential rate,= which is only natural when you start from scratch. Still, the plethora of = Node-inspired tools amount to a diverse and sustainable infrastructure, whi= ch could ultimatey redefine the web development stack. + + 2012-02-22T00:00:00Z + + + Google Chrome, HTML5, and the new Web platform + http://www.javaworld.com/javaworld/jw-02-2012/120216-fatal-exce= ption.html + The Chrome dev team is working toward a vision of Web ap= ps that offers a clean break from traditional websites. + + 2012-02-16T00:00:00Z + + + Java tip: Set up an RSS feed for your Android application</tit= le> + <link>http://www.javaworld.com/javaworld/jw-02-2012/120214-jtip-rss-f= or-android.html</link> + <description>Get a hands-on introduction to using <code>javax.x= ml.parsers.SAXParser</code> to parse an RSS feed in XML format. While= some familiarity with Java application development is assumed, this Java t= ip is suitable for developers new to Java mobile development.</description> + <dc:creator/> + <dc:date>2012-02-14T00:00:00Z</dc:date> + </item> + <item rdf:about=3D"http://www.javaworld.com//javaworld/jw-02-2012/1= 20208-mongodb-review.html"> + <title>Flexing NoSQL: MongoDB in review + http://www.javaworld.com/javaworld/jw-02-2012/120208-mongodb-re= view.html + MongoDB shines with broad programming language support, = SQL-like queries, and out-of-the-box scaling. Check the InfoWorld Review sc= ore card to see how MongoDB stacks up among NoSQL data stores. + + 2012-02-08T00:00:00Z + + + Programmer personality types: 13 profiles in code + http://www.javaworld.com/javaworld/jw-02-2012/120206-programmer= -personality-types.html + From Underdocumenters to flat-out Fakers, the world of s= oftware development is full of characters. Here, InfoWorld's Peter Way= ner offers 13 developer personality profiles based on coding style. + + 2012-02-06T00:00:00Z + + + Develop an environment-aware Maven build process + http://www.javaworld.com/javaworld/jw-02-2012/120202-environmen= t-aware-maven-build.html + Including environment variables in your Maven build proc= ess could boost your team's efficiency at every stage of the software= development lifecycle. Java developer Paul Spinelli demonstrates his custo= m approach to environment-aware Maven builds. + + 2012-02-02T00:00:00Z + + + Programming Opa: Web development, reimagined + http://www.javaworld.com/javaworld/jw-02-2012/120201-opa-progra= mming.html + MLstate's Opa streamlines Web app development with = a single language for client and server, but the bright promise is not with= out pitfalls. + + 2012-02-01T00:00:00Z + + + Here's how to solve America's developer shortage</ti= tle> + <link>http://www.javaworld.com/javaworld/jw-01-2012/120126-fatal-exce= ption.html</link> + <description>Employers say they can't find enough workers to sta= ff IT jobs. Maybe they've been going about it all wrong.</description> + <dc:creator/> + <dc:date>2012-01-26T00:00:00Z</dc:date> + </item> + </rdf:RDF> diff --git a/syndication/tests/rdf/javaworld.xml.expected b/syndication/tes= ts/rdf/javaworld.xml.expected new file mode 100644 index 0000000..5d3e0aa --- /dev/null +++ b/syndication/tests/rdf/javaworld.xml.expected @@ -0,0 +1,86 @@ +# Feed begin ###################### +title: #Featured Articles# +link: #http://www.javaworld.com/features/index.html# +description: #JW RSS feed for Featured Articles# +copyright: #Copyright(C) 1994 - 2012 Javaworld# +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120201-opa-programming= .html# +title: #Programming Opa: Web development, reimagined# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120201-opa-programmin= g.html# +description: #MLstate's Opa streamlines Web app development with a single = language for client and server, but the bright promise is not without pitfa= lls.# +datePublished: #Wed Feb 1 01:00:00 2012# +dateUpdated: #Wed Feb 1 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120222-node-js-tools-r= emake-server-side.html# +title: #Node.js tools: Server-side JavaScript comes of age# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120222-node-js-tools-= remake-server-side.html# +description: #Node's ecosystem is growing at an exponential rate, which is= only natural when you start from scratch. Still, the plethora of Node-insp= ired tools amount to a diverse and sustainable infrastructure, which could = ultimatey redefine the web development stack.# +datePublished: #Wed Feb 22 01:00:00 2012# +dateUpdated: #Wed Feb 22 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120216-fatal-exception= .html# +title: #Google Chrome, HTML5, and the new Web platform# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120216-fatal-exceptio= n.html# +description: #The Chrome dev team is working toward a vision of Web apps t= hat offers a clean break from traditional websites.# +datePublished: #Thu Feb 16 01:00:00 2012# +dateUpdated: #Thu Feb 16 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120208-mongodb-review.= html# +title: #Flexing NoSQL: MongoDB in review# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120208-mongodb-review= .html# +description: #MongoDB shines with broad programming language support, SQL-= like queries, and out-of-the-box scaling. Check the InfoWorld Review score = card to see how MongoDB stacks up among NoSQL data stores.# +datePublished: #Wed Feb 8 01:00:00 2012# +dateUpdated: #Wed Feb 8 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120224-bjarne-stroustr= up-interview.html# +title: #Stroustrup reveals what's new in C++ 11# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120224-bjarne-stroust= rup-interview.html# +description: #Latest version of language isn't a major overhaul, but offer= s many small upgrades to appeal to different areas of development.# +datePublished: #Fri Feb 24 01:00:00 2012# +dateUpdated: #Fri Feb 24 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120206-programmer-pers= onality-types.html# +title: #Programmer personality types: 13 profiles in code# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120206-programmer-per= sonality-types.html# +description: #From Underdocumenters to flat-out Fakers, the world of softw= are development is full of characters. Here, InfoWorld's Peter Wayner offer= s 13 developer personality profiles based on coding style.# +datePublished: #Mon Feb 6 01:00:00 2012# +dateUpdated: #Mon Feb 6 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120202-environment-awa= re-maven-build.html# +title: #Develop an environment-aware Maven build process# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120202-environment-aw= are-maven-build.html# +description: #Including environment variables in your Maven build process = could boost your team's efficiency at every stage of the software developm= ent lifecycle. Java developer Paul Spinelli demonstrates his custom approac= h to environment-aware Maven builds.# +datePublished: #Thu Feb 2 01:00:00 2012# +dateUpdated: #Thu Feb 2 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120228-modernizing-it.= html# +title: #Electric Cloud CEO: We automate agile development# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120228-modernizing-it= .html# +description: #An explosion of tools and platforms is making app dev much m= ore complex. Mike Maciag, CEO of Electric Cloud, offers cross-platform work= flow and automation to rationalize it all.# +datePublished: #Tue Feb 28 01:00:00 2012# +dateUpdated: #Tue Feb 28 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-02-2012/120214-jtip-rss-for-an= droid.html# +title: #Java tip: Set up an RSS feed for your Android application# +link: #http://www.javaworld.com/javaworld/jw-02-2012/120214-jtip-rss-for-a= ndroid.html# +description: #Get a hands-on introduction to using <code>javax.xml.parsers= .SAXParser</code> to parse an RSS feed in XML format. While some familiarit= y with Java application development is assumed, this Java tip is suitable f= or developers new to Java mobile development.# +datePublished: #Tue Feb 14 01:00:00 2012# +dateUpdated: #Tue Feb 14 01:00:00 2012# +# Item end ######################## +# Item begin ###################### +id: #http://www.javaworld.com//javaworld/jw-01-2012/120126-fatal-exception= .html# +title: #Here's how to solve America's developer shortage# +link: #http://www.javaworld.com/javaworld/jw-01-2012/120126-fatal-exceptio= n.html# +description: #Employers say they can't find enough workers to staff IT job= s. Maybe they've been going about it all wrong.# +datePublished: #Thu Jan 26 01:00:00 2012# +dateUpdated: #Thu Jan 26 01:00:00 2012# +# Item end ######################## +# Feed end ######################## diff --git a/syndication/tests/rdf/tagesschau.de.xml b/syndication/tests/rd= f/tagesschau.de.xml index 27b9ea1..fbf6906 100644 --- a/syndication/tests/rdf/tagesschau.de.xml +++ b/syndication/tests/rdf/tagesschau.de.xml @@ -1,7 +1,7 @@ <?xml version=3D"1.0" encoding=3D"ISO-8859-1"?><rdf:RDF xmlns:rdf=3D"http:= //www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns=3D"http://my.netscape.com/rdf= /simple/0.9/"> <!-- Source: www.tagesschau.de Properties: - - no-thrills RDF 1.0 feed + - no-thrills RDF 0.9 feed - unescaped quotes in text --> <!-- @@ -41,4 +41,4 @@ = = = -</rdf:RDF> \ No newline at end of file +</rdf:RDF>