[tracker/wip/carlosg/resources-as-cursors: 6/9] libtracker-sparql: Handle JSON-LD pretty TrackerResource printing specially
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/resources-as-cursors: 6/9] libtracker-sparql: Handle JSON-LD pretty TrackerResource printing specially
- Date: Tue, 12 Jul 2022 21:25:26 +0000 (UTC)
commit 6e8f156d65f67dbdbb3aacbb78f5b67e56225caa
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jul 11 20:35:02 2022 +0200
libtracker-sparql: Handle JSON-LD pretty TrackerResource printing specially
Since we return a very ugly JSON-LD document (i.e. not indented), and
a large usecase of the tracker_resource_print_rdf() function is to print
output that is easily human readable, make it sure that the JSON-LD
document is pretty printed.
src/libtracker-sparql/tracker-resource.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 7231968d9..6f2193285 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -1708,7 +1708,6 @@ tracker_resource_print_rdf (TrackerResource *self,
g_return_val_if_fail (TRACKER_IS_NAMESPACE_MANAGER (namespaces), NULL);
g_return_val_if_fail (format < TRACKER_N_RDF_FORMATS, NULL);
-#define BUF_SIZE 4096
deserializer = tracker_deserializer_resource_new (self, namespaces, graph);
serializer = tracker_serializer_new (TRACKER_SPARQL_CURSOR (deserializer),
namespaces,
@@ -1717,6 +1716,34 @@ tracker_resource_print_rdf (TrackerResource *self,
str = g_string_new (NULL);
+ if (format == TRACKER_RDF_FORMAT_JSON_LD) {
+ JsonParser *parser;
+ JsonGenerator *generator;
+ JsonNode *root;
+
+ /* Special case, ensure that json is pretty printed */
+ parser = json_parser_new ();
+
+ if (!json_parser_load_from_stream (parser,
+ serializer,
+ NULL,
+ NULL)) {
+ g_object_unref (parser);
+ return g_string_free (str, FALSE);
+ }
+
+ generator = json_generator_new ();
+ root = json_parser_get_root (parser);
+ json_generator_set_root (generator, root);
+ json_generator_set_pretty (generator, TRUE);
+ json_generator_to_gstring (generator, str);
+ g_object_unref (generator);
+ g_object_unref (parser);
+
+ return g_string_free (str, FALSE);
+ }
+
+#define BUF_SIZE 4096
while (TRUE) {
GBytes *bytes;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]