Magellan Linux

Annotation of /trunk/soprano/patches/soprano-2.6.51-git20110720.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1429 - (hide annotations) (download)
Wed Jul 20 20:32:12 2011 UTC (12 years, 11 months ago) by niro
File size: 54501 byte(s)
fixed patch
1 niro 1429 diff -Naur soprano-2.6.51/backends/redland/redlandqueryresult.cpp soprano/backends/redland/redlandqueryresult.cpp
2     --- soprano-2.6.51/backends/redland/redlandqueryresult.cpp 2011-06-05 10:38:25.000000000 +0200
3     +++ soprano/backends/redland/redlandqueryresult.cpp 2011-07-19 18:49:58.000000000 +0200
4     @@ -77,9 +77,10 @@
5 niro 1428 d->model = model;
6    
7     const char** names = 0;
8 niro 1429 + int number = librdf_query_results_get_bindings_count(d->result);
9 niro 1428 if ( !librdf_query_results_get_bindings( d->result, &names, 0 ) ) {
10 niro 1429 - for ( ; *names; names++ ) {
11     - d->names.append( QString::fromUtf8( *names ) );
12     + for ( int i = 0; i < number; i++ ) {
13     + d->names.append( QString::fromUtf8( names[i] ) );
14 niro 1428 }
15     }
16     }
17 niro 1429 diff -Naur soprano-2.6.51/ChangeLog soprano/ChangeLog
18     --- soprano-2.6.51/ChangeLog 2011-06-05 10:38:25.000000000 +0200
19     +++ soprano/ChangeLog 2011-07-19 18:49:58.000000000 +0200
20     @@ -2,6 +2,8 @@
21 niro 1428 * Use the new Virtuoso parameter XAnyNormalization to use normalized accents for full-text searching by default.
22     * Updated NAO Vocabulary namespace to include changes from SDO 0.7.
23     * Added method LiteralValue::fromVariant which provides some useful type conversions.
24 niro 1429 + * Fixed incorrect binding names counting in redland queries
25     + * Ported Raptor serializer and parser plugins to Raptor2.
26 niro 1428
27     2.6.1
28     * Let onto2vocabularyclass convert dots in entity names to underscores to create valid C++ names.
29 niro 1429 diff -Naur soprano-2.6.51/cmake/modules/FindRaptor.cmake soprano/cmake/modules/FindRaptor.cmake
30     --- soprano-2.6.51/cmake/modules/FindRaptor.cmake 2011-06-05 10:38:25.000000000 +0200
31     +++ soprano/cmake/modules/FindRaptor.cmake 2011-07-19 18:49:58.000000000 +0200
32     @@ -5,9 +5,13 @@
33 niro 1428 # RAPTOR_LIBRARIES - Link these to use Raptor
34     # RAPTOR_INCLUDE_DIR - Include directory for using Raptor
35     # RAPTOR_DEFINITIONS - Compiler switches required for using Raptor
36 niro 1429 -# RAPTOR_VERSION - The Raptor version string
37     +#
38     +# Capabilities
39     +# RAPTOR_HAVE_TRIG - Set if raptor has TRIG
40 niro 1428
41 niro 1429 -# (c) 2007-2009 Sebastian Trueg <trueg@kde.org>
42     +# (c) 2007-2011 Sebastian Trueg <trueg@kde.org>
43     +# (c) 2011 Artem Serebriyskiy <v.for.vandal@gmail.com>
44     +# (c) 2011 Michael Jansen <kde@michael-jansen.biz>
45 niro 1428 #
46     # Based on FindFontconfig Copyright (c) 2006,2007 Laurent Montel, <montel@kde.org>
47     #
48 niro 1429 @@ -15,89 +19,83 @@
49 niro 1428 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
50    
51    
52 niro 1429 -INCLUDE(MacroEnsureVersion)
53 niro 1428 -
54 niro 1429 +MACRO ( FIND_RAPTOR libname libhints includehints )
55     + find_library_with_debug(
56     + RAPTOR_LIBRARIES
57     + WIN32_DEBUG_POSTFIX d
58     + NAMES ${libname}
59     + HINTS ${libhints})
60     + find_path(
61     + RAPTOR_INCLUDE_DIR raptor.h
62     + HINTS ${includehints}
63     + PATH_SUFFIXES ${libname})
64     +ENDMACRO ()
65 niro 1428 +
66     +
67     +
68 niro 1429 +# Check if we have cached results in case the last round was successful.
69     +if ( NOT( RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES ) OR NOT RAPTOR_FOUND )
70 niro 1428 +
71 niro 1429 + include(FindLibraryWithDebug)
72     + include(MacroEnsureVersion)
73     + find_package(PkgConfig)
74 niro 1428 +
75 niro 1429 + # Vy default look for version 2.0
76     + if (NOT Raptor_FIND_VERSION )
77     + set( Raptor_FIND_VERSION "2.0")
78     + set( Raptor_FIND_VERSION_MAJOR "2" )
79     + set( Raptor_FIND_VERSION_MINOR "0" )
80     + endif ()
81 niro 1428 +
82 niro 1429 + if ( Raptor_FIND_VERSION_MAJOR EQUAL "2" )
83 niro 1428 +
84 niro 1429 + if ( NOT WIN32 )
85     + pkg_check_modules(PC_RAPTOR2 QUIET raptor2)
86     + if ( PC_RAPTOR2_FOUND )
87     + set(RAPTOR_DEFINITIONS ${PC_RAPTOR2_CFLAGS_OTHER})
88     + set(RAPTOR_VERSION ${PC_RAPTOR2_VERSION} CACHE STRING "Raptor Version found" )
89     + endif ()
90     + endif ()
91     + find_raptor( raptor2 "${PC_RAPTOR2_LIBDIR};${PC_RAPTOR2_LIBRARY_DIRS}" "${PC_RAPTOR2_INCLUDEDIR};${PC_RAPTOR2_INCLUDE_DIRS}")
92     +
93     + elseif ( Raptor_FIND_VERSION_MAJOR EQUAL "1" )
94     +
95     + if ( NOT WIN32 )
96     + pkg_check_modules(PC_RAPTOR QUIET raptor)
97     + if ( PC_RAPTOR_FOUND )
98     + set(RAPTOR_DEFINITIONS ${PC_RAPTOR_CFLAGS_OTHER})
99     + set(RAPTOR_VERSION ${PC_RAPTOR_VERSION} CACHE STRING "Raptor Version found" )
100     + endif ()
101     + endif ()
102     + find_raptor( raptor "${PC_RAPTOR_LIBDIR};${PC_RAPTOR_LIBRARY_DIRS}" "${PC_RAPTOR_INCLUDEDIR};${PC_RAPTOR_INCLUDE_DIRS}")
103     +
104     + else ()
105     +
106     + message( FATAL_ERROR "No idea how to check for version : ${Raptor_FIND_VERSION}")
107     +
108     + endif()
109     +
110     + if (RAPTOR_VERSION)
111     + MACRO_ENSURE_VERSION("1.4.16" ${RAPTOR_VERSION} RAPTOR_HAVE_TRIG)
112     + endif (RAPTOR_VERSION)
113     +
114     + mark_as_advanced(RAPTOR_INCLUDE_DIR RAPTOR_LIBRARIES)
115     +
116     +endif () # Check for cached values
117     +
118     +include(FindPackageHandleStandardArgs)
119     +
120     +find_package_handle_standard_args(
121     + Raptor
122     + VERSION_VAR RAPTOR_VERSION
123     + REQUIRED_VARS RAPTOR_LIBRARIES RAPTOR_INCLUDE_DIR)
124     +
125     +mark_as_advanced(RAPTOR_VERSION)
126     +
127     +if (NOT RAPTOR_FOUND AND Raptor_FIND_VERSION_MAJOR EQUAL "2" AND NOT Raptor_FIND_QUIET )
128     + pkg_check_modules(PC_RAPTOR QUIET raptor)
129     + if (PC_RAPTOR_FOUND)
130     + message( STATUS "You have raptor1 version ${PC_RAPTOR_VERSION} installed. Please update." )
131     + endif ()
132     +endif ()
133    
134     -if(WINCE)
135     -FIND_PROGRAM(
136     - RAPTOR_CONFIG
137     - NAMES raptor-config
138     - PATHS ${HOST_BINDIR} NO_DEFAULT_PATH
139     - )
140     -else(WINCE)
141     -FIND_PROGRAM(
142     - RAPTOR_CONFIG
143     - NAMES raptor-config
144     - )
145     -endif(WINCE)
146     -
147     -if(RAPTOR_CONFIG)
148     - EXECUTE_PROCESS(
149     - COMMAND ${RAPTOR_CONFIG} --version
150     - OUTPUT_VARIABLE RAPTOR_VERSION
151     - )
152     - if(RAPTOR_VERSION)
153     - STRING(REPLACE "\n" "" RAPTOR_VERSION ${RAPTOR_VERSION})
154     -
155     - MACRO_ENSURE_VERSION("1.4.16" ${RAPTOR_VERSION} RAPTOR_HAVE_TRIG)
156     -
157     - # extract include paths from raptor-config
158     - EXECUTE_PROCESS(
159     - COMMAND ${RAPTOR_CONFIG} --cflags
160     - OUTPUT_VARIABLE raptor_CFLAGS_ARGS)
161     - STRING( REPLACE " " ";" raptor_CFLAGS_ARGS ${raptor_CFLAGS_ARGS} )
162     - FOREACH( _ARG ${raptor_CFLAGS_ARGS} )
163     - IF(${_ARG} MATCHES "^-I")
164     - STRING(REGEX REPLACE "^-I" "" _ARG ${_ARG})
165     - STRING( REPLACE "\n" "" _ARG ${_ARG} )
166     - LIST(APPEND raptor_INCLUDE_DIRS ${_ARG})
167     - ENDIF(${_ARG} MATCHES "^-I")
168     - ENDFOREACH(_ARG)
169     -
170     - # extract lib paths from raptor-config
171     - EXECUTE_PROCESS(
172     - COMMAND ${RAPTOR_CONFIG} --libs
173     - OUTPUT_VARIABLE raptor_CFLAGS_ARGS)
174     - STRING( REPLACE " " ";" raptor_CFLAGS_ARGS ${raptor_CFLAGS_ARGS} )
175     - FOREACH( _ARG ${raptor_CFLAGS_ARGS} )
176     - IF(${_ARG} MATCHES "^-L")
177     - STRING(REGEX REPLACE "^-L" "" _ARG ${_ARG})
178     - LIST(APPEND raptor_LIBRARY_DIRS ${_ARG})
179     - ENDIF(${_ARG} MATCHES "^-L")
180     - ENDFOREACH(_ARG)
181     - endif(RAPTOR_VERSION)
182     -else(RAPTOR_CONFIG)
183     - SET(RAPTOR_VERSION "1.0.0")
184     -endif(RAPTOR_CONFIG)
185     -
186     -find_path(RAPTOR_INCLUDE_DIR raptor.h
187     - PATHS
188     - ${redland_INCLUDE_DIRS}
189     - ${raptor_INCLUDE_DIRS}
190     - /usr/X11/include
191     - PATH_SUFFIXES redland
192     - )
193     -
194     -find_library(RAPTOR_LIBRARIES NAMES raptor libraptor
195     - PATHS
196     - ${raptor_LIBRARY_DIRS}
197     - )
198     -
199     -if (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES)
200     - set(RAPTOR_FOUND TRUE)
201     -endif (RAPTOR_INCLUDE_DIR AND RAPTOR_LIBRARIES)
202     -
203     -if (RAPTOR_FOUND)
204     - set(RAPTOR_DEFINITIONS ${raptor_CFLAGS})
205     - if (NOT Raptor_FIND_QUIETLY)
206     - message(STATUS "Found Raptor ${RAPTOR_VERSION}: libs - ${RAPTOR_LIBRARIES}; includes - ${RAPTOR_INCLUDE_DIR}")
207     - endif (NOT Raptor_FIND_QUIETLY)
208     -else (RAPTOR_FOUND)
209     - if (Raptor_FIND_REQUIRED)
210     - message(FATAL_ERROR "Could NOT find Raptor")
211     - endif (Raptor_FIND_REQUIRED)
212     -endif (RAPTOR_FOUND)
213     -
214     -mark_as_advanced(RAPTOR_INCLUDE_DIR_TMP
215     - RAPTOR_INCLUDE_DIR
216     - RAPTOR_LIBRARIES)
217     diff -Naur soprano-2.6.51/CMakeLists.txt soprano/CMakeLists.txt
218     --- soprano-2.6.51/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200
219     +++ soprano/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200
220 niro 1428 @@ -7,7 +7,7 @@
221     ################## Soprano version ################################
222     set(CMAKE_SOPRANO_VERSION_MAJOR 2)
223     set(CMAKE_SOPRANO_VERSION_MINOR 6)
224 niro 1429 -set(CMAKE_SOPRANO_VERSION_RELEASE 51)
225     +set(CMAKE_SOPRANO_VERSION_RELEASE 52)
226 niro 1428 set(CMAKE_SOPRANO_VERSION_STRING "${CMAKE_SOPRANO_VERSION_MAJOR}.${CMAKE_SOPRANO_VERSION_MINOR}.${CMAKE_SOPRANO_VERSION_RELEASE}")
227    
228    
229 niro 1429 diff -Naur soprano-2.6.51/parsers/raptor/CMakeLists.txt soprano/parsers/raptor/CMakeLists.txt
230     --- soprano-2.6.51/parsers/raptor/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200
231     +++ soprano/parsers/raptor/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200
232     @@ -13,13 +13,11 @@
233 niro 1428 raptorparser.cpp
234     )
235    
236 niro 1429 -configure_file(raptor-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/raptor-config.h)
237     -
238 niro 1428 qt4_automoc(${raptor_parser_SRC})
239    
240 niro 1429 -add_library(soprano_raptorparser MODULE ${raptor_parser_SRC})
241     +add_library(soprano_raptorparser MODULE ${raptor_parser_SRC})
242 niro 1428
243 niro 1429 -TARGET_LINK_LIBRARIES(soprano_raptorparser soprano ${RAPTOR_LIBRARIES})
244     +TARGET_LINK_LIBRARIES(soprano_raptorparser soprano raptor2 ${RAPTOR_LIBRARIES})
245 niro 1428
246     set_target_properties(soprano_raptorparser PROPERTIES
247     DEFINE_SYMBOL MAKE_RAPTORPARSER_LIB
248 niro 1429 diff -Naur soprano-2.6.51/parsers/raptor/raptor-config.h.cmake soprano/parsers/raptor/raptor-config.h.cmake
249     --- soprano-2.6.51/parsers/raptor/raptor-config.h.cmake 2011-06-05 10:38:25.000000000 +0200
250     +++ soprano/parsers/raptor/raptor-config.h.cmake 1970-01-01 01:00:00.000000000 +0100
251     @@ -1 +0,0 @@
252     -#cmakedefine RAPTOR_HAVE_TRIG
253     diff -Naur soprano-2.6.51/parsers/raptor/raptorparser.cpp soprano/parsers/raptor/raptorparser.cpp
254     --- soprano-2.6.51/parsers/raptor/raptorparser.cpp 2011-06-05 10:38:25.000000000 +0200
255     +++ soprano/parsers/raptor/raptorparser.cpp 2011-07-19 18:49:58.000000000 +0200
256 niro 1428 @@ -3,7 +3,7 @@
257     * This file is part of Soprano Project
258     *
259     * Copyright (C) 2006 Duncan Mac-Vicar <duncan@kde.org>
260 niro 1429 - * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
261     + * Copyright (C) 2007,2011 Sebastian Trueg <trueg@kde.org>
262 niro 1428 *
263     * This library is free software; you can redistribute it and/or
264     * modify it under the terms of the GNU Library General Public
265 niro 1429 @@ -22,14 +22,13 @@
266 niro 1428 */
267    
268     #include "raptorparser.h"
269 niro 1429 -#include "raptor-config.h"
270 niro 1428
271     #include "util/simplestatementiterator.h"
272     #include "statement.h"
273     #include "locator.h"
274     #include "error.h"
275    
276 niro 1429 -#include <raptor.h>
277     +#include <raptor2/raptor.h>
278 niro 1428
279     #include <QtCore/QUrl>
280     #include <QtCore/QFile>
281 niro 1429 @@ -40,88 +39,71 @@
282 niro 1428 #include <QtCore/QMutexLocker>
283    
284    
285 niro 1429 -namespace {
286     - class RaptorInitHelper
287     - {
288     - public:
289     - RaptorInitHelper() {
290     - raptor_init();
291     - }
292     - ~RaptorInitHelper() {
293     - raptor_finish();
294     - }
295     - };
296     -}
297     -
298 niro 1428 Q_EXPORT_PLUGIN2(soprano_raptorparser, Soprano::Raptor::Parser)
299    
300     namespace {
301 niro 1429 - // for some strange reason raptor <= 1.4.15 can only handle application/turtle when parsing
302     - // and application/x-turtle when serializing, but not the other way around
303     - QString mimeTypeString( Soprano::RdfSerialization s, const QString& userSerialization )
304     - {
305     -#ifndef RAPTOR_HAVE_TRIG
306     - if ( s == Soprano::SerializationTurtle ) {
307     - return "application/turtle"; // x-turtle does not work....
308     - }
309     - else
310     -#endif
311     - {
312     - return serializationMimeType( s, userSerialization );
313     - }
314     - }
315     -
316     -
317     - void raptorMessageHandler( void* userData, raptor_locator* locator, const char* message )
318     + void raptorLogHandler(void *userData,raptor_log_message *message)
319 niro 1428 {
320     Soprano::Raptor::Parser* p = static_cast<Soprano::Raptor::Parser*>( userData );
321 niro 1429 - if ( locator ) {
322     - p->setError( Soprano::Error::ParserError( Soprano::Error::Locator( locator->line, locator->column, locator->byte ),
323     - QString::fromUtf8( message ),
324     + if ( message->locator ) {
325     + p->setError( Soprano::Error::ParserError( Soprano::Error::Locator( message->locator->line, message->locator->column, message->locator->byte ),
326     + QString::fromUtf8( message->text ),
327 niro 1428 Soprano::Error::ErrorParsingFailed ) );
328     }
329     else {
330 niro 1429 - p->setError( Soprano::Error::Error( QString::fromUtf8( message ), Soprano::Error::ErrorUnknown ) );
331     + p->setError( Soprano::Error::Error( QString::fromUtf8( message->text ), Soprano::Error::ErrorUnknown ) );
332 niro 1428 }
333     }
334    
335     -
336 niro 1429 - Soprano::Node convertNode( const void* data, raptor_identifier_type type,
337     - raptor_uri* objectLiteralDatatype = 0, const unsigned char* objectLiteralLanguage = 0 )
338     + Soprano::Node convertNode( raptor_term * term )
339     {
340     - switch( type ) {
341     - case RAPTOR_IDENTIFIER_TYPE_RESOURCE:
342     - case RAPTOR_IDENTIFIER_TYPE_PREDICATE:
343     - case RAPTOR_IDENTIFIER_TYPE_ORDINAL:
344     - return Soprano::Node::createResourceNode( QString::fromUtf8( ( char* )raptor_uri_as_string( ( raptor_uri* )data ) ) );
345 niro 1428 -
346 niro 1429 - case RAPTOR_IDENTIFIER_TYPE_ANONYMOUS:
347     - return Soprano::Node::createBlankNode( QString::fromUtf8( ( const char* )data ) );
348     -
349     - case RAPTOR_IDENTIFIER_TYPE_LITERAL:
350     - case RAPTOR_IDENTIFIER_TYPE_XML_LITERAL:
351     - if ( objectLiteralDatatype ) {
352     - return Soprano::Node::createLiteralNode( Soprano::LiteralValue::fromString( QString::fromUtf8( ( const char* )data ),
353     - QString::fromUtf8( ( char* )raptor_uri_as_string( objectLiteralDatatype ) ) ) );
354     + if(!term) {
355     + return Soprano::Node();
356     + }
357 niro 1428 +
358 niro 1429 + switch( term->type ) {
359     + case RAPTOR_TERM_TYPE_URI: {
360     + return Soprano::Node::createResourceNode(
361     + QString::fromUtf8( ( char* )raptor_uri_as_string( term->value.uri ) ) );
362     + }
363 niro 1428 +
364 niro 1429 + case RAPTOR_TERM_TYPE_BLANK: {
365     + return Soprano::Node::createBlankNode(
366     + QString::fromUtf8( ( const char* )(term->value.blank.string) ) );
367     + }
368     +
369     + case RAPTOR_TERM_TYPE_LITERAL: {
370     + if ( term->value.literal.datatype ) {
371     + return Soprano::Node::createLiteralNode(
372     + Soprano::LiteralValue::fromString(
373     + QString::fromUtf8( ( const char* )term->value.literal.string ),
374     + QString::fromUtf8(
375     + ( char* )raptor_uri_as_string(term->value.literal.datatype ) )
376     + )
377     + );
378 niro 1428 }
379     else {
380 niro 1429 - return Soprano::Node::createLiteralNode( Soprano::LiteralValue::createPlainLiteral( QString::fromUtf8( ( const char* )data ),
381     - QString::fromUtf8( ( const char* )objectLiteralLanguage ) ) );
382     + return Soprano::Node::createLiteralNode(
383     + Soprano::LiteralValue::createPlainLiteral(
384     + QString::fromUtf8( ( const char* )term->value.literal.string ),
385     + QString::fromUtf8( ( const char* )term->value.literal.language ) ) );
386 niro 1428 }
387 niro 1429 + }
388 niro 1428
389     default:
390     return Soprano::Node();
391     }
392 niro 1429 - }
393 niro 1428
394 niro 1429 + // make gcc shut up
395     + return Soprano::Node();
396     + }
397    
398 niro 1428 Soprano::Statement convertTriple( const raptor_statement* triple )
399     {
400 niro 1429 - return Soprano::Statement( convertNode( triple->subject, triple->subject_type ),
401     - convertNode( triple->predicate, triple->predicate_type ),
402     - convertNode( triple->object, triple->object_type,
403     - triple->object_literal_datatype,
404     - triple->object_literal_language ) );
405     + return Soprano::Statement( convertNode( triple->subject ),
406     + convertNode( triple->predicate ),
407     + convertNode( triple->object ),
408     + convertNode( triple->graph ) );
409 niro 1428 }
410    
411    
412 niro 1429 @@ -132,47 +114,48 @@
413 niro 1428 };
414    
415    
416 niro 1429 - void raptorTriplesHandler( void* userData, const raptor_statement* triple )
417     + void raptorTriplesHandler( void* userData, raptor_statement* triple )
418 niro 1428 {
419 niro 1429 + Q_ASSERT(userData);
420 niro 1428 ParserData* pd = static_cast<ParserData*>( userData );
421 niro 1429 - Soprano::Statement s = convertTriple( triple );
422     -// qDebug() << "got triple: " << s;
423     - s.setContext( pd->currentContext );
424     - pd->statements.append( s );
425     + pd->statements.append( convertTriple( triple ) );
426 niro 1428 }
427 niro 1429 +}
428 niro 1428
429    
430 niro 1429 - void raptorGraphHandler( void* userData, raptor_uri* graph )
431     - {
432     - Soprano::Node context = Soprano::Node::createResourceNode( QString::fromUtf8( ( char* )raptor_uri_as_string( graph ) ) );
433     - ParserData* pd = static_cast<ParserData*>( userData );
434     - pd->currentContext = context;
435     -// qDebug() << "got graph: " << context;
436     - }
437     -}
438     +class Soprano::Raptor::Parser::Private
439     +{
440     +public:
441     + raptor_world * world;
442     + mutable QMutex mutex;
443     +};
444 niro 1428
445    
446     Soprano::Raptor::Parser::Parser()
447     : QObject(),
448 niro 1429 - Soprano::Parser( "raptor" )
449     + Soprano::Parser( "raptor" ),
450     + d(new Private())
451 niro 1428 {
452 niro 1429 + d->world = raptor_new_world();
453     + raptor_world_open(d->world);
454     + Q_ASSERT(d->world);
455 niro 1428 }
456    
457    
458     Soprano::Raptor::Parser::~Parser()
459     {
460 niro 1429 + raptor_free_world(d->world);
461     + delete d;
462 niro 1428 }
463    
464    
465     Soprano::RdfSerializations Soprano::Raptor::Parser::supportedSerializations() const
466     {
467 niro 1429 - return( SerializationRdfXml
468     - |SerializationNTriples
469     - |SerializationTurtle
470     -#ifdef RAPTOR_HAVE_TRIG
471     - |SerializationTrig
472     -#endif
473     - );
474     + return( SerializationRdfXml
475     + |SerializationNTriples
476     + |SerializationTurtle
477     + |SerializationTrig
478     + );
479 niro 1428 }
480    
481    
482 niro 1429 @@ -180,13 +163,14 @@
483 niro 1428 const QString& userSerialization ) const
484     {
485     // create the parser
486 niro 1429 - QString mimeType = mimeTypeString( serialization, userSerialization );
487     + const QString mimeType = Soprano::serializationMimeType( serialization, userSerialization );
488 niro 1428 raptor_parser* parser = 0;
489     if ( serialization == Soprano::SerializationNTriples ) {
490 niro 1429 - parser = raptor_new_parser( "ntriples" ); // mimetype for ntriple is text/plain which is useless for the method below
491     + parser = raptor_new_parser(d->world,"ntriples"); // mimetype for ntriple is text/plain which is useless for the method below
492 niro 1428 }
493     else {
494 niro 1429 - parser = raptor_new_parser_for_content( 0,
495     + parser = raptor_new_parser_for_content( d->world,
496     + 0,
497 niro 1428 mimeType.toLatin1().data(),
498     0,
499     0,
500 niro 1429 @@ -194,16 +178,14 @@
501 niro 1428 }
502    
503     if ( !parser ) {
504 niro 1429 - qDebug() << "(Soprano::Raptor::Parser) no parser for serialization " << mimeTypeString( serialization, userSerialization );
505     - setError( QString( "Failed to create parser for serialization %1" ).arg( mimeTypeString( serialization, userSerialization ) ) );
506     + qDebug() << "(Soprano::Raptor::Parser) no parser for serialization " << Soprano::serializationMimeType( serialization, userSerialization );
507     + setError( QString( "Failed to create parser for serialization %1" ).arg( Soprano::serializationMimeType( serialization, userSerialization ) ) );
508 niro 1428 return 0;
509     }
510    
511 niro 1429 - // set the erro handling method
512     + // set the error handling method
513 niro 1428 Parser* that = const_cast<Parser*>( this );
514 niro 1429 - raptor_set_fatal_error_handler( parser, that, raptorMessageHandler );
515     - raptor_set_error_handler( parser, that, raptorMessageHandler );
516     - raptor_set_warning_handler( parser, that, raptorMessageHandler );
517     + raptor_world_set_log_handler(d->world, that, raptorLogHandler);
518 niro 1428
519     return parser;
520     }
521 niro 1429 @@ -223,48 +205,6 @@
522 niro 1428 setError( QString( "Could not open file %1 for reading." ).arg( filename ) );
523     return StatementIterator();
524     }
525 niro 1429 -
526     -// clearError();
527     -
528     -// raptor_parser* parser = createParser( serialization, userSerialization );
529     -// if ( !parser ) {
530     -// return StatementIterator();
531     -// }
532     -
533     -// // prepare the container for the parsed data
534     -// QList<Statement> statements;
535     -// raptor_set_statement_handler( parser, &statements, raptorTriplesHandler );
536     -
537     -// // start the atual parsing
538     -// QUrl uri( QUrl::fromLocalFile( filename ) );
539     -// if ( uri.scheme().isEmpty() ) {
540     -// // we need to help the stupid librdf file url handling
541     -// uri.setScheme("file");
542     -// }
543     -// raptor_uri* raptorBaseUri = 0;
544     -// if ( !baseUri.toString().isEmpty() ) {
545     -// raptorBaseUri = raptor_new_uri( (unsigned char *) baseUri.toString().toUtf8().data() );
546     -// }
547     -// raptor_uri* raptorUri = raptor_new_uri( (unsigned char *) uri.toString().toUtf8().data() );
548     -// if ( !raptorUri ) {
549     -// setError( QLatin1String( "Internal: Failed to create raptor_uri instance for '%1'" ).arg( uri ) );
550     -// return StatementIterator();
551     -// }
552     -
553     -// int r = raptor_parse_uri( parser, raptorUri, raptorBaseUri );
554     -
555     -// raptor_free_parser( parser );
556     -// raptor_free_uri( raptorUri );
557     -// if ( raptorBaseUri ) {
558     -// raptor_free_uri( raptorBaseUri );
559     -// }
560     -
561     -// if ( r == 0 ) {
562     -// return SimpleStatementIterator( statements );
563     -// }
564     -// else {
565     -// return StatementIterator();
566     -// }
567 niro 1428 }
568    
569    
570 niro 1429 @@ -279,14 +219,12 @@
571 niro 1428 }
572    
573    
574 niro 1429 -Soprano::StatementIterator
575     -Soprano::Raptor::Parser::parseStream( QTextStream& stream,
576     - const QUrl& baseUri,
577     - RdfSerialization serialization,
578     - const QString& userSerialization ) const
579     +Soprano::StatementIterator Soprano::Raptor::Parser::parseStream( QTextStream& stream,
580     + const QUrl& baseUri,
581     + RdfSerialization serialization,
582     + const QString& userSerialization ) const
583 niro 1428 {
584 niro 1429 - QMutexLocker lock( &m_mutex );
585     - RaptorInitHelper raptorInitHelper;
586     + QMutexLocker lock( &d->mutex );
587 niro 1428
588     clearError();
589    
590 niro 1429 @@ -297,22 +235,19 @@
591 niro 1428
592     // prepare the container for the parsed data
593     ParserData data;
594 niro 1429 - raptor_set_statement_handler( parser, &data, raptorTriplesHandler );
595     -#ifdef RAPTOR_HAVE_TRIG
596     - raptor_set_graph_handler( parser, &data, raptorGraphHandler );
597     -#endif
598     + raptor_parser_set_statement_handler( parser, &data, raptorTriplesHandler );
599 niro 1428
600     // start the atual parsing
601     raptor_uri* raptorBaseUri = 0;
602     if ( baseUri.isValid() ) {
603 niro 1429 - raptorBaseUri = raptor_new_uri( (unsigned char *) baseUri.toString().toUtf8().data() );
604     + raptorBaseUri = raptor_new_uri( d->world,(unsigned char *) baseUri.toString().toUtf8().data() );
605 niro 1428 }
606     else {
607 niro 1429 - raptorBaseUri = raptor_new_uri( (unsigned char *) "http://soprano.sourceforge.net/dummyBaseUri" );
608     + raptorBaseUri = raptor_new_uri( d->world, (unsigned char *) "http://soprano.sourceforge.net/dummyBaseUri" );
609 niro 1428 }
610    
611     clearError();
612 niro 1429 - if ( raptor_start_parse( parser, raptorBaseUri ) ) {
613     + if ( raptor_parser_parse_start( parser, raptorBaseUri ) != 0 ) {
614 niro 1428 if ( !lastError() ) {
615     ErrorCache::setError( QLatin1String( "Failed to start parsing." ) );
616     }
617 niro 1429 @@ -331,7 +266,10 @@
618 niro 1428 while ( !dev->atEnd() ) {
619     qint64 r = dev->read( buf.data(), buf.size() );
620     if ( r <= 0 ||
621 niro 1429 - raptor_parse_chunk( parser, ( const unsigned char* )buf.data(), r, 0 ) ) {
622     + raptor_parser_parse_chunk( parser, ( const unsigned char* )buf.data(), r, 0 ) ) {
623     + // parse_chunck return failure code.
624     + // Call it with END=true and then free
625     + raptor_parser_parse_chunk(parser,0,0,/*END=*/1);
626 niro 1428 raptor_free_parser( parser );
627     if ( raptorBaseUri ) {
628     raptor_free_uri( raptorBaseUri );
629 niro 1429 @@ -344,7 +282,10 @@
630 niro 1428 while ( !stream.atEnd() ) {
631     QString buf = stream.read( bufSize );
632     QByteArray utf8Data = buf.toUtf8();
633 niro 1429 - if ( raptor_parse_chunk( parser, ( const unsigned char* )utf8Data.data(), utf8Data.length(), 0 ) ) {
634     + if ( raptor_parser_parse_chunk( parser, ( const unsigned char* )utf8Data.data(), utf8Data.length(), 0 ) ) {
635     + // parse_chunck return failure code.
636     + // Call it with END=true and then free
637     + raptor_parser_parse_chunk(parser,0,0,/*END=*/1);
638 niro 1428 raptor_free_parser( parser );
639     if ( raptorBaseUri ) {
640     raptor_free_uri( raptorBaseUri );
641 niro 1429 @@ -353,7 +294,8 @@
642 niro 1428 }
643     }
644     }
645 niro 1429 - raptor_parse_chunk( parser, 0, 0, 1 );
646     + // Call parse_chunk with END=true
647     + raptor_parser_parse_chunk( parser, 0, 0, 1 );
648 niro 1428
649     raptor_free_parser( parser );
650     if ( raptorBaseUri ) {
651 niro 1429 diff -Naur soprano-2.6.51/parsers/raptor/raptorparser.h soprano/parsers/raptor/raptorparser.h
652     --- soprano-2.6.51/parsers/raptor/raptorparser.h 2011-06-05 10:38:25.000000000 +0200
653     +++ soprano/parsers/raptor/raptorparser.h 2011-07-19 18:49:58.000000000 +0200
654     @@ -29,13 +29,11 @@
655 niro 1428
656     #include "parser.h"
657    
658 niro 1429 -#include <raptor.h>
659     -
660     +#include<raptor2/raptor.h>
661 niro 1428
662     namespace Soprano {
663     namespace Raptor {
664 niro 1429 - class Parser : public QObject, public Soprano::Parser
665     - {
666     + class Parser : public QObject, public Soprano::Parser {
667 niro 1428 Q_OBJECT
668     Q_INTERFACES(Soprano::Parser)
669    
670 niro 1429 @@ -43,7 +41,7 @@
671 niro 1428 Parser();
672     ~Parser();
673    
674 niro 1429 - RdfSerializations supportedSerializations() const;
675     + RdfSerializations supportedSerializations() const;
676 niro 1428
677     StatementIterator parseFile( const QString& filename,
678     const QUrl& baseUri,
679 niro 1429 @@ -64,7 +62,10 @@
680 niro 1428 raptor_parser* createParser( RdfSerialization serialization,
681     const QString& userSerialization = QString() ) const;
682    
683 niro 1429 - mutable QMutex m_mutex;
684     + class Private;
685     + Private * d;
686     +
687     +
688 niro 1428 };
689     }
690     }
691 niro 1429 diff -Naur soprano-2.6.51/serializers/raptor/CMakeLists.txt soprano/serializers/raptor/CMakeLists.txt
692     --- soprano-2.6.51/serializers/raptor/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200
693     +++ soprano/serializers/raptor/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200
694     @@ -9,13 +9,8 @@
695 niro 1428 ${RAPTOR_INCLUDE_DIR}
696     )
697    
698 niro 1429 -include(CheckFunctionExists)
699 niro 1428 set(CMAKE_REQUIRED_INCLUDES ${RAPTOR_INCLUDE_DIR})
700     set(CMAKE_REQUIRED_LIBRARIES ${RAPTOR_LIBRARIES})
701 niro 1429 -check_function_exists( raptor_new_iostream_from_handler2 HAVE_IOSTREAM_HANDLER2 )
702     -if(HAVE_IOSTREAM_HANDLER2)
703     - add_definitions(-DHAVE_IOSTREAM_HANDLER2)
704     -endif(HAVE_IOSTREAM_HANDLER2)
705 niro 1428
706     set(raptor_serializer_SRC
707     raptorserializer.cpp
708 niro 1429 diff -Naur soprano-2.6.51/serializers/raptor/raptorserializer.cpp soprano/serializers/raptor/raptorserializer.cpp
709     --- soprano-2.6.51/serializers/raptor/raptorserializer.cpp 2011-06-05 10:38:25.000000000 +0200
710     +++ soprano/serializers/raptor/raptorserializer.cpp 2011-07-19 18:49:58.000000000 +0200
711     @@ -38,54 +38,135 @@
712 niro 1428 class RaptorInitHelper
713     {
714     public:
715 niro 1429 + raptor_world* world;
716     +
717 niro 1428 RaptorInitHelper() {
718 niro 1429 - raptor_init();
719     + world = raptor_new_world();
720     + raptor_world_open(world);
721 niro 1428 }
722     ~RaptorInitHelper() {
723 niro 1429 - raptor_finish();
724     + raptor_free_world(world);
725 niro 1428 }
726     };
727    
728 niro 1429 - bool convertNode( const Soprano::Node& node, const void** data, raptor_identifier_type* type, raptor_uri** dataType = 0, const unsigned char** lang = 0 )
729     + /* Probably unnecessary for serializer*/
730     + /*
731     + QString mimeTypeString( Soprano::RdfSerialization s, const QString& userSerialization )
732     + {
733     + if ( s == Soprano::SerializationTurtle ) {
734     + return "application/turtle"; // x-turtle does not work....
735     + }
736     + else {
737     + return serializationMimeType( s, userSerialization );
738     + }
739     + }*/
740     +
741     + raptor_term * convertNode( raptor_world * world, const Soprano::Node& node)
742 niro 1428 {
743 niro 1429 + raptor_term * answer = 0;
744     + /* According to documentation, raptor_new_term family takes copy of
745     + * all given input parameters
746     + */
747 niro 1428 if ( node.isResource() ) {
748 niro 1429 - *data = raptor_new_uri( ( const unsigned char* )node.uri().toEncoded().data() );
749     - *type = RAPTOR_IDENTIFIER_TYPE_RESOURCE;
750     - return true;
751     + raptor_uri * uri = raptor_new_uri(world, ( const unsigned char* )node.uri().toEncoded().data() );
752     + answer = raptor_new_term_from_uri(world,uri);
753     +
754     + raptor_free_uri(uri);
755 niro 1428 }
756     else if ( node.isBlank() ) {
757 niro 1429 - *data = qstrdup( node.identifier().toUtf8().data() );
758     - *type = RAPTOR_IDENTIFIER_TYPE_ANONYMOUS;
759     - return true;
760     + answer = raptor_new_term_from_blank(
761     + world, (const unsigned char*)node.identifier().toUtf8().data() );
762 niro 1428 }
763     else if ( node.isLiteral() ) {
764 niro 1429 - *data = qstrdup( node.toString().toUtf8().data() );
765     + // Because QByteArray.data() is valid as long as QByteArray itself is
766     + // alive, we store langBA ( and others _x_BA untill function exits
767     +
768     + //const unsigned char * literal = 0;
769     + QByteArray langBA;
770     + const unsigned char * lang = 0;
771     + raptor_uri * datatype = 0;
772     +
773 niro 1428 if ( node.literal().isPlain() ) {
774     if ( !node.language().isEmpty() )
775 niro 1429 - *lang = ( unsigned char* )qstrdup( ( const char* )node.language().toUtf8().data() );
776     + langBA = node.language().toUtf8();
777     + lang = ( const unsigned char* )( langBA.constData() );
778 niro 1428 }
779     else {
780 niro 1429 - *dataType = raptor_new_uri( ( const unsigned char* )node.dataType().toEncoded().data() );
781     + datatype = raptor_new_uri( world, ( const unsigned char* )node.dataType().toEncoded().data() );
782 niro 1428 }
783 niro 1429 - *type = RAPTOR_IDENTIFIER_TYPE_LITERAL;
784     - return true;
785     +
786     + // Now we costructs statement
787     + answer = raptor_new_term_from_literal(world,(const unsigned char*)node.literal().toByteArray().constData(),datatype,lang);
788     +
789     + // And free unnecessary resources
790     + if ( datatype)
791     + raptor_free_uri(datatype);
792     +
793 niro 1428 }
794    
795 niro 1429 - return false;
796     + return answer;
797 niro 1428 }
798    
799    
800 niro 1429 - raptor_statement* convertStatement( const Soprano::Statement& statement )
801     + raptor_statement* convertStatement(raptor_world * world, const Soprano::Statement& statement )
802 niro 1428 {
803 niro 1429 - raptor_statement* s = new raptor_statement;
804     - memset( s, 0, sizeof( raptor_statement ) );
805     - convertNode( statement.subject(), &s->subject, &s->subject_type );
806     - convertNode( statement.predicate(), &s->predicate, &s->predicate_type );
807     - convertNode( statement.object(), &s->object, &s->object_type, &s->object_literal_datatype, &s->object_literal_language );
808     + // Get terms
809     + raptor_term * subject_term = 0, *object_term = 0, * predicate_term = 0;
810     + raptor_term * graph_term = 0;
811     +
812     + subject_term = convertNode(world,statement.subject());
813     + if ( !subject_term) {
814     + qDebug() << "Failed to convert subject to raptor_term";
815     + return 0;
816     + }
817     +
818     + predicate_term = convertNode(world,statement.predicate());
819     + if (!predicate_term) {
820     + qDebug() << "Failed to convert predicate to raptor_term";
821     + raptor_free_term(subject_term);
822     + return 0;
823     + }
824     +
825     + object_term = convertNode(world,statement.object());
826     + if (!object_term) {
827     + qDebug() << "Failed to convert object to raptor_term";
828     + raptor_free_term(subject_term);
829     + raptor_free_term(predicate_term);
830     + return 0;
831     + }
832     +
833     + if ( !statement.context().isEmpty() ) {
834     + graph_term = convertNode(world,statement.context());
835     + if(!graph_term) {
836     + qDebug() << "Failed to convert graph/context to raptor_term. Node is" << statement.context();
837     + raptor_free_term(subject_term);
838     + raptor_free_term(predicate_term);
839     + raptor_free_term(object_term);
840     + return 0;
841     + }
842     + }
843     +
844     +
845     + raptor_statement* s = raptor_new_statement_from_nodes(
846     + world,
847     + subject_term,
848     + predicate_term,
849     + object_term,
850     + graph_term);
851     +
852     + if (!s) {
853     + qDebug() << "Failed to build raptor_statement from terms";
854     + raptor_free_term(subject_term);
855     + raptor_free_term(predicate_term);
856     + raptor_free_term(object_term);
857     + raptor_free_term(graph_term);
858     + }
859     +
860 niro 1428 return s;
861     }
862    
863    
864 niro 1429 + /*
865 niro 1428 void free_node( const void* data, raptor_identifier_type type )
866     {
867     switch( type ) {
868 niro 1429 @@ -109,6 +190,7 @@
869 niro 1428 free( ( char* )s->object_literal_language );
870     delete s;
871     }
872 niro 1429 + */
873 niro 1428
874    
875     int raptorIOStreamWriteByte( void* data, const int byte )
876 niro 1429 @@ -121,6 +203,7 @@
877 niro 1428 else {
878     ( *s ) << ( char )byte;
879     }
880 niro 1429 + //qDebug() << "Write char:" << (char)(byte);
881 niro 1428 return 0;
882     }
883    
884 niro 1429 @@ -140,6 +223,7 @@
885 niro 1428 raptorIOStreamWriteByte( data, p[i] );
886     }
887     }
888 niro 1429 + //qDebug() << "Write string: " << p;
889 niro 1428 break;
890     }
891     default:
892 niro 1429 @@ -153,15 +237,36 @@
893 niro 1428 Q_EXPORT_PLUGIN2(soprano_raptorserializer, Soprano::Raptor::Serializer)
894    
895    
896 niro 1429 +
897     +/* We can not rely on RaptorInitHelper anymore because
898     + * we need raptor_world in supportedUserSerializations.
899     + * Instead of constantly creating new raptor_world just to
900     + * detect user supported serializations, it is easier to
901     + * embed raptor_world into class.
902     + * And we can not declare raptor_world as a member of
903     + * Serializer directly, because raptor_world is a typedef,
904     + * not a class. So it can not be forward declarated
905     + */
906     +class Soprano::Raptor::Serializer::Private
907     +{
908     + public:
909     + raptor_world * world;
910     +};
911     +
912 niro 1428 Soprano::Raptor::Serializer::Serializer()
913     : QObject(),
914     Soprano::Serializer( "raptor" )
915     {
916 niro 1429 + this->d = new Private();
917     + this->d->world = raptor_new_world();
918     + raptor_world_open(d->world);
919 niro 1428 }
920    
921    
922     Soprano::Raptor::Serializer::~Serializer()
923     {
924 niro 1429 + raptor_free_world(d->world);
925     + delete d;
926 niro 1428 }
927    
928    
929 niro 1429 @@ -174,17 +279,19 @@
930 niro 1428 QStringList Soprano::Raptor::Serializer::supportedUserSerializations() const
931     {
932     QStringList sl;
933 niro 1429 - int i = 0;
934     - const char* name = 0;
935     - const char* label = 0;
936     - const char* mimeType = 0;
937     - const unsigned char* uri = 0;
938     - while ( !raptor_serializers_enumerate( i,
939     - &name,
940     - &label,
941     - &mimeType,
942     - &uri ) ) {
943     - sl << QString::fromUtf8( name );
944     + const raptor_syntax_description * serializer_descr = 0;
945     + for ( int i = 0; 1; ++i ) {
946     + serializer_descr =
947     + raptor_world_get_serializer_description(d->world,i);
948     +
949     + /* raptor_world_get_serializer_description will return
950     + * NULL when conter runs out of bonds and there is no
951     + * more serializers
952     + */
953     + if (!serializer_descr)
954     + break;
955     +
956     + sl << QString::fromUtf8( serializer_descr->names[0] );
957 niro 1428 ++i;
958     }
959     return sl;
960 niro 1429 @@ -198,28 +305,43 @@
961 niro 1428 {
962     clearError();
963    
964 niro 1429 - RaptorInitHelper raptorHelper;
965     + raptor_world * world = this->d->world;
966 niro 1428
967     raptor_serializer* serializer = 0;
968 niro 1429 + QString mimeType = serializationMimeType(serialization,userSerialization);
969     +
970 niro 1428 if ( serialization == SerializationRdfXml ) {
971 niro 1429 - serializer = raptor_new_serializer( "rdfxml-abbrev" ); // we always want the abbreviated xmlrdf
972     + serializer = raptor_new_serializer( world, "rdfxml-abbrev" ); // we always want the abbreviated xmlrdf
973 niro 1428 }
974     else {
975 niro 1429 + const raptor_syntax_description * serializer_descr = 0;
976 niro 1428 for ( int i = 0; 1; ++i ) {
977 niro 1429 - const char* syntax_name = 0;
978     - const char* syntax_label = 0;
979     - const char* mime_type = 0;
980     - const unsigned char* uri_string = 0;
981     - if ( raptor_serializers_enumerate( i,
982     - &syntax_name,
983     - &syntax_label,
984     - &mime_type,
985     - &uri_string ) )
986     - break;
987     - if ( !qstrcmp( serializationMimeType( serialization, userSerialization ).toLatin1().data(), mime_type ) ) {
988     - serializer = raptor_new_serializer( syntax_name );
989     + serializer_descr =
990     + raptor_world_get_serializer_description(world,i);
991     +
992     + /* raptor_world_get_serializer_description will return
993     + * NULL when conter runs out of bonds and there is no
994     + * more serializers
995     + */
996     + if (!serializer_descr)
997 niro 1428 break;
998 niro 1429 +
999     + /* In serializer_descr->mime_types we have a array of pairs
1000     + * (mime_type,Q) of mime_type for this syntax. It looks like
1001     + * we can ignore Q value in this case
1002     + * Acording to documentation, this array can have zero elements
1003     + */
1004     + for( int mt_number = 0; mt_number < serializer_descr->mime_types_count;
1005     + mt_number++)
1006     + {
1007     + const char * mime_type_N = serializer_descr->mime_types[mt_number].mime_type;
1008     + if ( !qstrcmp( serializationMimeType( serialization, userSerialization ).toLatin1().data(), mime_type_N ) ) {
1009     + serializer = raptor_new_serializer( world, serializer_descr->names[0] );
1010     + break;
1011     + }
1012     }
1013     + if ( serializer )
1014     + break;
1015 niro 1428 }
1016     }
1017    
1018 niro 1429 @@ -232,8 +354,8 @@
1019 niro 1428 QHash<QString, QUrl> namespaces = prefixes();
1020     for ( QHash<QString, QUrl>::const_iterator pfit = namespaces.constBegin();
1021     pfit != namespaces.constEnd(); ++pfit ) {
1022 niro 1429 - raptor_uri* ns = raptor_new_uri( reinterpret_cast<unsigned char*>( pfit.value().toEncoded().data() ) );
1023     - raptor_serialize_set_namespace( serializer,
1024     + raptor_uri* ns = raptor_new_uri( world,reinterpret_cast<unsigned char*>( pfit.value().toEncoded().data() ) );
1025     + raptor_serializer_set_namespace( serializer,
1026 niro 1428 ns,
1027     ( unsigned char* )pfit.key().toLatin1().data() );
1028     raptor_free_uri( ns );
1029 niro 1429 @@ -241,42 +363,53 @@
1030 niro 1428
1031     bool success = true;
1032    
1033 niro 1429 -#ifdef HAVE_IOSTREAM_HANDLER2
1034     - raptor_iostream_handler2 raptorStreamHandler = {
1035     - 2,
1036     - 0,
1037     - 0,
1038     - raptorIOStreamWriteByte,
1039     - raptorIOStreamWriteBytes,
1040     - 0,
1041     - 0,
1042     - 0
1043     - };
1044     - raptor_iostream* raptorStream = raptor_new_iostream_from_handler2( &stream,
1045     - &raptorStreamHandler );
1046     -#else
1047     - raptor_iostream_handler raptorStreamHandler = {
1048     - 0,
1049     - 0,
1050     - raptorIOStreamWriteByte,
1051     - raptorIOStreamWriteBytes,
1052     - 0
1053     - };
1054     - raptor_iostream* raptorStream = raptor_new_iostream_from_handler( &stream,
1055     - &raptorStreamHandler );
1056     -#endif
1057     + raptor_iostream_handler raptorStreamHandler;
1058     + // ATTENTION: Raptor documentation is incorrect! Always set
1059     + // version to 2 and raptor_iostream_calculate_modes internal
1060     + // call will correctly determine operation mode ( read,write,readwrite)
1061     + raptorStreamHandler.version = 2;
1062     + raptorStreamHandler.init = 0;
1063     + raptorStreamHandler.finish = 0;
1064     + raptorStreamHandler.write_byte = raptorIOStreamWriteByte;
1065     + raptorStreamHandler.write_bytes = raptorIOStreamWriteBytes;
1066     + raptorStreamHandler.write_end = 0;
1067     + raptorStreamHandler.read_bytes = 0;
1068     + raptorStreamHandler.read_eof = 0;
1069     +
1070     + raptor_iostream* raptorStream = raptor_new_iostream_from_handler(
1071     + world,
1072     + &stream,
1073     + &raptorStreamHandler
1074     + );
1075     +
1076     + if (!raptorStream) {
1077     + qDebug() << "Can not create raptor iostream";
1078     + raptor_free_serializer(serializer);
1079     + return false;
1080     + }
1081 niro 1428
1082     // raptor_serialize_start takes ownership of raptorStream
1083 niro 1429 - raptor_serialize_start( serializer, 0, raptorStream );
1084     + raptor_serializer_start_to_iostream( serializer,0, raptorStream );
1085 niro 1428
1086     while ( it.next() ) {
1087 niro 1429 - raptor_statement* rs = convertStatement( *it );
1088     - raptor_serialize_statement( serializer, rs );
1089     - free_statement( rs );
1090     + raptor_statement * rs = convertStatement(world, *it );
1091     + if (rs) {
1092     + //qDebug() << "Serializing statement: " << *it;
1093     + raptor_serializer_serialize_statement(serializer, rs );
1094     + raptor_free_statement( rs );
1095     + }
1096     + else {
1097     + qDebug() << "Fail to convert Soprano::Statement " <<
1098     + *it <<
1099     + " to raptor_statement";
1100     + success = false;
1101     + break;
1102     + }
1103 niro 1428 }
1104    
1105 niro 1429 - raptor_serialize_end( serializer );
1106     + raptor_serializer_serialize_end( serializer );
1107 niro 1428 raptor_free_serializer( serializer );
1108 niro 1429 + raptor_free_iostream(raptorStream);
1109 niro 1428
1110     return success;
1111     }
1112 niro 1429 diff -Naur soprano-2.6.51/serializers/raptor/raptorserializer.h soprano/serializers/raptor/raptorserializer.h
1113     --- soprano-2.6.51/serializers/raptor/raptorserializer.h 2011-06-05 10:38:25.000000000 +0200
1114     +++ soprano/serializers/raptor/raptorserializer.h 2011-07-19 18:49:58.000000000 +0200
1115     @@ -28,7 +28,6 @@
1116 niro 1428
1117     #include "serializer.h"
1118    
1119 niro 1429 -
1120 niro 1428 namespace Soprano {
1121     namespace Raptor {
1122     class Serializer : public QObject, public Soprano::Serializer
1123 niro 1429 @@ -47,6 +46,12 @@
1124 niro 1428 QTextStream& stream,
1125     RdfSerialization serialization,
1126     const QString& userSerialization = QString() ) const;
1127 niro 1429 + private:
1128     + /* See source file comments, that explain why it is necessary to
1129     + * use Private class and RaptorInitHelper is not succifient anymore
1130     + */
1131     + class Private;
1132     + Private * d;
1133 niro 1428 };
1134     }
1135     }
1136 niro 1429 diff -Naur soprano-2.6.51/soprano/inference/inferenceruleset.cpp soprano/soprano/inference/inferenceruleset.cpp
1137     --- soprano-2.6.51/soprano/inference/inferenceruleset.cpp 2011-06-05 10:38:25.000000000 +0200
1138     +++ soprano/soprano/inference/inferenceruleset.cpp 2011-07-19 18:49:58.000000000 +0200
1139     @@ -27,7 +27,10 @@
1140 niro 1428
1141     #include <QtCore/QHash>
1142     #include <QtCore/QList>
1143 niro 1429 -
1144     +#ifdef Q_OS_WIN
1145     +#include <QtCore/QCoreApplication>
1146     +#include <QtCore/QDir>
1147     +#endif
1148 niro 1428
1149     class Soprano::Inference::RuleSet::Private : public QSharedData
1150     {
1151 niro 1429 @@ -138,5 +141,22 @@
1152 niro 1428
1153     RuleParser parser;
1154     parser.parseFile( path );
1155 niro 1429 +#ifdef Q_OS_WIN
1156     + // Additionally try to look up the rules based on the runtime Path if
1157     + // they can not be found at the install prefix
1158     + if (!parser.rules().count()) {
1159     + path = QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( ".." );
1160     + path += "/share/soprano/rules/";
1161     +
1162     + switch( set ) {
1163     + case RDFS:
1164     + path += "rdfs.rules";
1165     + break;
1166     + case NRL:
1167     + path += "nrl.rules";
1168     + break;
1169     + }
1170     + }
1171     +#endif
1172 niro 1428 return parser.rules();
1173     }
1174 niro 1429 diff -Naur soprano-2.6.51/soprano/sopranodirs.cpp soprano/soprano/sopranodirs.cpp
1175     --- soprano-2.6.51/soprano/sopranodirs.cpp 2011-06-05 10:38:25.000000000 +0200
1176     +++ soprano/soprano/sopranodirs.cpp 2011-07-19 18:49:58.000000000 +0200
1177     @@ -28,8 +28,12 @@
1178 niro 1428 #include <QtCore/QCoreApplication>
1179     #include <QtCore/QDebug>
1180    
1181 niro 1429 -
1182     -#if defined _WIN32 || defined _WIN64
1183     +#ifdef Q_OS_WIN
1184     +static inline QString getWinPrefix()
1185     +{
1186     + // returns the parent directory of the application
1187     + return QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( ".." );
1188     +}
1189 niro 1428 #define PATH_SEPARATOR ';'
1190     #else
1191     #define PATH_SEPARATOR ':'
1192 niro 1429 @@ -123,6 +127,8 @@
1193 niro 1428 paths << QLatin1String( SOPRANO_PREFIX"/lib"SOPRANO_LIB_SUFFIX );
1194     #ifdef Q_OS_WIN
1195     paths << QLatin1String( SOPRANO_PREFIX"/bin" );
1196 niro 1429 + paths << getWinPrefix() + QLatin1String( "/bin" );
1197     + paths << getWinPrefix() + QLatin1String( "/lib"SOPRANO_LIB_SUFFIX );
1198 niro 1428 #else
1199     paths << QLatin1String( "/usr/lib"SOPRANO_LIB_SUFFIX );
1200     paths << QLatin1String( "/usr/local/lib"SOPRANO_LIB_SUFFIX );
1201 niro 1429 @@ -136,6 +142,9 @@
1202 niro 1428 {
1203     QStringList paths;
1204     paths << QLatin1String( SOPRANO_PREFIX"/share" )
1205 niro 1429 +#ifdef Q_OS_WIN
1206     + << getWinPrefix() + QLatin1String( "/share" )
1207     +#endif
1208 niro 1428 << Soprano::envDirList( "SOPRANO_DIRS" )
1209     << Soprano::envDirList( "XDG_DATA_DIRS" );
1210     return paths;
1211 niro 1429 @@ -146,6 +155,9 @@
1212 niro 1428 {
1213     QStringList paths;
1214     paths << QLatin1String( SOPRANO_PREFIX"/bin" )
1215 niro 1429 +#ifdef Q_OS_WIN
1216     + << getWinPrefix() + QLatin1String( "/bin" )
1217     +#endif
1218 niro 1428 << envDirList( "PATH" );
1219     return paths;
1220     }
1221 niro 1429 diff -Naur soprano-2.6.51/test/CMakeLists.txt soprano/test/CMakeLists.txt
1222     --- soprano-2.6.51/test/CMakeLists.txt 2011-06-05 10:38:25.000000000 +0200
1223     +++ soprano/test/CMakeLists.txt 2011-07-19 18:49:58.000000000 +0200
1224     @@ -135,6 +135,12 @@
1225 niro 1428 target_link_libraries(parsertest soprano ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY})
1226     add_test(parsertest ${EXECUTABLE_OUTPUT_PATH}/parsertest)
1227    
1228 niro 1429 +# serializer test
1229     +qt4_automoc(serializetest serializetest.cpp)
1230     +add_executable(serializertest serializetest.cpp)
1231     +target_link_libraries(serializertest soprano ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY})
1232     +add_test(serializertest ${EXECUTABLE_OUTPUT_PATH}/serializertest)
1233     +
1234 niro 1428 # Error test
1235     qt4_automoc(errortest errortest.cpp)
1236     add_executable(errortest errortest.cpp)
1237 niro 1429 diff -Naur soprano-2.6.51/test/serializetest.cpp soprano/test/serializetest.cpp
1238     --- soprano-2.6.51/test/serializetest.cpp 1970-01-01 01:00:00.000000000 +0100
1239     +++ soprano/test/serializetest.cpp 2011-07-19 18:49:58.000000000 +0200
1240     @@ -0,0 +1,167 @@
1241     +/*
1242     + * This file is part of Soprano Project.
1243     + *
1244     + * Copyright (C) 2007-2008 Sebastian Trueg <trueg@kde.org>
1245     + *
1246     + * This library is free software; you can redistribute it and/or
1247     + * modify it under the terms of the GNU Library General Public
1248     + * License as published by the Free Software Foundation; either
1249     + * version 2 of the License, or (at your option) any later version.
1250     + *
1251     + * This library is distributed in the hope that it will be useful,
1252     + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1253     + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1254     + * Library General Public License for more details.
1255     + *
1256     + * You should have received a copy of the GNU Library General Public License
1257     + * along with this library; see the file COPYING.LIB. If not, write to
1258     + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1259     + * Boston, MA 02110-1301, USA.
1260     + */
1261     +
1262     +#include "serializetest.h"
1263     +#include "config-testdata.h"
1264     +
1265     +#include "serializer.h"
1266     +#include "parser.h"
1267     +#include "pluginmanager.h"
1268     +#include "statementiterator.h"
1269     +#include "simplestatementiterator.h"
1270     +#include "statement.h"
1271     +#include "vocabulary.h"
1272     +
1273     +#include <QtTest/QTest>
1274     +#include <QtCore/QFile>
1275     +#include <QtCore/QDebug>
1276     +
1277     +
1278     +using namespace Soprano;
1279     +
1280     +#include "testdata.h"
1281     +
1282     +
1283     +void SerializerTest::init()
1284     +{
1285     +#if 0
1286     + // Init reference statements list
1287     + const Parser * parser = PluginManager::instance()->discoverParserForSerialization(SerializationTrig);
1288     + QVERIFY(parser);
1289     + StatementIterator refIt = parser->parseFile(
1290     + SOPRANO_TEST_DATA_DIR"/trig-testdata.trig",
1291     + QUrl("http://soprano.sf.net/testdata/"),
1292     + SerializationTrig);
1293     + this->referenceStatements = refIt.allStatements();
1294     +#endif
1295     +}
1296     +
1297     +Q_DECLARE_METATYPE( Soprano::RdfSerialization )
1298     +
1299     +void SerializerTest::testSerializer_data()
1300     +{
1301     +
1302     + QTest::addColumn<Soprano::RdfSerialization>( "serialization" );
1303     + QTest::addColumn<bool>( "withContext" );
1304     +
1305     + QTest::newRow("rdf_xml") << SerializationRdfXml << false;
1306     + QTest::newRow("turtle") << SerializationTurtle << false;
1307     + QTest::newRow("trig") << SerializationTrig << true;
1308     +}
1309     +
1310     +
1311     +
1312     +void SerializerTest::testSerializer()
1313     +{
1314     + QFETCH( RdfSerialization, serialization );
1315     + QFETCH( bool, withContext );
1316     +
1317     + //qDebug() << "Serialization: " << serializationMimeType(serialization);
1318     + QList<const Serializer*> serializers = PluginManager::instance()->allSerializers();
1319     +
1320     +
1321     + /* Step 1 - create reference statements */
1322     + QList<Statement> referenceStatements = testData(withContext);
1323     + //QList<Statement> testStatements = testData( withContext );
1324     +
1325     + Q_FOREACH( const Serializer * serializer, serializers ) {
1326     + if ( serializer->supportsSerialization( serialization ) ) {
1327     + // Find if we have Parser for this serialization, to parse data back.
1328     + // If not, then oops )
1329     + const Parser * back_parser = PluginManager::instance()->discoverParserForSerialization(serialization);
1330     + if ( !back_parser ) {
1331     + qDebug() << "We can not found parser for" <<
1332     + serializationMimeType(serialization) <<
1333     + " Skipping it";
1334     + continue;
1335     + }
1336     +
1337     + // Now serialize reference data
1338     + QByteArray data_array;
1339     + QTextStream serializationStorage(&data_array,QIODevice::ReadWrite);
1340     +
1341     + bool result = serializer->serialize(
1342     + /*what*/Util::SimpleStatementIterator(referenceStatements),
1343     + /*where*/serializationStorage,
1344     + /*type*/serialization
1345     + );
1346     + QVERIFY(result);
1347     +
1348     + //qDebug() << "Serialization storage: " << data_array;
1349     +
1350     + // Now parse gained text stream back
1351     + QTextStream readStorageStream(&data_array, QIODevice::ReadOnly);
1352     + StatementIterator it = back_parser->parseStream(
1353     + readStorageStream,
1354     + QUrl("http://soprano.sf.net/testdata/"),
1355     + serialization);
1356     +
1357     + QList<Statement> all = it.allStatements();
1358     +
1359     +
1360     + // Now compare recieved with reference
1361     + QCOMPARE( all.count(), referenceStatements.count() );
1362     +
1363     + Q_FOREACH( Statement s, referenceStatements ) {
1364     + bool contains = all.contains(s);
1365     + if ( !contains ) {
1366     + qDebug() << "Not found in parsed: " << s;
1367     + }
1368     +
1369     + QVERIFY( contains );
1370     + }
1371     +
1372     + }
1373     + }
1374     +}
1375     +
1376     +
1377     +#if 0
1378     +void SerializerTest::testEncoding()
1379     +{
1380     + // FIXME: provide test data for all supported encodings (no big problem so far since we only have the raptor parser)
1381     +
1382     + // parse both files, same content, different encodings and compare the results
1383     + const QString utf8File = SOPRANO_TEST_DATA_DIR"/rdf_xml-testdata-utf8.rdf";
1384     + const QString isoFile = SOPRANO_TEST_DATA_DIR"/rdf_xml-testdata-iso8859.rdf";
1385     +
1386     + const Soprano::Parser* parser = PluginManager::instance()->discoverParserForSerialization( SerializationRdfXml );
1387     + if ( parser ) {
1388     + QList<Statement> utf8Statements = parser->parseFile( utf8File, QUrl(), SerializationRdfXml ).allStatements();
1389     + QList<Statement> isoStatements = parser->parseFile( isoFile, QUrl(), SerializationRdfXml ).allStatements();
1390     +
1391     + // brute force comparision, time is not an issue, no need to get inventive. ;)
1392     + foreach( const Statement& s, utf8Statements ) {
1393     + if ( !isoStatements.contains( s ) ) qDebug() << s;
1394     + QVERIFY( isoStatements.contains( s ) );
1395     + }
1396     + foreach( const Statement& s, isoStatements ) {
1397     + if ( !utf8Statements.contains( s ) ) qDebug() << s;
1398     + QVERIFY( utf8Statements.contains( s ) );
1399     + }
1400     + }
1401     +}
1402     +#endif
1403     +
1404     +QTEST_MAIN( SerializerTest )
1405     +
1406     +#include "serializetest.moc"
1407     +
1408     diff -Naur soprano-2.6.51/test/serializetest.h soprano/test/serializetest.h
1409     --- soprano-2.6.51/test/serializetest.h 1970-01-01 01:00:00.000000000 +0100
1410     +++ soprano/test/serializetest.h 2011-07-19 18:49:58.000000000 +0200
1411     @@ -0,0 +1,52 @@
1412     +/*
1413     + * This file is part of Soprano Project.
1414     + *
1415     + * Copyright (C) 2007-2008 Sebastian Trueg <strueg@mandriva.com>
1416     + *
1417     + * This library is free software; you can redistribute it and/or
1418     + * modify it under the terms of the GNU Library General Public
1419     + * License as published by the Free Software Foundation; either
1420     + * version 2 of the License, or (at your option) any later version.
1421     + *
1422     + * This library is distributed in the hope that it will be useful,
1423     + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1424     + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1425     + * Library General Public License for more details.
1426     + *
1427     + * You should have received a copy of the GNU Library General Public License
1428     + * along with this library; see the file COPYING.LIB. If not, write to
1429     + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1430     + * Boston, MA 02110-1301, USA.
1431     + */
1432     +
1433     +#ifndef SOPRANO_SERIALIZER_TEST_H
1434     +#define SOPRANO_SERIALIZER_TEST_H
1435     +
1436     +#include <QtCore/QObject>
1437     +#include <QtCore/QList>
1438     +
1439     +#include "statement.h"
1440     +
1441     +
1442     +/* Workflow:
1443     + * 1) Prepare one QList<Statement> with data, used as reference
1444     + * 2) For each serializer:
1445     + * 2.1) Serialize reference to memory
1446     + * 2.2) Parse this memory back to QList<Statement>
1447     + * 2.3) Compare with reference
1448     + */
1449     +class SerializerTest: public QObject
1450     +{
1451     + Q_OBJECT
1452     +
1453     +private Q_SLOTS:
1454     + void init();
1455     + void testSerializer_data();
1456     + void testSerializer();
1457     + //void testEncoding();
1458     + private:
1459     + //QList<Soprano::Statement> referenceStatements;
1460     +};
1461     +
1462     +#endif
1463     +