[tracker/regions-of-interest] libtracker-extract: handle correctly XMP namespaces



commit 0b0a50f7751880779695bc50d11d54eb70472a19
Author: Ivan Frade <ivan frade gmail com>
Date:   Mon Aug 1 16:02:16 2011 +0300

    libtracker-extract: handle correctly XMP namespaces
    
    We instruct XMP to use a known prefix for the namespaces, so we can
    use it in the comparison in the code

 src/libtracker-extract/tracker-xmp.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-xmp.c b/src/libtracker-extract/tracker-xmp.c
index a270a2f..beddcc3 100644
--- a/src/libtracker-extract/tracker-xmp.c
+++ b/src/libtracker-extract/tracker-xmp.c
@@ -29,6 +29,8 @@
 #ifdef HAVE_EXEMPI
 
 #define NS_XMP_REGIONS "http://www.metadataworkinggroup.com/schemas/regions/";
+#define NS_ST_DIM "http://ns.adobe.com/xap/1.0/sType/Dimensions#";
+#define NS_ST_AREA "http://ns.adobe.com/xap/1.0/sType/Area#";
 
 #include <exempi/xmp.h>
 #include <exempi/xmpconsts.h>
@@ -501,9 +503,6 @@ iterate_simple (const gchar    *uri,
 			data->rating = g_strdup (value);
 		}
 	} else if (g_ascii_strcasecmp (schema, NS_XMP_REGIONS) == 0) {
-                /*
-                 *  FIXME: Is wrong to assume the namespace is mwg-rs, stArea and stDim
-                 */
                 if (g_str_has_prefix (path, "mwg-rs:Regions/mwg-rs:RegionList")) {
                         current_region = g_list_nth_data (data->regions, 0);
 
@@ -527,6 +526,8 @@ iterate_simple (const gchar    *uri,
                                    } else if (!current_region->unit 
                                               && g_ascii_strcasecmp (propname, "stArea:unit") == 0) {
                                    current_region->unit = g_strdup (value);
+
+                                   we consider it always comes normalized
                                 */
 
                         } else if (!current_region->type && g_ascii_strcasecmp (propname, "mwg-rs:Type") == 0) {
@@ -534,9 +535,7 @@ iterate_simple (const gchar    *uri,
                         } else if (g_str_has_prefix (strrchr (path, ']') + 2, "mwg-rs:Extensions")) {
                                 current_region->link_class = g_strdup (propname);
                                 current_region->link_uri = g_strdup (value);
-                        } else {
-                                g_debug ("(unhandled)  prop: %s (%s)\n", path, value);
-                        }
+                        } 
                 }
         }
 	g_free (name);
@@ -549,8 +548,6 @@ iterate_complex_element (TrackerXmpData *data, const gchar *schema, const gchar
 
         /* When we go into an Area, we put a region on the stack 
          *  further statements will put values in that region. 
-         *
-         *  FIXME: Is wrong to assume the namespace is mwg-rs
          */
         if (g_str_has_suffix (path, "mwg-rs:Area")) {
                 region = g_new0 (TrackerXmpRegion, 1);
@@ -571,6 +568,7 @@ iterate (XmpPtr          xmp,
 	XmpStringPtr the_schema = xmp_string_new ();
 	XmpStringPtr the_path = xmp_string_new ();
 	XmpStringPtr the_prop = xmp_string_new ();
+
 	uint32_t opt;
 
 	while (xmp_iterator_next (iter, the_schema, the_path, the_prop, &opt)) {
@@ -596,7 +594,7 @@ iterate (XmpPtr          xmp,
                                    In those cases, to avoid duplicated values, is easier
                                    to skip the subtree 
                                 */
-                                if (g_str_has_prefix (path, "dc:")) {
+                                if (g_ascii_strcasecmp (schema, NS_DC) == 0) {
                                         xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE);
                                 }
 			}
@@ -610,6 +608,15 @@ iterate (XmpPtr          xmp,
 	xmp_string_free (the_schema);
 }
 
+
+static void
+register_namespace (const gchar *ns_uri, const gchar *suggested_prefix)
+{
+        if (!xmp_namespace_prefix (ns_uri, NULL)) {
+                xmp_register_namespace (ns_uri, suggested_prefix, NULL);
+        }     
+}
+
 #endif /* HAVE_EXEMPI */
 
 static gboolean
@@ -627,6 +634,10 @@ parse_xmp (const gchar    *buffer,
 #ifdef HAVE_EXEMPI
 
 	xmp_init ();
+        
+        register_namespace (NS_XMP_REGIONS, "mwg-rs");
+        register_namespace (NS_ST_DIM, "stDim");
+        register_namespace (NS_ST_AREA, "stArea");
 
 	xmp = xmp_new_empty ();
 	xmp_parse (xmp, buffer, len);



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