--- gsf-opendoc-utils.c	2005-12-21 09:28:53.000000000 -0300
+++ gsf-opendoc-utils.c	2005-12-21 16:31:31.891826784 -0300
@@ -26,6 +26,9 @@
 #include <gsf/gsf-opendoc-utils.h>
 #include <gsf/gsf-meta-names.h>
 #include <gsf/gsf-doc-meta-data.h>
+#include <string.h>
+
+#define OFFICE	 "office:"
 
 typedef struct {
 	GsfDocMetaData	*md;
@@ -201,9 +204,65 @@ gsf_opendoc_metadata_subtree (GsfXMLIn *
 		NULL);
 }
 
+static void
+meta_write_props (char *key, GsfDocProp *value, GsfXMLOut *output)
+{
+	const GValue *meta_prop = g_new0(GValue, 1);
+	char *prop_name = strstr (key, "gsf:");
+	
+	if (prop_name != NULL) {//checks existence of "gsf:" and uses "meta:" instead
+		if (!strcmp (prop_name, "gsf:revision-count")) //properties with diferent names
+			prop_name = g_strdup("meta:editing-cycles");
+		else if (!strcmp (prop_name, "gsf:date-created"))
+			prop_name = g_strdup("meta:creation-date");
+		else
+			prop_name = g_strconcat (g_strdup("meta"), g_strdup(strchr (key, ':')), NULL);
+	} else {
+		if (!strcmp (key, "dc:last-printed")) //properties with diferent names
+			prop_name = g_strdup("dc:print-date");
+		else if (!strcmp (key, "dc:date-modified"))
+			prop_name = g_strdup("dc:date");
+		else
+			prop_name = g_strdup (key);
+	}
+	gsf_xml_out_start_element (output, prop_name);
+
+	meta_prop = g_value_init(meta_prop, G_VALUE_TYPE(gsf_doc_prop_get_val (value)));
+	meta_prop = gsf_doc_prop_get_val (value);
+
+	if (G_VALUE_TYPE (meta_prop) == G_TYPE_STRING)
+		gsf_xml_out_add_cstr_unchecked (output, NULL, g_value_get_string (meta_prop));
+	else if (G_VALUE_TYPE (meta_prop) == G_TYPE_UINT)
+		gsf_xml_out_add_uint (output, NULL, g_value_get_uint (meta_prop));
+
+	gsf_xml_out_end_element (output);
+}
+
 gboolean
 gsf_opendoc_metadata_write (GsfXMLOut *output, GsfDocMetaData const *md)
 {
-	/* TODO */
-	return FALSE;
+	if (output == NULL)
+		return FALSE;
+
+	gsf_xml_out_set_doc_type (output, "\n");
+	gsf_xml_out_start_element (output, OFFICE "document-meta");
+	gsf_xml_out_add_cstr_unchecked (output, "xmlns:office",
+		"urn:oasis:names:tc:opendocument:xmlns:office:1.0");
+	gsf_xml_out_add_cstr_unchecked (output, "xmlns:xlink",
+		"http://www.w3.org/1999/xlink");
+	gsf_xml_out_add_cstr_unchecked (output, "xmlns:dc",
+		"http://purl.org/dc/elements/1.1/");
+	gsf_xml_out_add_cstr_unchecked (output, "xmlns:meta",
+		"urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
+	gsf_xml_out_add_cstr_unchecked (output, "xmlns:ooo",
+		"http://openoffice.org/2004/office");
+	gsf_xml_out_add_cstr_unchecked (output, "office:version", "1.0");
+	gsf_xml_out_start_element (output, OFFICE "meta");
+
+	gsf_doc_meta_data_foreach (md, (GHFunc) meta_write_props, output);
+
+	gsf_xml_out_end_element (output); /* </office:meta> */
+	gsf_xml_out_end_element (output); /* </office:document-meta> */
+
+	return TRUE;
 }
