[tracker] Handle special DC case in full-uri to prefix:uri translation



commit 250da91e1f6978851c579088cdb60841133358f7
Author: Ivan Frade <ivan frade nokia com>
Date:   Fri Nov 13 12:54:38 2009 +0200

    Handle special DC case in full-uri to prefix:uri translation

 utils/services/Makefile.am  |    9 +++++++-
 utils/services/qname-test.c |   48 +++++++++++++++++++++++++++++++++++++++++++
 utils/services/qname.c      |   35 +++++++++++++++++++++++++++++-
 3 files changed, 89 insertions(+), 3 deletions(-)
---
diff --git a/utils/services/Makefile.am b/utils/services/Makefile.am
index f622559..ad6b9d2 100644
--- a/utils/services/Makefile.am
+++ b/utils/services/Makefile.am
@@ -1,6 +1,8 @@
 include $(top_srcdir)/Makefile.decl
 
-noinst_PROGRAMS = ontology-validator ttl2html data-validator ttl2graphviz
+noinst_PROGRAMS = ontology-validator ttl2html data-validator ttl2graphviz $(TEST_PROGS)
+
+TEST_PROGS += qname-test
 
 INCLUDES = 								\
 	-DG_LOG_DOMAIN=\"Tracker\"					\
@@ -66,3 +68,8 @@ ttl2graphviz_LDADD = 							\
 	$(DBUS_LIBS)							\
 	$(GLIB2_LIBS)							\
 	$(GIO_LIBS)	
+
+qname_test_SOURCES = qname-test.c qname.c
+qname_test_LDADD = 	$(DBUS_LIBS)					\
+			$(GLIB2_LIBS)					\
+			$(GIO_LIBS)
diff --git a/utils/services/qname-test.c b/utils/services/qname-test.c
new file mode 100644
index 0000000..535cc5e
--- /dev/null
+++ b/utils/services/qname-test.c
@@ -0,0 +1,48 @@
+#include <glib.h>
+#include <qname.h>
+
+
+static void
+test_qname_to_shortname (void) 
+{
+        gchar *result = NULL;
+
+        result = qname_to_shortname ("http://purl.org/dc/elements/1.1/source";);
+        g_assert_cmpstr (result, ==, "dc:source");
+        g_free (result);
+
+        result = qname_to_shortname ("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#InformationElement";);
+        g_assert_cmpstr (result, ==, "nie:InformationElement");
+        g_free (result);
+
+        result = qname_to_shortname ("test://local_uri#Class");
+        g_assert_cmpstr (result, ==, "local:Class");
+        g_free (result);
+
+        result = qname_to_shortname ("test://doesnt_exists#Class");
+        g_assert_cmpstr (result, ==, "test://doesnt_exists#Class");
+        g_free (result);
+}
+
+int
+main (int argc, char **argv)
+{
+	int result;
+
+	g_type_init ();
+	g_test_init (&argc, &argv, NULL);
+
+        qname_init ("test://local_uri#", "local", NULL);
+
+	g_test_add_func ("/html_generator/qname/qname_to_shortname",
+			 test_qname_to_shortname);
+
+	result = g_test_run ();
+
+        qname_shutdown ();
+
+	return result;
+}
+
+
+
diff --git a/utils/services/qname.c b/utils/services/qname.c
index ac3d1a6..3386940 100644
--- a/utils/services/qname.c
+++ b/utils/services/qname.c
@@ -1,4 +1,5 @@
 #include "qname.h"
+#include <gio/gio.h>
 
 //static gchar *local_uri = NULL;
 //static gchar *local_prefix = NULL;
@@ -46,6 +47,20 @@ qname_init (const gchar *luri, const gchar *lprefix, const gchar *class_location
 
         if (class_location) {
                 /* TODO */
+                GFile *file;
+                gint   i;
+                gchar **contents;
+                gsize   length;
+
+                file = g_file_new_for_commandline_arg (class_location);
+                if (!g_file_load_contents (file, NULL, contents, &length, NULL, NULL)) {
+                        g_error ("Unable to load '%s'", class_location);
+                }
+                
+                for (i = 0; contents[i] != NULL; i++) {
+                        g_print ("%s\n", contents[i]);
+                }
+                
         }
 
 }
@@ -86,10 +101,26 @@ qname_to_shortname (const gchar *qname)
 
         for (i = 0; NAMESPACES[i].namespace != NULL; i++) {
                 if (g_str_has_prefix (qname, NAMESPACES[i].uri)) {
+
+
                         pieces = g_strsplit (qname, "#", 2);
                         if (g_strv_length (pieces) != 2) {
-                                g_warning ("Unable to get the shortname for %s", qname);
-                                break;
+
+                                /* Special case for DC. It doesnt use # in the namespace */
+                                if ( g_strcmp0 (NAMESPACES[i].namespace, "dc") == 0) {
+                                        gchar *classname;
+
+                                        g_strfreev (pieces);
+                                        pieces = g_new0 (gchar*, 3);
+
+                                        classname = g_strrstr (qname, "/");
+                                        pieces[0] =  g_strdup ("");
+                                        pieces[1] =  g_strdup (&classname[1]);
+                                        pieces[2] = NULL;
+                                } else {
+                                        g_warning ("Unable to get the shortname for %s", qname);
+                                        break;
+                                }
                         }
 
                         name = g_strdup_printf ("%s:%s", 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]