23 #include <QtCore/QByteArray>
24 #include <QtCore/QEventLoop>
25 #include <QtCore/QHash>
26 #include <QtCore/QPair>
27 #include <QtCore/QString>
28 #include <QtCore/QTextStream>
29 #include <QtCore/QUrl>
31 #include <Soprano/Model>
32 #include <Soprano/Global>
33 #include <Soprano/Parser>
34 #include <Soprano/PluginManager>
35 #include <Soprano/StatementIterator>
42 class Nepomuk2::GraphRetriever::Private
47 void get(
const QUrl&
url );
53 unsigned int m_idleCount;
54 unsigned int m_timeoutThreshold;
65 void Nepomuk2::GraphRetriever::Private::get(
const QUrl& url )
67 KIO::StoredTransferJob* job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
68 job->addMetaData(
"accept",
69 QString(
"%1;q=0.2, %2" )
70 .arg( Soprano::serializationMimeType( Soprano::SerializationRdfXml ) )
71 .arg( Soprano::serializationMimeType( Soprano::SerializationTrig ) ) );
72 job->addMetaData(
"Charsets",
"utf-8" );
74 connect( job, SIGNAL(result(
KJob*)),
75 q, SLOT(httpRequestFinished(
KJob*)));
81 d( new Private(this) )
112 Soprano::Model* result = Soprano::createModel();
113 Soprano::StatementIterator it = statements();
114 while ( it.next() ) {
115 result->addStatement( *it );
124 Soprano::RdfSerialization serialization = Soprano::SerializationRdfXml;
125 if ( d->m_data.contains( (
int )Soprano::SerializationTrig ) ) {
126 serialization = Soprano::SerializationTrig;
127 data = d->m_data[( int )Soprano::SerializationTrig];
130 serialization = Soprano::SerializationRdfXml;
131 data = d->m_data[( int )Soprano::SerializationRdfXml];
134 QTextStream stream( data );
135 if (
const Soprano::Parser* parser =
136 Soprano::PluginManager::instance()->discoverParserForSerialization( serialization ) ) {
137 return parser->parseStream( stream, d->url, serialization );
140 return Soprano::StatementIterator();
145 void Nepomuk2::GraphRetriever::httpRequestFinished(
KJob* job )
147 KIO::StoredTransferJob* tj =
static_cast<KIO::StoredTransferJob*
>( job );
152 QString mimetype = tj->mimetype();
153 Soprano::RdfSerialization serialization = Soprano::mimeTypeToSerialization( mimetype );
154 if ( serialization == Soprano::SerializationUser &&
155 mimetype.contains(
"xml", Qt::CaseInsensitive ) ) {
156 serialization = Soprano::SerializationRdfXml;
158 if ( serialization != Soprano::SerializationUser )
159 d->m_data[( int )serialization] = tj->data();
173 #include "graphretriever.moc"
GraphRetriever(QObject *parent=0)
Custom and default constructor.
Utility class for retrieving RDF graphs from Web locations.
Soprano::Model * model() const
Returns a new Soprano model constructed from the retrieved graph fragments.
~GraphRetriever()
Default destructor.
void start()
Adds a get request for the given URL.
void setUrl(const QUrl &url)
Soprano::StatementIterator statements() const
static GraphRetriever * retrieve(const QUrl &uri)