diff options
-rw-r--r-- | src/raptor.h | 4 | ||||
-rw-r--r-- | src/raptor_internal.h | 17 | ||||
-rw-r--r-- | src/raptor_rss.c | 2 | ||||
-rw-r--r-- | src/raptor_serialize.c | 212 | ||||
-rw-r--r-- | src/raptor_serialize_dot.c | 24 | ||||
-rw-r--r-- | src/raptor_serialize_json.c | 50 | ||||
-rw-r--r-- | src/raptor_serialize_ntriples.c | 26 | ||||
-rw-r--r-- | src/raptor_serialize_rdfxml.c | 26 | ||||
-rw-r--r-- | src/raptor_serialize_rdfxmla.c | 81 | ||||
-rw-r--r-- | src/raptor_serialize_rss.c | 71 | ||||
-rw-r--r-- | src/raptor_serialize_simple.c | 25 | ||||
-rw-r--r-- | src/raptor_serialize_turtle.c | 23 | ||||
-rw-r--r-- | utils/rapper.c | 19 |
13 files changed, 351 insertions, 229 deletions
diff --git a/src/raptor.h b/src/raptor.h index 19668349..aa0a8119 100644 --- a/src/raptor.h +++ b/src/raptor.h @@ -770,7 +770,7 @@ RAPTOR_API const char* raptor_world_guess_parser_name(raptor_world* world, raptor_uri *uri, const char *mime_type, const unsigned char *buffer, size_t len, const unsigned char *identifier); RAPTOR_API -int raptor_world_enumerate_serializers(raptor_world* world, const unsigned int counter, const char **name, const char **label, const char **mime_type, const unsigned char **uri_string); +const raptor_syntax_description* raptor_world_get_serializer_description(raptor_world* world, const unsigned int counter); RAPTOR_API int raptor_world_is_serializer_name(raptor_world* world, const char *name); RAPTOR_API @@ -919,6 +919,8 @@ RAPTOR_API raptor_iostream* raptor_serializer_get_iostream(raptor_serializer *serializer); RAPTOR_API raptor_locator* raptor_serializer_get_locator(raptor_serializer *rdf_serializer); +RAPTOR_API +const raptor_syntax_description* raptor_serializer_get_description(raptor_serializer *rdf_serializer); /* serializer option methods */ RAPTOR_API diff --git a/src/raptor_internal.h b/src/raptor_internal.h index aa2ac522..26efdd4a 100644 --- a/src/raptor_internal.h +++ b/src/raptor_internal.h @@ -639,22 +639,13 @@ struct raptor_serializer_factory_s { struct raptor_serializer_factory_s* next; - /* syntax name */ - const char* name; - /* alternate syntax name; not mentioned in enumerations */ - const char* alias; - - /* syntax readable label */ - const char* label; - /* syntax MIME type (or NULL) */ - const char* mime_type; - /* syntax URI (or NULL) */ - const unsigned char* uri_string; - /* the rest of this structure is populated by the serializer-specific register function */ size_t context_length; + /* static desc that the parser registration initialises */ + raptor_syntax_description desc; + /* create a new serializer */ int (*init)(raptor_serializer* serializer, const char *name); @@ -694,7 +685,7 @@ typedef struct /* raptor_serialize.c */ -int raptor_serializer_register_factory(raptor_world* world, const char *name, const char *label, const char *mime_type, const char *alias, const unsigned char *uri_string, int (*factory) (raptor_serializer_factory*)); +raptor_serializer_factory* raptor_serializer_register_factory(raptor_world* world, int (*factory) (raptor_serializer_factory*)); /* raptor_general.c */ diff --git a/src/raptor_rss.c b/src/raptor_rss.c index b1e83e24..1ce06ca9 100644 --- a/src/raptor_rss.c +++ b/src/raptor_rss.c @@ -1650,7 +1650,7 @@ static const raptor_type_q rss_tag_soup_types[RSS_TAG_SOUP_TYPES_COUNT + 1] = { { "text/rss", 8, 8}, { "application/xml", 15, 3}, { "text/xml", 8, 3}, - { NULL, 0} + { NULL, 0, 0} }; static int diff --git a/src/raptor_serialize.c b/src/raptor_serialize.c index 6764d063..870ca185 100644 --- a/src/raptor_serialize.c +++ b/src/raptor_serialize.c @@ -61,17 +61,6 @@ raptor_free_serializer_factory(raptor_serializer_factory* factory) if(factory->finish_factory) factory->finish_factory(factory); - if(factory->name) - RAPTOR_FREE(raptor_serializer_factory, (void*)factory->name); - if(factory->label) - RAPTOR_FREE(raptor_serializer_factory, (void*)factory->label); - if(factory->alias) - RAPTOR_FREE(raptor_serializer_factory, (void*)factory->alias); - if(factory->mime_type) - RAPTOR_FREE(cstring, factory->mime_type); - if(factory->uri_string) - RAPTOR_FREE(raptor_serializer_factory, (void*)factory->uri_string); - RAPTOR_FREE(raptor_serializer_factory, factory); } @@ -90,35 +79,35 @@ raptor_serializers_init(raptor_world* world) /* raptor_init_serializer_simple(); */ #ifdef RAPTOR_SERIALIZER_NTRIPLES - rc+= raptor_init_serializer_ntriples(world) != 0; + rc += raptor_init_serializer_ntriples(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_TURTLE - rc+= raptor_init_serializer_turtle(world) != 0; + rc += raptor_init_serializer_turtle(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_RDFXML_ABBREV - rc+= raptor_init_serializer_rdfxmla(world) != 0; + rc += raptor_init_serializer_rdfxmla(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_RDFXML - rc+= raptor_init_serializer_rdfxml(world) != 0; + rc += raptor_init_serializer_rdfxml(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_RSS_1_0 - rc+= raptor_init_serializer_rss10(world) != 0; + rc += raptor_init_serializer_rss10(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_ATOM - rc+= raptor_init_serializer_atom(world) != 0; + rc += raptor_init_serializer_atom(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_DOT - rc+= raptor_init_serializer_dot(world) != 0; + rc += raptor_init_serializer_dot(world) != 0; #endif #ifdef RAPTOR_SERIALIZER_JSON - rc+= raptor_init_serializer_json(world) != 0; + rc += raptor_init_serializer_json(world) != 0; #endif return rc; @@ -152,97 +141,72 @@ raptor_serializers_finish(raptor_world* world) * Return value: non-0 on failure **/ RAPTOR_EXTERN_C -int +raptor_serializer_factory* raptor_serializer_register_factory(raptor_world* world, - const char *name, const char *label, - const char *mime_type, - const char *alias, - const unsigned char *uri_string, int (*factory) (raptor_serializer_factory*)) { raptor_serializer_factory *serializer; - char *name_copy, *label_copy, *mime_type_copy, *alias_copy; - unsigned char *uri_string_copy; - int i; - -#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 - RAPTOR_DEBUG4("Received registration for syntax serializer %s '%s' with alias '%s'\n", - name, label, (alias ? alias : "none")); - RAPTOR_DEBUG3("MIME type %s, URI %s\n", - (mime_type ? mime_type : "none"), - (uri_string ? (const char *)uri_string : "none")); -#endif - - for(i = 0; - (serializer = (raptor_serializer_factory*)raptor_sequence_get_at(world->serializers, i)); - i++) { - if(!strcmp(serializer->name, name)) { - RAPTOR_FATAL2("serializer %s already registered\n", name); - return 1; - } - } - serializer = (raptor_serializer_factory*)RAPTOR_CALLOC(raptor_serializer_factory, 1, sizeof(*serializer)); if(!serializer) - return 1; + return NULL; serializer->world = world; - name_copy = (char*)RAPTOR_CALLOC(cstring, strlen(name)+1, 1); - if(!name_copy) - goto tidy; - strcpy(name_copy, name); - serializer->name = name_copy; - - label_copy = (char*)RAPTOR_CALLOC(cstring, strlen(label)+1, 1); - if(!label_copy) - goto tidy; - strcpy(label_copy, label); - serializer->label = label_copy; - - if(mime_type) { - mime_type_copy = (char*)RAPTOR_CALLOC(cstring, strlen(mime_type)+1, 1); - if(!mime_type_copy) - goto tidy; - strcpy(mime_type_copy, mime_type); - serializer->mime_type = mime_type_copy; - } - - if(uri_string) { - uri_string_copy = (unsigned char*)RAPTOR_CALLOC(cstring, strlen((const char*)uri_string)+1, 1); - if(!uri_string_copy) - goto tidy; - strcpy((char*)uri_string_copy, (const char*)uri_string); - serializer->uri_string = uri_string_copy; - } - - if(alias) { - alias_copy = (char*)RAPTOR_CALLOC(cstring, strlen(alias)+1, 1); - if(!alias_copy) - goto tidy; - strcpy(alias_copy, alias); - serializer->alias = alias_copy; - } - + serializer->desc.mime_types = NULL; + if(raptor_sequence_push(world->serializers, serializer)) - return 1; /* on error, serializer is already freed by the sequence */ + return NULL; /* on error, serializer is already freed by the sequence */ /* Call the serializer registration function on the new object */ if(factory(serializer)) - return 1; /* serializer is owned and freed by the serializers sequence */ + return NULL; /* serializer is owned and freed by the serializers sequence */ + if(!serializer->desc.names || !serializer->desc.names[0] || + !serializer->desc.label) { + raptor_log_error(world, RAPTOR_LOG_LEVEL_ERROR, NULL, + "Serializer failed to register required names and label fields\n"); + goto tidy; + } + +#ifdef RAPTOR_DEBUG + /* Maintainer only check of static data */ + if(serializer->desc.mime_types) { + unsigned int i; + const raptor_type_q* type_q = NULL; + + for(i = 0; + (type_q = &serializer->desc.mime_types[i]) && type_q->mime_type; + i++) { + size_t len = strlen(type_q->mime_type); + if(len != type_q->mime_type_len) { + fprintf(stderr, + "Serializer %s mime type %s actual len %d static len %d\n", + serializer->desc.names[0], type_q->mime_type, + (int)len, (int)type_q->mime_type_len); + } + } + + if(i != serializer->desc.mime_types_count) { + fprintf(stderr, + "Serializer %s saw %d mime types static count %d\n", + serializer->desc.names[0], i, serializer->desc.mime_types_count); + } + } +#endif + #if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1 - RAPTOR_DEBUG3("%s has context size %d\n", name, serializer->context_length); + RAPTOR_DEBUG3("Registered serializer %s with context size %d\n", + serializer->names[0], serializer->context_length); #endif - return 0; + return serializer; /* Clean up on failure */ tidy: raptor_free_serializer_factory(serializer); - return 1; + return NULL; } @@ -258,7 +222,7 @@ raptor_serializer_register_factory(raptor_world* world, static raptor_serializer_factory* raptor_get_serializer_factory(raptor_world* world, const char *name) { - raptor_serializer_factory *factory; + raptor_serializer_factory *factory = NULL; /* return 1st serializer if no particular one wanted - why? */ if(!name) { @@ -273,16 +237,15 @@ raptor_get_serializer_factory(raptor_world* world, const char *name) for(i = 0; (factory = (raptor_serializer_factory*)raptor_sequence_get_at(world->serializers, i)); i++) { - if(!strcmp(factory->name, name) || - (factory->alias && !strcmp(factory->alias, name))) + int namei; + const char* fname; + + for(namei = 0; (fname = factory->desc.names[namei]); namei++) { + if(!strcmp(fname, name)) + break; + } + if(fname) break; - - } - - /* else FACTORY name not found */ - if(!factory) { - RAPTOR_DEBUG2("No serializer with name %s found\n", name); - return NULL; } } @@ -291,24 +254,17 @@ raptor_get_serializer_factory(raptor_world* world, const char *name) /** - * raptor_world_enumerate_serializers: - * @world: raptor_world object - * @counter: index into the list of syntaxes - * @name: pointer to store the name of the syntax (or NULL) - * @label: pointer to store syntax readable label (or NULL) - * @mime_type: pointer to store syntax MIME Type (or NULL) - * @uri_string: pointer to store syntax URI string (or NULL) + * raptor_world_get_serializer_description: + * @world: world object + * @counter: index into the list of serializers * - * Get information on syntax serializers. + * Get serializer descriptive syntax information * - * Return value: non 0 on failure of if counter is out of range + * Return value: description or NULL if counter is out of range **/ -int -raptor_world_enumerate_serializers(raptor_world* world, - const unsigned int counter, - const char **name, const char **label, - const char **mime_type, - const unsigned char **uri_string) +const raptor_syntax_description* +raptor_world_get_serializer_description(raptor_world* world, + const unsigned int counter) { raptor_serializer_factory *factory; @@ -316,18 +272,9 @@ raptor_world_enumerate_serializers(raptor_world* world, counter); if(!factory) - return 1; - - if(name) - *name=factory->name; - if(label) - *label=factory->label; - if(mime_type) - *mime_type=factory->mime_type; - if(uri_string) - *uri_string=factory->uri_string; + return NULL; - return 0; + return &factory->desc; } @@ -796,3 +743,22 @@ raptor_serializer_get_world(raptor_serializer* rdf_serializer) { return rdf_serializer->world; } + + +/** + * raptor_serializer_get_description: + * @rdf_serializer: #raptor_serializer serializer object + * + * Get description of the syntaxes of the serializer. + * + * The returned description is static and lives as long as the raptor + * library (raptor world). + * + * Return value: description of syntax + **/ +const raptor_syntax_description* +raptor_serializer_get_description(raptor_serializer *rdf_serializer) +{ + return &rdf_serializer->factory->desc; +} + diff --git a/src/raptor_serialize_dot.c b/src/raptor_serialize_dot.c index ee81f0f5..aa3d5ddb 100644 --- a/src/raptor_serialize_dot.c +++ b/src/raptor_serialize_dot.c @@ -541,9 +541,24 @@ raptor_dot_serializer_statement(raptor_serializer* serializer, } +static const char* dot_names[3] = { "dot", NULL}; + +#define DOT_TYPES_COUNT 1 +static const raptor_type_q dot_types[DOT_TYPES_COUNT + 1] = { + { "text/x-graphviz", 15, 5}, + { NULL, 0, 0} +}; + static int raptor_dot_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = dot_names; + factory->desc.mime_types = dot_types; + factory->desc.mime_types_count = DOT_TYPES_COUNT; + + factory->desc.label = "GraphViz DOT format"; + factory->desc.uri_string = "http://www.graphviz.org/doc/info/lang.html"; + factory->context_length = sizeof(raptor_dot_context); factory->init = raptor_dot_serializer_init; @@ -563,11 +578,6 @@ raptor_dot_serializer_register_factory(raptor_serializer_factory *factory) int raptor_init_serializer_dot(raptor_world* world) { - return raptor_serializer_register_factory(world, - "dot", - "GraphViz DOT format", - "text/x-graphviz", - NULL, - (const unsigned char*)"http://www.graphviz.org/doc/info/lang.html", - &raptor_dot_serializer_register_factory); + return !raptor_serializer_register_factory(world, + &raptor_dot_serializer_register_factory); } diff --git a/src/raptor_serialize_json.c b/src/raptor_serialize_json.c index 0398284a..2cfef615 100644 --- a/src/raptor_serialize_json.c +++ b/src/raptor_serialize_json.c @@ -461,9 +461,24 @@ raptor_json_serialize_finish_factory(raptor_serializer_factory* factory) +static const char* json_triples_names[3] = { "json-triples", NULL}; + +#define JSON_TRIPLES_TYPES_COUNT 1 +static const raptor_type_q json_triples_types[JSON_TRIPLES_TYPES_COUNT + 1] = { + { "application/json", 16, 0}, + { NULL, 0, 0} +}; + static int raptor_json_triples_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = json_triples_names; + factory->desc.mime_types = json_triples_types; + factory->desc.mime_types_count = JSON_TRIPLES_TYPES_COUNT; + + factory->desc.label = "RDF/JSON Triples"; + factory->desc.uri_string = NULL; + factory->context_length = sizeof(raptor_json_context); factory->init = raptor_json_serialize_init; @@ -479,9 +494,24 @@ raptor_json_triples_serializer_register_factory(raptor_serializer_factory *facto } +static const char* json_resource_names[3] = { "json", NULL}; + +#define JSON_RESOURCE_TYPES_COUNT 1 +static const raptor_type_q json_resource_types[JSON_RESOURCE_TYPES_COUNT + 1] = { + { "application/json", 16, 0}, + { NULL, 0, 0} +}; + static int raptor_json_resource_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = json_resource_names; + factory->desc.mime_types = json_resource_types; + factory->desc.mime_types_count = JSON_RESOURCE_TYPES_COUNT; + + factory->desc.label = "RDF/JSON Resource-Centric"; + factory->desc.uri_string = "http://n2.talis.com/wiki/RDF_JSON_Specification"; + factory->context_length = sizeof(raptor_json_context); factory->init = raptor_json_serialize_init; @@ -502,21 +532,13 @@ raptor_init_serializer_json(raptor_world* world) { int rc; - rc = raptor_serializer_register_factory(world, - "json-triples", - "RDF/JSON Triples", - "application/json", - NULL, - NULL, - &raptor_json_triples_serializer_register_factory); + rc = !raptor_serializer_register_factory(world, + &raptor_json_triples_serializer_register_factory); if(rc) return rc; - return raptor_serializer_register_factory(world, - "json", - "RDF/JSON Resource-Centric", - "application/json", - NULL, - (const unsigned char *)"http://n2.talis.com/wiki/RDF_JSON_Specification", - &raptor_json_resource_serializer_register_factory); + rc = !raptor_serializer_register_factory(world, + &raptor_json_resource_serializer_register_factory); + + return rc; } diff --git a/src/raptor_serialize_ntriples.c b/src/raptor_serialize_ntriples.c index b6d544e2..9a52ef0d 100644 --- a/src/raptor_serialize_ntriples.c +++ b/src/raptor_serialize_ntriples.c @@ -224,9 +224,24 @@ raptor_ntriples_serialize_finish_factory(raptor_serializer_factory* factory) } +static const char* ntriples_names[3] = { "ntriples", NULL}; + +#define NTRIPLES_TYPES_COUNT 1 +static const raptor_type_q ntriples_types[NTRIPLES_TYPES_COUNT + 1] = { + { "application/rdf+xml", 19, 0}, + { NULL, 0, 0} +}; + static int raptor_ntriples_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = ntriples_names; + factory->desc.mime_types = ntriples_types; + factory->desc.mime_types_count = NTRIPLES_TYPES_COUNT; + + factory->desc.label = "N-Triples"; + factory->desc.uri_string = "http://www.w3.org/TR/rdf-testcases/#ntriples"; + factory->context_length = sizeof(raptor_ntriples_serializer_context); factory->init = raptor_ntriples_serialize_init; @@ -242,13 +257,10 @@ raptor_ntriples_serializer_register_factory(raptor_serializer_factory *factory) int -raptor_init_serializer_ntriples(raptor_world* world) { - return raptor_serializer_register_factory(world, - "ntriples", "N-Triples", - "text/plain", - NULL, - (const unsigned char*)"http://www.w3.org/TR/rdf-testcases/#ntriples", - &raptor_ntriples_serializer_register_factory); +raptor_init_serializer_ntriples(raptor_world* world) +{ + return !raptor_serializer_register_factory(world, + &raptor_ntriples_serializer_register_factory); } diff --git a/src/raptor_serialize_rdfxml.c b/src/raptor_serialize_rdfxml.c index a6d17102..a0c61f99 100644 --- a/src/raptor_serialize_rdfxml.c +++ b/src/raptor_serialize_rdfxml.c @@ -697,9 +697,24 @@ raptor_rdfxml_serialize_finish_factory(raptor_serializer_factory* factory) } +static const char* rdfxml_names[3] = { "rdfxml", NULL}; + +#define RDFXML_TYPES_COUNT 1 +static const raptor_type_q rdfxml_types[RDFXML_TYPES_COUNT + 1] = { + { "application/rdf+xml", 19, 0}, + { NULL, 0, 0} +}; + static int raptor_rdfxml_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = rdfxml_names; + factory->desc.mime_types = rdfxml_types; + factory->desc.mime_types_count = RDFXML_TYPES_COUNT; + + factory->desc.label = "RDF/XML"; + factory->desc.uri_string = "http://www.w3.org/TR/rdf-syntax-grammar", + factory->context_length = sizeof(raptor_rdfxml_serializer_context); factory->init = raptor_rdfxml_serialize_init; @@ -717,13 +732,10 @@ raptor_rdfxml_serializer_register_factory(raptor_serializer_factory *factory) int -raptor_init_serializer_rdfxml(raptor_world* world) { - return raptor_serializer_register_factory(world, - "rdfxml", "RDF/XML", - "application/rdf+xml", - NULL, - (const unsigned char*)"http://www.w3.org/TR/rdf-syntax-grammar", - &raptor_rdfxml_serializer_register_factory); +raptor_init_serializer_rdfxml(raptor_world* world) +{ + return !raptor_serializer_register_factory(world, + &raptor_rdfxml_serializer_register_factory); } diff --git a/src/raptor_serialize_rdfxmla.c b/src/raptor_serialize_rdfxmla.c index 60281867..9f655939 100644 --- a/src/raptor_serialize_rdfxmla.c +++ b/src/raptor_serialize_rdfxmla.c @@ -1059,7 +1059,7 @@ raptor_rdfxmla_serialize_set_write_rdf_RDF(raptor_serializer* serializer, { raptor_rdfxmla_context* context; - if(strcmp(serializer->factory->name, "rdfxml-abbrev")) + if(strcmp(serializer->factory->desc.names[0], "rdfxml-abbrev")) return 1; context = (raptor_rdfxmla_context*)serializer->context; @@ -1087,7 +1087,7 @@ raptor_rdfxmla_serialize_set_xml_writer(raptor_serializer* serializer, { raptor_rdfxmla_context* context; - if(strcmp(serializer->factory->name, "rdfxml-abbrev")) + if(strcmp(serializer->factory->desc.names[0], "rdfxml-abbrev")) return 1; context = (raptor_rdfxmla_context*)serializer->context; @@ -1130,7 +1130,7 @@ raptor_rdfxmla_serialize_set_single_node(raptor_serializer* serializer, { raptor_rdfxmla_context* context; - if(strcmp(serializer->factory->name, "rdfxml-abbrev")) + if(strcmp(serializer->factory->desc.names[0], "rdfxml-abbrev")) return 1; context = (raptor_rdfxmla_context*)serializer->context; @@ -1159,7 +1159,7 @@ raptor_rdfxmla_serialize_set_write_typed_nodes(raptor_serializer* serializer, { raptor_rdfxmla_context* context; - if(strcmp(serializer->factory->name, "rdfxml-abbrev")) + if(strcmp(serializer->factory->desc.names[0], "rdfxml-abbrev")) return 1; context = (raptor_rdfxmla_context*)serializer->context; @@ -1484,9 +1484,57 @@ raptor_rdfxmla_serialize_finish_factory(raptor_serializer_factory* factory) } +static const char* rdfxml_xmp_names[3] = { "rdfxml-xmp", NULL}; + +#define RDFXML_XMP_TYPES_COUNT 1 +static const raptor_type_q rdfxml_xmp_types[RDFXML_XMP_TYPES_COUNT + 1] = { + { "application/rdf+xml", 19, 0}, + { NULL, 0, 0} +}; + +static int +raptor_rdfxml_xmp_serializer_register_factory(raptor_serializer_factory *factory) +{ + factory->desc.names = rdfxml_xmp_names; + factory->desc.mime_types = rdfxml_xmp_types; + factory->desc.mime_types_count = RDFXML_XMP_TYPES_COUNT; + + factory->desc.label = "RDF/XML (XMP Profile)"; + factory->desc.uri_string = "http://www.w3.org/TR/rdf-syntax-grammar"; + + factory->context_length = sizeof(raptor_rdfxmla_context); + + factory->init = raptor_rdfxmla_serialize_init; + factory->terminate = raptor_rdfxmla_serialize_terminate; + factory->declare_namespace = raptor_rdfxmla_serialize_declare_namespace; + factory->declare_namespace_from_namespace = raptor_rdfxmla_serialize_declare_namespace_from_namespace; + factory->serialize_start = raptor_rdfxmla_serialize_start; + factory->serialize_statement = raptor_rdfxmla_serialize_statement; + factory->serialize_end = raptor_rdfxmla_serialize_end; + factory->finish_factory = raptor_rdfxmla_serialize_finish_factory; + + return 0; +} + + +static const char* rdfxmla_names[3] = { "rdfxml-abbrev", NULL}; + +#define RDFXMLA_TYPES_COUNT 1 +static const raptor_type_q rdfxmla_types[RDFXMLA_TYPES_COUNT + 1] = { + { "application/rdf+xml", 19, 0}, + { NULL, 0, 0} +}; + static int raptor_rdfxmla_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = rdfxmla_names; + factory->desc.mime_types = rdfxmla_types; + factory->desc.mime_types_count = RDFXMLA_TYPES_COUNT; + + factory->desc.label = "RDF/XML (Abbreviated)"; + factory->desc.uri_string = "http://www.w3.org/TR/rdf-syntax-grammar"; + factory->context_length = sizeof(raptor_rdfxmla_context); factory->init = raptor_rdfxmla_serialize_init; @@ -1505,19 +1553,16 @@ raptor_rdfxmla_serializer_register_factory(raptor_serializer_factory *factory) int raptor_init_serializer_rdfxmla(raptor_world* world) { - return - raptor_serializer_register_factory(world, - "rdfxml-xmp", "RDF/XML (XMP Profile)", - "application/rdf+xml", - NULL, - (const unsigned char*)"http://www.w3.org/TR/rdf-syntax-grammar", - &raptor_rdfxmla_serializer_register_factory) - || - raptor_serializer_register_factory(world, - "rdfxml-abbrev", "RDF/XML (Abbreviated)", - "application/rdf+xml", - NULL, - (const unsigned char*)"http://www.w3.org/TR/rdf-syntax-grammar", - &raptor_rdfxmla_serializer_register_factory); + int rc; + + rc = !raptor_serializer_register_factory(world, + &raptor_rdfxml_xmp_serializer_register_factory); + if(rc) + return rc; + + rc = !raptor_serializer_register_factory(world, + &raptor_rdfxmla_serializer_register_factory); + + return rc; } diff --git a/src/raptor_serialize_rss.c b/src/raptor_serialize_rss.c index 5812cc31..073a5595 100644 --- a/src/raptor_serialize_rss.c +++ b/src/raptor_serialize_rss.c @@ -2189,9 +2189,58 @@ raptor_rss10_serialize_finish_factory(raptor_serializer_factory* factory) } +static const char* rss10_names[3] = { "rss-1.0", NULL}; + +#define RSS10_TYPES_COUNT 1 +static const raptor_type_q rss10_types[RSS10_TYPES_COUNT + 1] = { + { "application/rss+xml", 19, 10}, + { NULL, 0, 0} +}; + static int raptor_rss10_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = rss10_names; + factory->desc.mime_types = rss10_types; + factory->desc.mime_types_count = RSS10_TYPES_COUNT; + + factory->desc.label = "RSS 1.0"; + factory->desc.uri_string = "http://purl.org/rss/1.0/spec"; + + factory->context_length = sizeof(raptor_rss10_serializer_context); + + factory->init = raptor_rss10_serialize_init; + factory->terminate = raptor_rss10_serialize_terminate; + factory->declare_namespace = raptor_rss10_serialize_declare_namespace; + factory->declare_namespace_from_namespace = raptor_rss10_serialize_declare_namespace_from_namespace; + factory->serialize_start = raptor_rss10_serialize_start; + factory->serialize_statement = raptor_rss10_serialize_statement; + factory->serialize_end = raptor_rss10_serialize_end; + factory->finish_factory = raptor_rss10_serialize_finish_factory; + + return 0; +} + + + +static const char* atom_names[3] = { "atom", NULL}; + +#define ATOM_TYPES_COUNT 1 +static const raptor_type_q atom_types[ATOM_TYPES_COUNT + 1] = { + { "application/atom+xml", 20, 10}, + { NULL, 0, 0} +}; + +static int +raptor_atom_serializer_register_factory(raptor_serializer_factory *factory) +{ + factory->desc.names = atom_names; + factory->desc.mime_types = atom_types; + factory->desc.mime_types_count = ATOM_TYPES_COUNT; + + factory->desc.label = "Atom 1.0"; + factory->desc.uri_string = NULL; + factory->context_length = sizeof(raptor_rss10_serializer_context); factory->init = raptor_rss10_serialize_init; @@ -2209,22 +2258,16 @@ raptor_rss10_serializer_register_factory(raptor_serializer_factory *factory) int -raptor_init_serializer_rss10(raptor_world* world) { - return raptor_serializer_register_factory(world, - "rss-1.0", "RSS 1.0", - NULL, - NULL, - (const unsigned char*)"http://purl.org/rss/1.0/spec", - &raptor_rss10_serializer_register_factory); +raptor_init_serializer_rss10(raptor_world* world) +{ + return !raptor_serializer_register_factory(world, + &raptor_rss10_serializer_register_factory); } int -raptor_init_serializer_atom(raptor_world* world) { - return raptor_serializer_register_factory(world, - "atom", "Atom 1.0", - "application/atom+xml", - NULL, - NULL, - &raptor_rss10_serializer_register_factory); +raptor_init_serializer_atom(raptor_world* world) +{ + return !raptor_serializer_register_factory(world, + &raptor_atom_serializer_register_factory); } diff --git a/src/raptor_serialize_simple.c b/src/raptor_serialize_simple.c index 34c56c62..fa64f864 100644 --- a/src/raptor_serialize_simple.c +++ b/src/raptor_serialize_simple.c @@ -138,9 +138,23 @@ raptor_simple_serialize_finish_factory(raptor_serializer_factory* factory) } +static const char* simple_names[3] = { "simple", NULL}; + +#define SIMPLE_TYPES_COUNT 0 +static const raptor_type_q simple_types[SIMPLE_TYPES_COUNT + 1] = { + { NULL, 0, 0} +}; + static int raptor_simple_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = simple_names; + factory->desc.mime_types = simple_types; + factory->desc.mime_types_count = SIMPLE_TYPES_COUNT; + + factory->desc.label = "A simple format"; + factory->desc.uri_string = NULL; + factory->context_length = sizeof(raptor_simple_serializer_context); factory->init = raptor_simple_serialize_init; @@ -156,11 +170,8 @@ raptor_simple_serializer_register_factory(raptor_serializer_factory *factory) int -raptor_init_serializer_simple(raptor_world* world) { - return raptor_serializer_register_factory(world, - "simple", "A simple format", - NULL, - NULL, - NULL, - &raptor_simple_serializer_register_factory); +raptor_init_serializer_simple(raptor_world* world) +{ + return !raptor_serializer_register_factory(world, + &raptor_simple_serializer_register_factory); } diff --git a/src/raptor_serialize_turtle.c b/src/raptor_serialize_turtle.c index e87a6931..2a71d8f5 100644 --- a/src/raptor_serialize_turtle.c +++ b/src/raptor_serialize_turtle.c @@ -1136,9 +1136,24 @@ raptor_turtle_serialize_finish_factory(raptor_serializer_factory* factory) } +static const char* turtle_names[3] = { "turtle", NULL}; + +#define TURTLE_TYPES_COUNT 1 +static const raptor_type_q turtle_types[TURTLE_TYPES_COUNT + 1] = { + { "application/x-turtle", 20, 10}, + { NULL, 0, 0} +}; + static int raptor_turtle_serializer_register_factory(raptor_serializer_factory *factory) { + factory->desc.names = turtle_names; + factory->desc.mime_types = turtle_types; + factory->desc.mime_types_count = TURTLE_TYPES_COUNT; + + factory->desc.label = "Turtle"; + factory->desc.uri_string = "http://www.dajobe.org/2004/01/turtle"; + factory->context_length = sizeof(raptor_turtle_context); factory->init = raptor_turtle_serialize_init; @@ -1157,11 +1172,7 @@ raptor_turtle_serializer_register_factory(raptor_serializer_factory *factory) int raptor_init_serializer_turtle(raptor_world* world) { - return raptor_serializer_register_factory(world, - "turtle", "Turtle", - "application/x-turtle", - NULL, - (const unsigned char*)"http://www.dajobe.org/2004/01/turtle", - &raptor_turtle_serializer_register_factory); + return !raptor_serializer_register_factory(world, + &raptor_turtle_serializer_register_factory); } diff --git a/utils/rapper.c b/utils/rapper.c index ef107ece..f39d059a 100644 --- a/utils/rapper.c +++ b/utils/rapper.c @@ -559,13 +559,11 @@ main(int argc, char *argv[]) program, optarg); fprintf(stderr, "Valid arguments are:\n"); for(i = 0; 1; i++) { - const char *help_name; - const char *help_label; - if(raptor_world_enumerate_serializers(world, i, - &help_name, &help_label, - NULL, NULL)) + const raptor_syntax_description* sd; + sd = raptor_world_get_serializer_description(world, i); + if(!sd) break; - fprintf(stderr, " %-14s for %s\n", help_name, help_label); + fprintf(stderr, " %-14s for %s\n", sd->names[0], sd->label); } usage = 1; break; @@ -701,12 +699,11 @@ main(int argc, char *argv[]) puts(HELP_TEXT("o FORMAT", "output FORMAT", "Set the output format/serializer to one of:")); for(i = 0; 1; i++) { - const char *help_name; - const char *help_label; - if(raptor_world_enumerate_serializers(world, i, &help_name, &help_label, - NULL, NULL)) + const raptor_syntax_description* sd; + sd = raptor_world_get_parser_description(world, i); + if(!sd) break; - printf(" %-14s %s", help_name, help_label); + printf(" %-14s %s", sd->names[0], sd->label); if(!i) puts(" (default)"); else |