[tracker] Support to translate class uris into links inside documentation
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Support to translate class uris into links inside documentation
- Date: Sat, 14 Nov 2009 17:52:43 +0000 (UTC)
commit dede46c8a8be837493ca80b5323af384d56c8f08
Author: Ivan Frade <ivan frade nokia com>
Date: Fri Nov 13 14:00:56 2009 +0200
Support to translate class uris into links inside documentation
utils/services/qname-test.c | 52 +++++++++++++++++++++++++++-
utils/services/qname.c | 79 +++++++++++++++++++++++++++++++++++++------
utils/services/qname.h | 2 +
3 files changed, 121 insertions(+), 12 deletions(-)
---
diff --git a/utils/services/qname-test.c b/utils/services/qname-test.c
index 535cc5e..1efee86 100644
--- a/utils/services/qname-test.c
+++ b/utils/services/qname-test.c
@@ -24,6 +24,50 @@ test_qname_to_shortname (void)
g_free (result);
}
+static void
+test_qname_to_classname (void)
+{
+ gchar *result = NULL;
+
+ result = qname_to_classname ("http://purl.org/dc/elements/1.1/source");
+ g_assert_cmpstr (result, ==, "source");
+ g_free (result);
+
+ result = qname_to_classname ("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#InformationElement");
+ g_assert_cmpstr (result, ==, "InformationElement");
+ g_free (result);
+
+ result = qname_to_classname ("test://local_uri#Class");
+ g_assert_cmpstr (result, ==, "Class");
+ g_free (result);
+
+ result = qname_to_classname ("test://doesnt_exists#Class");
+ g_assert_cmpstr (result, ==, "test://doesnt_exists#Class");
+ g_free (result);
+}
+
+static void
+test_qname_to_link (void)
+{
+ gchar *result = NULL;
+
+ result = qname_to_link ("test://local_uri#Class");
+ g_assert_cmpstr (result, ==, "#Class");
+ g_free (result);
+
+ result = qname_to_link ("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#InformationElement");
+ g_assert_cmpstr (result, ==, "../nie/index.html#InformationElement");
+ g_free (result);
+
+ /* This is one of the special cases, where the prefix of the class
+ * doesn't match with the prefix of the file where it is defined
+ */
+ result = qname_to_link ("http://www.tracker-project.org/ontologies/tracker#Namespace");
+ g_assert_cmpstr (result, ==, "../rdf/index.html#Namespace");
+ g_free (result);
+
+}
+
int
main (int argc, char **argv)
{
@@ -32,11 +76,17 @@ main (int argc, char **argv)
g_type_init ();
g_test_init (&argc, &argv, NULL);
- qname_init ("test://local_uri#", "local", NULL);
+ qname_init ("test://local_uri#", "local", "./file-class.cache.test");
g_test_add_func ("/html_generator/qname/qname_to_shortname",
test_qname_to_shortname);
+ g_test_add_func ("/html_generator/qname/qname_to_classname",
+ test_qname_to_classname);
+
+ g_test_add_func ("/html_generator/qname/qname_to_link",
+ test_qname_to_link);
+
result = g_test_run ();
qname_shutdown ();
diff --git a/utils/services/qname.c b/utils/services/qname.c
index 3386940..def776a 100644
--- a/utils/services/qname.c
+++ b/utils/services/qname.c
@@ -1,5 +1,6 @@
#include "qname.h"
-#include <gio/gio.h>
+#include <glib/gstdio.h>
+#include <string.h>
//static gchar *local_uri = NULL;
//static gchar *local_prefix = NULL;
@@ -9,6 +10,8 @@ typedef struct {
gchar *uri;
} Namespace;
+static GHashTable *class_deffile = NULL;
+
Namespace NAMESPACES [] = {
{NULL, NULL}, /* Save this for the local_uri and prefix */
{"dc", "http://purl.org/dc/elements/1.1/"},
@@ -41,26 +44,46 @@ qname_init (const gchar *luri, const gchar *lprefix, const gchar *class_location
g_warning ("Reinitializing qname_module");
g_free (NAMESPACES[0].namespace);
g_free (NAMESPACES[0].uri);
+ if (class_deffile) {
+ g_hash_table_destroy (class_deffile);
+ }
}
+
NAMESPACES[0].uri = g_strdup (luri);
NAMESPACES[0].namespace = (lprefix != NULL ? g_strdup (lprefix) : g_strdup (""));
if (class_location) {
- /* TODO */
- GFile *file;
+ /* Process a file that contains: dir class pairs by line
+ */
gint i;
- gchar **contents;
+ gchar *raw_content = NULL;
+ gchar **lines;
gsize length;
-
- file = g_file_new_for_commandline_arg (class_location);
- if (!g_file_load_contents (file, NULL, contents, &length, NULL, NULL)) {
+
+ if (!g_file_get_contents (class_location, &raw_content, &length, NULL)) {
g_error ("Unable to load '%s'", class_location);
}
-
- for (i = 0; contents[i] != NULL; i++) {
- g_print ("%s\n", contents[i]);
+
+ class_deffile = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
+
+ lines = g_strsplit (raw_content, "\n", -1);
+ for (i = 0; lines[i] != NULL; i++) {
+ if (strlen (lines[i]) < 1) {
+ continue;
+ }
+
+ gchar **pieces = NULL;
+
+ pieces = g_strsplit (lines[i], " ", -1);
+ g_assert (g_strv_length (pieces) == 2);
+ g_hash_table_insert (class_deffile, pieces[1], pieces[0]);
+
}
-
+ g_strfreev (lines);
+ g_free (raw_content);
}
}
@@ -70,6 +93,9 @@ qname_shutdown (void)
{
g_free (NAMESPACES[0].namespace);
g_free (NAMESPACES[0].uri);
+ if (class_deffile) {
+ g_hash_table_destroy (class_deffile);
+ }
}
gchar *
@@ -88,6 +114,17 @@ qname_to_link (const gchar *qname)
return name;
}
}
+
+ if (class_deffile) {
+ gchar *dir, *shortname;
+ shortname = qname_to_shortname (qname);
+ dir = g_hash_table_lookup (class_deffile, shortname);
+ g_free (shortname);
+ if (dir) {
+ return g_strdup_printf ("../%s/index.html#%s",
+ dir, qname_to_classname (qname));
+ }
+ }
return g_strdup (qname);
}
@@ -138,6 +175,26 @@ qname_to_shortname (const gchar *qname)
}
}
+gchar *
+qname_to_classname (const gchar *qname) {
+
+ gchar *shortname;
+ gchar **pieces;
+ gchar *classname = NULL;
+
+ shortname = qname_to_shortname (qname);
+ if (g_strcmp0 (qname, shortname) == 0) {
+ return shortname;
+ }
+ pieces = g_strsplit (shortname, ":", -1);
+ g_assert (g_strv_length (pieces) == 2);
+
+ classname = g_strdup (pieces[1]);
+ g_strfreev (pieces);
+ g_free (shortname);
+ return classname;
+}
+
gboolean
qname_is_basic_type (const gchar *qname)
{
diff --git a/utils/services/qname.h b/utils/services/qname.h
index 31660a9..dbeca59 100644
--- a/utils/services/qname.h
+++ b/utils/services/qname.h
@@ -12,6 +12,8 @@ void qname_shutdown (void);
gchar * qname_to_link (const gchar *qname);
gchar * qname_to_shortname (const gchar *qname);
+gchar * qname_to_classname (const gchar *qname);
+
gboolean qname_is_basic_type (const gchar *qname);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]