[yelp/yelp-3-0] [libyelp] Allow file paths to page files for Mallard documents



commit 50dc0da5ab045284705fa359e415447cdcd22d58
Author: Shaun McCance <shaunm gnome org>
Date:   Tue Oct 20 09:43:28 2009 -0500

    [libyelp] Allow file paths to page files for Mallard documents
    
    This involved a few fixes to yelp-document and yelp-mallard-document
    for page ID mapping.  Mallard documents never did page ID mapping
    before now.

 libyelp/yelp-document.c         |    2 ++
 libyelp/yelp-mallard-document.c |    9 +++++++--
 libyelp/yelp-uri.c              |   20 +++++++++++++++++++-
 3 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index 202ea7e..50e85ac 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -315,6 +315,8 @@ yelp_document_set_page_id (YelpDocument *document,
 	reqs = hash_lookup (document->priv->reqs_by_page_id, id);
 	for (cur = reqs; cur != NULL; cur = cur->next) {
 	    Request *request = (Request *) cur->data;
+            if (request == NULL)
+                continue;
 	    g_free (request->page_id);
 	    request->page_id = g_strdup (page_id);
 	    hash_slist_insert (document->priv->reqs_by_page_id, page_id, request);
diff --git a/libyelp/yelp-mallard-document.c b/libyelp/yelp-mallard-document.c
index fb69c5e..3cf7feb 100644
--- a/libyelp/yelp-mallard-document.c
+++ b/libyelp/yelp-mallard-document.c
@@ -321,9 +321,11 @@ mallard_think (YelpMallardDocument *mallard)
     g_mutex_lock (priv->mutex);
     priv->state = MALLARD_STATE_IDLE;
     while (priv->pending) {
-        gchar *page_id;
+        gchar *page_id, *real_id;
         page_id = (gchar *) priv->pending->data;
-        mallard_try_run (mallard, page_id);
+        real_id = yelp_document_get_page_id ((YelpDocument *) mallard, page_id);
+        mallard_try_run (mallard, real_id);
+        g_free (real_id);
         g_free (page_id);
         priv->pending = g_slist_delete_link (priv->pending, priv->pending);
     }
@@ -420,6 +422,9 @@ mallard_page_data_walk (MallardPageData *page_data)
         if (xmlStrEqual (page_data->cur->name, BAD_CAST "page")) {
             page_data->page_id = g_strdup ((gchar *) id);
             xmlSetProp (page_data->cache, BAD_CAST "id", id);
+            yelp_document_set_page_id ((YelpDocument *) page_data->mallard,
+                                       g_strrstr (page_data->filename, G_DIR_SEPARATOR_S),
+                                       page_data->page_id);
         } else {
             gchar *newid = g_strdup_printf ("%s#%s", page_data->page_id, id);
             xmlSetProp (page_data->cache, BAD_CAST "id", BAD_CAST newid);
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index 83c1537..3edd748 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -884,7 +884,25 @@ resolve_gfile (YelpUri *uri, const gchar *hash)
             const gchar *mime_type = g_file_info_get_attribute_string (info,
                                                                        G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
             basename = g_file_get_basename (priv->gfile);
-            if (g_str_equal (mime_type, "text/xml") ||
+            if (g_str_has_suffix (basename, ".page")) {
+                GFile *old;
+                priv->tmptype = YELP_URI_DOCUMENT_TYPE_MALLARD;
+                old = priv->gfile;
+                priv->gfile = g_file_get_parent (old);
+                if (priv->page_id == NULL) {
+                    /* File names aren't really page IDs, so we stick an illegal character
+                       on the beginning so it can't possibly be confused with a real page
+                       ID.  Then we let YelpMallardDocument map file names to pages IDs.
+                     */
+                    gchar *tmp = g_file_get_basename (old);
+                    priv->page_id = g_strconcat (G_DIR_SEPARATOR_S, tmp, NULL);
+                    g_free (tmp);
+                }
+                if (priv->frag_id == NULL)
+                    priv->frag_id = g_strdup (hash);
+                g_object_unref (old);
+            }
+            else if (g_str_equal (mime_type, "text/xml") ||
                 g_str_equal (mime_type, "application/docbook+xml") ||
                 g_str_equal (mime_type, "application/xml")) {
                 priv->tmptype = YELP_URI_DOCUMENT_TYPE_DOCBOOK;



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