Exemplo n.º 1
1
static void
gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOut *output)
{
	GObject *val_obj;
	GType    prop_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
	GValue	 value = { 0 };

	g_value_init (&value, prop_type);
	g_object_get_property (G_OBJECT (obj), pspec->name, &value);

	/* No need to save default values */
	if (((pspec->flags & GOG_PARAM_POSITION) &&
	     gog_object_is_default_position_flags (obj, pspec->name)) ||
	    (!(pspec->flags & GOG_PARAM_FORCE_SAVE) &&
	     !(pspec->flags & GOG_PARAM_POSITION) &&
	     g_param_value_defaults (pspec, &value))) {
		g_value_unset (&value);
		return;
	}

	switch (G_TYPE_FUNDAMENTAL (prop_type)) {
	case G_TYPE_CHAR:
	case G_TYPE_UCHAR:
	case G_TYPE_BOOLEAN:
	case G_TYPE_INT:
	case G_TYPE_UINT:
	case G_TYPE_LONG:
	case G_TYPE_ULONG:
	case G_TYPE_ENUM:
	case G_TYPE_FLAGS: {
		GValue str = { 0 };
		g_value_init (&str, G_TYPE_STRING);
		g_value_transform (&value, &str);
		gsf_xml_out_start_element (output, "property");
		gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
		gsf_xml_out_add_cstr (output, NULL, g_value_get_string (&str));
		gsf_xml_out_end_element (output); /* </property> */
		g_value_unset (&str);
		break;
	}

	case G_TYPE_FLOAT:
	case G_TYPE_DOUBLE: {
		GValue vd = { 0 };
		GString *str = g_string_new (NULL);

		g_value_init (&vd, G_TYPE_DOUBLE);
		g_value_transform (&value, &vd);
		go_dtoa (str, "!g", g_value_get_double (&vd));
		g_value_unset (&vd);

		gsf_xml_out_start_element (output, "property");
		gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
		gsf_xml_out_add_cstr (output, NULL, str->str);
		gsf_xml_out_end_element (output); /* </property> */
		g_string_free (str, TRUE);
		break;
	}

	case G_TYPE_STRING: {
		char const *str = g_value_get_string (&value);
		if (str != NULL) {
			gsf_xml_out_start_element (output, "property");
			gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
			gsf_xml_out_add_cstr (output, NULL, str);
			gsf_xml_out_end_element (output); /* </property> */
		}
		break;
	}

	case G_TYPE_OBJECT:
		val_obj = g_value_get_object (&value);
		if (val_obj != NULL) {
			if (GO_IS_PERSIST (val_obj)) {
				gsf_xml_out_start_element (output, "property");
				gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
				go_persist_sax_save (GO_PERSIST (val_obj), output);
				gsf_xml_out_end_element (output); /* </property> */
			} else
				g_warning ("How are we supposed to persist this ??");
		}
		break;

	default:
		g_warning ("I could not persist property \"%s\", since type \"%s\" is unhandled.",
			   g_param_spec_get_name (pspec), g_type_name (G_TYPE_FUNDAMENTAL(prop_type)));
	}
	g_value_unset (&value);
}
Exemplo n.º 2
0
static void
gnm_so_path_write_xml_sax (SheetObject const *so, GsfXMLOut *output,
			   G_GNUC_UNUSED GnmConventions const *convs)
{
	GnmSOPath const *sop = GNM_SO_PATH (so);
	char *svg;

	if (sop->text != NULL && *(sop->text) != '\0') {
		gsf_xml_out_add_cstr (output, "Label", sop->text);
		if (sop->markup != NULL) {
			GOFormat *fmt = go_format_new_markup	(sop->markup, TRUE);
			gsf_xml_out_add_cstr (output, "LabelFormat",
					      go_format_as_XL (fmt));
			go_format_unref (fmt);
		}
	}
	if (sop->path) {
		svg = go_path_to_svg (sop->path);
		gsf_xml_out_add_cstr (output, "Path", svg);
		g_free (svg);
	} else if (sop->paths) {
		unsigned i;
		for (i = 0; i < sop->paths->len; i++) {
			gsf_xml_out_start_element (output, "Path");
			svg = go_path_to_svg ((GOPath *) g_ptr_array_index (sop->paths, i));
			gsf_xml_out_add_cstr (output, "Path", svg);
			g_free (svg);
			gsf_xml_out_end_element (output); /* </Path> */
		}
	}

	gsf_xml_out_start_element (output, "Style");
	go_persist_sax_save (GO_PERSIST (sop->style), output);
	gsf_xml_out_end_element (output); /* </Style> */
}
static void
xlsx_write_pivot_cache_source (XLSXWriteState *state, GsfXMLOut *xml, GODataCache const *cache)
{
	GODataCacheSource const *src = go_data_cache_get_source (cache);

	if (NULL == src)
		return;

	if (IS_GNM_DATA_CACHE_SOURCE (src)) {
		GnmDataCacheSource const *ssrc = GNM_DATA_CACHE_SOURCE (src);
		Sheet const *src_sheet	= gnm_data_cache_source_get_sheet (ssrc);
		GnmRange const	*r	= gnm_data_cache_source_get_range (ssrc);
		char const	*name	= gnm_data_cache_source_get_name  (ssrc);
		gsf_xml_out_start_element (xml, "cacheSource");
		gsf_xml_out_add_cstr_unchecked (xml, "type", "worksheet");
		gsf_xml_out_start_element (xml, "worksheetSource");
		if (NULL != r)		xlsx_add_range (xml, "ref", r);
		if (NULL != src_sheet)	gsf_xml_out_add_cstr (xml, "sheet", src_sheet->name_unquoted);
		if (NULL != name)	gsf_xml_out_add_cstr (xml, "name", name);
		/* "id" == sheetId : do we need this ? */
		gsf_xml_out_end_element (xml); /* </worksheetSource> */
		gsf_xml_out_end_element (xml); /* </cacheSource> */
	} else {
		g_warning ("UNSUPPORTED  GODataCacheSource of type %s", G_OBJECT_TYPE_NAME(src));
	}
}
Exemplo n.º 4
0
static void
gog_dataset_sax_save (GogDataset const *set, GsfXMLOut *output, gpointer user)
{
	GOData  *dat;
	char    *tmp;
	int      i, last;

	gsf_xml_out_start_element (output, "data");
	gog_dataset_dims (set, &i, &last);
	for ( ; i <= last ; i++) {
		dat = gog_dataset_get_dim (set, i);
		if (dat == NULL)
			continue;

		gsf_xml_out_start_element (output, "dimension");
		gsf_xml_out_add_int (output, "id", i);
		gsf_xml_out_add_cstr (output, "type",
			G_OBJECT_TYPE_NAME (dat));
		tmp = go_data_serialize (dat, user);
		gsf_xml_out_add_cstr (output, NULL, tmp);
		g_free (tmp);
		gsf_xml_out_end_element (output); /* </dimension> */
	}
	gsf_xml_out_end_element (output); /* </data> */

}
static char const *
xlsx_write_pivot_cache_definition (XLSXWriteState *state, GsfOutfile *wb_part,
				   GODataCache const *cache, unsigned int cache_def_num)
{
	GsfXMLOut *xml;
	int i, n;
	char const *record_id;
	char *name = g_strdup_printf ("pivotCacheDefinition%u.xml", cache_def_num);
	GsfOutput *cache_def_part = gsf_outfile_new_child_full (state->pivotCache.dir, name, FALSE,
		"content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
		NULL);
	char const *cache_def_id = gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (cache_def_part),
		GSF_OUTFILE_OPEN_PKG (wb_part),
		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition");

	record_id = xlsx_write_pivot_cache_records (state, cache, cache_def_part, cache_def_num);

	xml = gsf_xml_out_new (cache_def_part);

	gsf_xml_out_start_element (xml, "pivotCacheDefinition");
	gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss);
	gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);

	gsf_xml_out_add_cstr (xml, "r:id", record_id);
	if (cache->refreshed_by) gsf_xml_out_add_cstr (xml, "refreshedBy", cache->refreshed_by);
	if (cache->refreshed_on) {
		if (state->version == ECMA_376_2006)
			gsf_xml_out_add_float (xml, "refreshedDate", 
					       go_val_as_float (cache->refreshed_on), -1);
		else {
			GOFormat const *format = go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss");
			gchar *date = format_value (format, cache->refreshed_on, NULL, -1, NULL);
			gsf_xml_out_add_cstr_unchecked (xml, "refreshedDateIso", date);
			g_free (date);
			go_format_unref (format);
		}		
	}
	gsf_xml_out_add_int (xml, "createdVersion",	cache->XL_created_ver);
	gsf_xml_out_add_int (xml, "refreshedVersion",	cache->XL_refresh_ver);
	gsf_xml_out_add_uint (xml, "recordCount",	go_data_cache_num_items  (cache));
	xlsx_add_bool (xml, "upgradeOnRefresh", cache->refresh_upgrades);
	xlsx_write_pivot_cache_source (state, xml, cache);

	gsf_xml_out_start_element (xml, "cacheFields");
	n = go_data_cache_num_fields (cache);
	gsf_xml_out_add_uint (xml, "count", n);
	for (i = 0 ; i < n ; i++)
		xlsx_write_pivot_cache_field (state, xml, go_data_cache_get_field (cache, i));
	gsf_xml_out_end_element (xml); /* </cacheFields> */

	gsf_xml_out_end_element (xml); /* </pivotCacheDefinition> */

	g_object_unref (xml);
	gsf_output_close (cache_def_part);
	g_object_unref (cache_def_part);
	g_free (name);

	return cache_def_id;
}
static void
xlsx_write_pivot_cache_field (XLSXWriteState *state, GsfXMLOut *xml,
			      GODataCacheField const *field)
{
	GOValArray const *vals;

	gsf_xml_out_start_element (xml, "cacheField");
	gsf_xml_out_add_cstr (xml, "name", go_data_cache_field_get_name (field)->str);
	gsf_xml_out_add_int (xml, "numFmtId", 0);	/* TODO */

	if (NULL != (vals = go_data_cache_field_get_vals (field, FALSE)))
		xlsx_write_pivot_val_array (state, xml, vals, "sharedItems");

	if (NULL != (vals = go_data_cache_field_get_vals (field, TRUE))) {
		int		parent_group;
		GOValBucketer  *bucketer = NULL;
		const char *group_by = NULL;

		g_object_get (G_OBJECT (field),
			      "group-parent", &parent_group,
			      "bucketer", &bucketer,
			      NULL);
		gsf_xml_out_start_element (xml, "fieldGroup");
		if (parent_group >= 0)
			gsf_xml_out_add_int (xml, "base", parent_group);

		gsf_xml_out_start_element (xml, "rangePr");
		switch (bucketer->type) {
		case GO_VAL_BUCKET_SECOND		: group_by = "seconds"; break;
		case GO_VAL_BUCKET_MINUTE		: group_by = "minutes"; break;
		case GO_VAL_BUCKET_HOUR			: group_by = "hours"; break;
		case GO_VAL_BUCKET_DAY_OF_YEAR		: group_by = "days"; break;
		case GO_VAL_BUCKET_MONTH		: group_by = "months"; break;
		case GO_VAL_BUCKET_CALENDAR_QUARTER	: group_by = "quarters"; break;
		case GO_VAL_BUCKET_YEAR			: group_by = "years"; break;
		default:
							  /* default to linear */;
		case GO_VAL_BUCKET_SERIES_LINEAR 	:break;
		}
		if (group_by) gsf_xml_out_add_cstr_unchecked (xml, "groupBy", group_by);
		if (bucketer->type == GO_VAL_BUCKET_SERIES_LINEAR) {
			gsf_xml_out_add_float (xml, "startNum",		bucketer->details.series.minimum, -1);
			gsf_xml_out_add_float (xml, "endNum",		bucketer->details.series.maximum, -1);
			gsf_xml_out_add_float (xml, "groupInterval",	bucketer->details.series.step, -1);
		} else {
			xlsx_write_date (state, xml, "startDate", bucketer->details.dates.minimum);
			xlsx_write_date (state, xml, "endDate",   bucketer->details.dates.maximum);
		}
		gsf_xml_out_end_element (xml); /* </rangePr> */

		xlsx_write_pivot_val_array (state, xml, vals, "groupItems");
		gsf_xml_out_end_element (xml); /* </fieldGroup> */
	}

	gsf_xml_out_end_element (xml); /* </cacheField> */
}
static char const *
xlsx_write_pivot_cache_records (XLSXWriteState *state, GODataCache const *cache,
				GsfOutput *cache_def_part, unsigned int cache_records_num)
{
	unsigned int i, j;
	GsfXMLOut *xml;
	char *name = g_strdup_printf ("pivotCacheRecords%u.xml", cache_records_num);
	GsfOutput *record_part = gsf_outfile_new_child_full (state->pivotCache.dir, name, FALSE,
		"content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml",
		NULL);
	char const *record_id = gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (record_part),
		GSF_OUTFILE_OPEN_PKG (cache_def_part),
		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords");

	xml = gsf_xml_out_new (record_part);

	gsf_xml_out_start_element (xml, "pivotCacheRecords");
	gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss);
	gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);

	gsf_xml_out_add_int (xml, "count", go_data_cache_num_items (cache));
	for (j = 0 ; j < go_data_cache_num_items (cache); j++) {
		gsf_xml_out_start_element (xml, "r");
		for (i = 0 ; i < go_data_cache_num_fields (cache); i++) {
			GODataCacheField *field = go_data_cache_get_field (cache, i);
			switch (go_data_cache_field_ref_type (field)) {
			case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I8 :
			case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I16 :	/* fallthrough */
			case GO_DATA_CACHE_FIELD_TYPE_INDEXED_I32 :	/* fallthrough */
				gsf_xml_out_start_element (xml, "x");
				gsf_xml_out_add_int (xml, "v",
					go_data_cache_get_index (cache, field, j));
				gsf_xml_out_end_element (xml);
				break;

			case GO_DATA_CACHE_FIELD_TYPE_INLINE :
				xlsx_write_pivot_val (state, xml,
					go_data_cache_field_get_val (field, j));
			break;

			case GO_DATA_CACHE_FIELD_TYPE_NONE :
				continue;
			}
		}
		gsf_xml_out_end_element (xml); /* </r> */
	}
	gsf_xml_out_end_element (xml); /* </pivotCacheRecords> */

	g_object_unref (xml);
	gsf_output_close (record_part);
	g_object_unref (record_part);
	g_free (name);

	return record_id;
}
/*
 *
 * DO * NOT * COMPILE * DIRECTLY *
 * DO * NOT * COMPILE * DIRECTLY *
 * DO * NOT * COMPILE * DIRECTLY *
 *
 * included via xlsx-write.c
 **/
static void
xlsx_write_pivot_val (XLSXWriteState *state, GsfXMLOut *xml,
		      GOVal const *v)
{
	switch (v->type) {
	case VALUE_CELLRANGE:
	case VALUE_ARRAY:
		g_warning ("REMOVE THIS CODE WHEN WE MOVE TO GOFFICE");
		break;

	case VALUE_EMPTY:
		gsf_xml_out_simple_element (xml, "m", NULL);
		break;

	case VALUE_BOOLEAN:
		gsf_xml_out_start_element (xml, "b");
		xlsx_add_bool (xml, "v", v->v_bool.val);
		gsf_xml_out_end_element (xml);
		break;

	case VALUE_FLOAT: {
		GOFormat const *fmt = go_val_get_fmt (v);
		if (NULL != fmt && go_format_is_date (fmt)) {
			char *d = format_value (state->date_fmt, v, NULL, -1, workbook_date_conv (state->base.wb));
			gsf_xml_out_start_element (xml, "d");
			gsf_xml_out_add_cstr_unchecked (xml, "v", d);
			gsf_xml_out_end_element (xml);
		} else {
			gsf_xml_out_start_element (xml, "n");
			gsf_xml_out_add_float (xml, "v", v->v_float.val, -1);
			gsf_xml_out_end_element (xml);
		}
		break;
	}

	case VALUE_ERROR :
		gsf_xml_out_start_element (xml, "e");
		gsf_xml_out_add_cstr (xml, "v", v->v_err.mesg->str);
		gsf_xml_out_end_element (xml);
		break;

	case VALUE_STRING :
		gsf_xml_out_start_element (xml, "s");
		gsf_xml_out_add_cstr (xml, "v", v->v_str.val->str);
		gsf_xml_out_end_element (xml);
		break;
	}
}
Exemplo n.º 9
0
static void
gnm_soi_write_xml_sax (SheetObject const *so, GsfXMLOut *output,
		       G_GNUC_UNUSED GnmConventions const *convs)
{
	SheetObjectImage *soi;

	g_return_if_fail (IS_SHEET_OBJECT_IMAGE (so));
	soi = SHEET_OBJECT_IMAGE (so);

	gsf_xml_out_add_float (output, "crop-top", soi->crop_top, 3);
	gsf_xml_out_add_float (output, "crop-bottom", soi->crop_bottom, 3);
	gsf_xml_out_add_float (output, "crop-left", soi->crop_left, 3);
	gsf_xml_out_add_float (output, "crop-right", soi->crop_right, 3);
	gsf_xml_out_start_element (output, "Content");
	if (soi->type != NULL)
		gsf_xml_out_add_cstr (output, "image-type", soi->type);
	if (soi->image && go_image_get_name (soi->image)) {
		gsf_xml_out_add_cstr (output, "name", go_image_get_name (soi->image));
		if (sheet_object_get_sheet (so))
			go_doc_save_image (GO_DOC (sheet_object_get_sheet (so)->workbook), go_image_get_name (soi->image));
		else {
			/* looks that this may happen when pasting from another process, see #687414 */
			gsize length;
			guint8 const *data = go_image_get_data (soi->image, &length);
			gsf_xml_out_add_uint (output, "size-bytes", length);
			gsf_xml_out_add_base64 (output, NULL, data, length);
		}
	} else {
		gsf_xml_out_add_uint (output, "size-bytes", soi->bytes.len);
		gsf_xml_out_add_base64 (output, NULL, soi->bytes.data, soi->bytes.len);
	}
	gsf_xml_out_end_element (output);
}
Exemplo n.º 10
0
static void
gsf_open_pkg_write_content_override (GsfOutfileOpenPkg const *open_pkg,
				     char const *base,
				     GsfXMLOut *xml)
{
	GsfOutfileOpenPkg const *child;
	char   *path;
	GSList *ptr;

	for (ptr = open_pkg->children ; ptr != NULL ; ptr = ptr->next) {
		child = ptr->data;
		if (child->is_dir) {
			path = g_strconcat (base, gsf_output_name (GSF_OUTPUT (child)), "/", NULL);
			gsf_open_pkg_write_content_override (child, path, xml);
		} else {
			path = g_strconcat (base, gsf_output_name (GSF_OUTPUT (child)), NULL);
			/* rels files do need content types, the defaults handle them */
			if (NULL != child->content_type) {
				gsf_xml_out_start_element (xml, "Override");
				gsf_xml_out_add_cstr (xml, "PartName", path);
				gsf_xml_out_add_cstr (xml, "ContentType", child->content_type);
				gsf_xml_out_end_element (xml); /* </Override> */
			}
		}
		g_free (path);
	}
}
Exemplo n.º 11
0
static void
gsf_open_pkg_write_content_default (GsfXMLOut *xml, char const *ext, char const *type)
{
	gsf_xml_out_start_element (xml, "Default");
	gsf_xml_out_add_cstr (xml, "Extension", ext);
	gsf_xml_out_add_cstr (xml, "ContentType", type);
	gsf_xml_out_end_element (xml); /* </Default> */
}
Exemplo n.º 12
0
UT_Error IE_Exp_EPUB::writeContainer()
{
    GsfOutput* metaInf = gsf_outfile_new_child(m_root, "META-INF", TRUE);

    if (metaInf == NULL)
    {
        UT_DEBUGMSG(("Can`t create META-INF dir\n"));
        return UT_ERROR;
    }
    GsfOutput* container = gsf_outfile_new_child(GSF_OUTFILE(metaInf),
            "container.xml", FALSE);
    if (container == NULL)
    {
        UT_DEBUGMSG(("Can`t create container.xml\n"));
        gsf_output_close(metaInf);
        return UT_ERROR;
    }
    GsfXMLOut * containerXml = gsf_xml_out_new(container);

    // <container>
    gsf_xml_out_start_element(containerXml, "container");
    gsf_xml_out_add_cstr(containerXml, "version", "1.0");
    gsf_xml_out_add_cstr(containerXml, "xmlns", OCF201_NAMESPACE);
    // <rootfiles>
    gsf_xml_out_start_element(containerXml, "rootfiles");
    // <rootfile>
    gsf_xml_out_start_element(containerXml, "rootfile");
    gsf_xml_out_add_cstr(containerXml, "full-path", "OEBPS/book.opf");
    gsf_xml_out_add_cstr(containerXml, "media-type", OPF_MIMETYPE);
    // </rootfile>
    gsf_xml_out_end_element(containerXml);
    // </rootfiles>
    gsf_xml_out_end_element(containerXml);
    // </container>
    gsf_xml_out_end_element(containerXml);

    gsf_output_close(container);
    gsf_output_close(metaInf);
    return UT_OK;
}
Exemplo n.º 13
0
static void
xlsx_write_pivot_val_array (XLSXWriteState *state, GsfXMLOut *xml,
			    GOValArray const *vals, char const *name)
{
	unsigned int i;
	GOVal const *v;

	gsf_xml_out_start_element (xml, name);
	gsf_xml_out_add_uint (xml, "count", vals->len);
	for (i = 0 ; i < vals->len ; i++)
		if (NULL != (v = g_ptr_array_index (vals, i)))
			xlsx_write_pivot_val (state, xml, v);
	gsf_xml_out_end_element (xml);
}
static void
gnm_soi_write_xml_sax (SheetObject const *so, GsfXMLOut *output,
		       GnmConventions const *convs)
{
	SheetObjectImage *soi;

	g_return_if_fail (IS_SHEET_OBJECT_IMAGE (so));
	soi = SHEET_OBJECT_IMAGE (so);

	gsf_xml_out_add_float (output, "crop-top", soi->crop_top, 3);
	gsf_xml_out_add_float (output, "crop-bottom", soi->crop_bottom, 3);
	gsf_xml_out_add_float (output, "crop-left", soi->crop_left, 3);
	gsf_xml_out_add_float (output, "crop-right", soi->crop_right, 3);
	gsf_xml_out_start_element (output, "Content");
	if (soi->type != NULL)
		gsf_xml_out_add_cstr (output, "image-type", soi->type);
	gsf_xml_out_add_uint (output, "size-bytes", soi->bytes.len);
	gsf_xml_out_add_base64 (output, NULL, soi->bytes.data, soi->bytes.len);
	gsf_xml_out_end_element (output);
}
Exemplo n.º 15
0
void
gog_object_write_xml_sax (GogObject const *obj, GsfXMLOut *output, gpointer user)
{
	guint	     n;
	GParamSpec **props;
	GSList	    *ptr;

	g_return_if_fail (GOG_IS_OBJECT (obj));

	gsf_xml_out_start_element (output, "GogObject");

	/* Primary details */
	if (obj->role != NULL) {
		if (strcmp (obj->role->id, GOG_BACKPLANE_NEW_ROLE_NAME) == 0)
			gsf_xml_out_add_cstr (output, "role", GOG_BACKPLANE_OLD_ROLE_NAME);
		else
			gsf_xml_out_add_cstr (output, "role", obj->role->id);
	}
	if (obj->explicitly_typed_role || obj->role == NULL)
		gsf_xml_out_add_cstr (output, "type", G_OBJECT_TYPE_NAME (obj));

	/* properties */
	props = g_object_class_list_properties (G_OBJECT_GET_CLASS (obj), &n);
	while (n-- > 0)
		if (props[n]->flags & GO_PARAM_PERSISTENT)
			gog_object_write_property_sax (obj, props[n], output);

	g_free (props);

	if (GO_IS_PERSIST (obj))	/* anything special for this class */
		go_persist_sax_save (GO_PERSIST (obj), output);
	if (GOG_IS_DATASET (obj))	/* convenience to save data */
		gog_dataset_sax_save (GOG_DATASET (obj), output, user);

	/* the children */
	for (ptr = obj->children; ptr != NULL ; ptr = ptr->next)
		gog_object_write_xml_sax (ptr->data, output, user);

	gsf_xml_out_end_element (output); /* </GogObject> */
}
Exemplo n.º 16
0
static gboolean
gsf_outfile_open_pkg_close (GsfOutput *output)
{
	GsfOutfileOpenPkg *open_pkg = GSF_OUTFILE_OPEN_PKG (output);
	GsfOutput *dir;
	gboolean res = FALSE;
	char *rels_name;

	if (NULL == open_pkg->sink || gsf_output_is_closed (open_pkg->sink))
		return TRUE;

	/* Generate [Content_types].xml when we close the root dir */
	if (NULL == gsf_output_name (output)) {
		GsfOutput *out = gsf_outfile_new_child (GSF_OUTFILE (open_pkg->sink),
			"[Content_Types].xml", FALSE);
		GsfXMLOut *xml = gsf_xml_out_new (out);

		gsf_xml_out_start_element (xml, "Types");
		gsf_xml_out_add_cstr_unchecked (xml, "xmlns",
			"http://schemas.openxmlformats.org/package/2006/content-types");
		gsf_open_pkg_write_content_default (xml, "rels",
			"application/vnd.openxmlformats-package.relationships+xml");
		gsf_open_pkg_write_content_default (xml, "xlbin",
			"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings");
		gsf_open_pkg_write_content_default (xml, "xml",
			"application/xml");
		gsf_open_pkg_write_content_override (open_pkg, "/", xml);
		gsf_xml_out_end_element (xml); /* </Types> */
		g_object_unref (xml);

		gsf_output_close (out);
		g_object_unref (out);

		dir = open_pkg->sink;
		rels_name = g_strdup (".rels");
	} else {
		res = gsf_output_close (open_pkg->sink);

		dir = (GsfOutput *)gsf_output_container (open_pkg->sink);
		rels_name = g_strconcat (gsf_output_name (output), ".rels", NULL);
	}

	if (NULL != open_pkg->relations) {
		GsfOutput *rels;
		GsfXMLOut *xml;
		GsfOpenPkgRel *rel;
		GSList *ptr;

		dir = gsf_outfile_new_child (GSF_OUTFILE (dir), "_rels", TRUE);
		rels = gsf_outfile_new_child (GSF_OUTFILE (dir), rels_name, FALSE);
		xml = gsf_xml_out_new (rels);

		gsf_xml_out_start_element (xml, "Relationships");
		gsf_xml_out_add_cstr_unchecked (xml, "xmlns",
			"http://schemas.openxmlformats.org/package/2006/relationships");

		for (ptr = open_pkg->relations ; ptr != NULL ; ptr = ptr->next) {
			rel = ptr->data;
			gsf_xml_out_start_element (xml, "Relationship");
			gsf_xml_out_add_cstr (xml, "Id", rel->id);
			gsf_xml_out_add_cstr (xml, "Type", rel->type);
			gsf_xml_out_add_cstr (xml, "Target", rel->target);
			if (rel->is_extern)
				gsf_xml_out_add_cstr_unchecked (xml, "TargetMode", "External");
			gsf_xml_out_end_element (xml); /* </Relationship> */

			g_free (rel->id);
			g_free (rel->type);
			g_free (rel->target);
			g_free (rel);
		}
		g_slist_free (open_pkg->relations);

		gsf_xml_out_end_element (xml); /* </Relationships> */
		g_object_unref (xml);
		gsf_output_close (rels);
		g_object_unref (rels);
		g_object_unref (dir);
	}
	g_free (rels_name);

	/* close the container */
	if (NULL == gsf_output_name (output))
		return gsf_output_close (open_pkg->sink);
	return res;
}
Exemplo n.º 17
0
static int
test_xml_indent (void)
{
	GsfOutput *mem = gsf_output_memory_new ();
	GsfXMLOut *xml = gsf_xml_out_new (mem);
	const char *data;
	gboolean pprint;
	int err;
	const char *expected =
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
		"<outer>\n"
		"  <data/>\n"
		"  <data attr=\"val\"/>\n"
		"  <data>text</data>\n"
		"  <data>\n"
		"    <inner>text</inner>\n"
		"  </data>\n"
		"  <data>text</data>\n"
		"  <data><inner>text</inner></data>\n"
		"</outer>\n";

	gsf_xml_out_start_element (xml, "outer");

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_add_cstr_unchecked (xml, "attr", "val");
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	gsf_xml_out_start_element (xml, "inner");
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_end_element (xml);
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	pprint = gsf_xml_out_set_pretty_print (xml, FALSE);
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_set_pretty_print (xml, pprint);
	gsf_xml_out_end_element (xml);

	gsf_xml_out_start_element (xml, "data");
	pprint = gsf_xml_out_set_pretty_print (xml, FALSE);
	gsf_xml_out_start_element (xml, "inner");
	gsf_xml_out_add_cstr_unchecked (xml, NULL, "text");
	gsf_xml_out_end_element (xml);
	gsf_xml_out_set_pretty_print (xml, pprint);
	gsf_xml_out_end_element (xml);

	gsf_xml_out_end_element (xml);

	g_object_unref (xml);

	data = (const char *)gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (mem));
	g_printerr ("Got\n%s\n", data);

	err = !g_str_equal (data, expected);
	if (err)
		g_printerr ("Expected\n%s\n", expected);

	g_object_unref (mem);

	return err;
}
Exemplo n.º 18
0
UT_Error IE_Exp_EPUB::EPUB2_writeNavigation()
{
    GsfOutput* ncx = gsf_outfile_new_child(GSF_OUTFILE(m_oebps), "toc.ncx",
            FALSE);
    if (ncx == NULL)
    {
        UT_DEBUGMSG(("Can`t create toc.ncx file\n"));
        return UT_ERROR;
    }
    GsfXMLOut* ncxXml = gsf_xml_out_new(ncx);

    // <ncx>
    gsf_xml_out_start_element(ncxXml, "ncx");
    gsf_xml_out_add_cstr(ncxXml, "xmlns", NCX_NAMESPACE);
    gsf_xml_out_add_cstr(ncxXml, "version", "2005-1");
    gsf_xml_out_add_cstr(ncxXml, "xml:lang", NULL);
    // <head>
    gsf_xml_out_start_element(ncxXml, "head");
    // <meta name="dtb:uid" content=... >
    gsf_xml_out_start_element(ncxXml, "meta");
    gsf_xml_out_add_cstr(ncxXml, "name", "dtb:uid");
    gsf_xml_out_add_cstr(ncxXml, "content", getDoc()->getDocUUIDString());
    // </meta>
    gsf_xml_out_end_element(ncxXml);
    // <meta name="epub-creator" content=... >
    gsf_xml_out_start_element(ncxXml, "meta");
    gsf_xml_out_add_cstr(ncxXml, "name", "epub-creator");
    gsf_xml_out_add_cstr(ncxXml, "content",
            "AbiWord (http://www.abisource.com/)");
    // </meta>
    gsf_xml_out_end_element(ncxXml);
    // <meta name="dtb:depth" content=... >
    gsf_xml_out_start_element(ncxXml, "meta");
    gsf_xml_out_add_cstr(ncxXml, "name", "dtb:depth");
    gsf_xml_out_add_cstr(ncxXml, "content", "1");
    // </meta>
    gsf_xml_out_end_element(ncxXml);
    // <meta name="dtb:totalPageCount" content=... >
    gsf_xml_out_start_element(ncxXml, "meta");
    gsf_xml_out_add_cstr(ncxXml, "name", "dtb:totalPageCount");
    gsf_xml_out_add_cstr(ncxXml, "content", "0");
    // </meta>
    gsf_xml_out_end_element(ncxXml);
    // <meta name="dtb:totalPageCount" content=... >
    gsf_xml_out_start_element(ncxXml, "meta");
    gsf_xml_out_add_cstr(ncxXml, "name", "dtb:maxPageCount");
    gsf_xml_out_add_cstr(ncxXml, "content", "0");
    // </meta>
    gsf_xml_out_end_element(ncxXml);
    // </head>
    gsf_xml_out_end_element(ncxXml);

    // <docTitle>
    gsf_xml_out_start_element(ncxXml, "docTitle");
    gsf_xml_out_start_element(ncxXml, "text");
    gsf_xml_out_add_cstr(ncxXml, NULL, getTitle().c_str());
    gsf_xml_out_end_element(ncxXml);
    // </docTitle>
    gsf_xml_out_end_element(ncxXml);

    // <docAuthor>
    gsf_xml_out_start_element(ncxXml, "docAuthor");
    gsf_xml_out_start_element(ncxXml, "text");
    gsf_xml_out_add_cstr(ncxXml, NULL, getAuthor().c_str());
    gsf_xml_out_end_element(ncxXml);
    // </docAuthor>
    gsf_xml_out_end_element(ncxXml);


    // <navMap>
    gsf_xml_out_start_element(ncxXml, "navMap");
    if (m_pHmtlExporter->getNavigationHelper()->hasTOC())
    {
        int lastItemLevel;
        int curItemLevel = 0;
        std::vector<int> tagLevels;
        int tocNum = 0;
        for (int currentItem = 0; 
            currentItem < m_pHmtlExporter->getNavigationHelper()->getNumTOCEntries(); 
            currentItem++)
        {
            lastItemLevel = curItemLevel;
	    std::string itemStr = m_pHmtlExporter->getNavigationHelper()
			->getNthTOCEntry(currentItem, &curItemLevel).utf8_str();
            PT_DocPosition itemPos;
            m_pHmtlExporter->getNavigationHelper()->getNthTOCEntryPos(currentItem, itemPos);
            
            std::string itemFilename;
            if (m_exp_opt.bSplitDocument)
            {
                itemFilename = m_pHmtlExporter->getNavigationHelper()
					->getFilenameByPosition(itemPos).utf8_str();

                if (itemFilename.length() == 0 || (itemFilename[0] ==  '.'))
                {
                    itemFilename = "index.xhtml";
                }
                else
                {
                    itemFilename +=   + ".xhtml";
                }
            } else
            {
                itemFilename = "index.xhtml";
            }

            if (std::find(m_opsId.begin(), m_opsId.end(), 
                          escapeForId(itemFilename)) == m_opsId.end())
            {
                m_opsId.push_back(escapeForId(itemFilename));
                tocNum = 0;
            }

            UT_DEBUGMSG(("Item filename %s at pos %d\n", 
                itemFilename.c_str(),itemPos));

            if ((lastItemLevel >= curItemLevel) && (currentItem != 0))
            {
                while ((tagLevels.size() > 0) 
                        && (tagLevels.back() >= curItemLevel))
                {
                    gsf_xml_out_end_element(ncxXml);
                    tagLevels.pop_back();
                }

            }

	    std::string navClass = UT_std_string_sprintf("h%d", curItemLevel);
	    std::string navId = UT_std_string_sprintf("AbiTOC%d", tocNum);
	    std::string navSrc = std::string(itemFilename.c_str()) + "#" + navId;
            gsf_xml_out_start_element(ncxXml, "navPoint");
            gsf_xml_out_add_cstr(ncxXml, "playOrder",
                    UT_std_string_sprintf("%d", currentItem + 1).c_str());
            gsf_xml_out_add_cstr(ncxXml, "class", navClass.c_str());
            gsf_xml_out_add_cstr(ncxXml, "id", navId.c_str());
            gsf_xml_out_start_element(ncxXml, "navLabel");
            gsf_xml_out_start_element(ncxXml, "text");
            gsf_xml_out_add_cstr(ncxXml, NULL, itemStr.c_str());
            gsf_xml_out_end_element(ncxXml);
            gsf_xml_out_end_element(ncxXml);
            gsf_xml_out_start_element(ncxXml, "content");
            gsf_xml_out_add_cstr(ncxXml, "src", navSrc.c_str());
            gsf_xml_out_end_element(ncxXml);

            tagLevels.push_back(curItemLevel);
            tocNum++;

        }

        closeNTags(ncxXml, tagLevels.size());
    }
    else
    {
        m_opsId.push_back(escapeForId("index.xhtml"));
        gsf_xml_out_start_element(ncxXml, "navPoint");
        gsf_xml_out_add_cstr(ncxXml, "playOrder", "1");
        gsf_xml_out_add_cstr(ncxXml, "class", "h1");
        gsf_xml_out_add_cstr(ncxXml, "id", "index");

        gsf_xml_out_start_element(ncxXml, "navLabel");
        gsf_xml_out_start_element(ncxXml, "text");
        gsf_xml_out_add_cstr(ncxXml, NULL, getTitle().c_str());
        gsf_xml_out_end_element(ncxXml);
        gsf_xml_out_end_element(ncxXml);

        gsf_xml_out_start_element(ncxXml, "content");
        gsf_xml_out_add_cstr(ncxXml, "src", "index.xhtml");
        gsf_xml_out_end_element(ncxXml);
        gsf_xml_out_end_element(ncxXml);
    }
    // </navMap>
    gsf_xml_out_end_element(ncxXml);

    // </ncx>
    gsf_xml_out_end_element(ncxXml);
    gsf_output_close(ncx);

    return UT_OK;
}
Exemplo n.º 19
0
UT_Error IE_Exp_EPUB::EPUB3_writeNavigation()
{
    GsfOutput* nav = gsf_outfile_new_child(GSF_OUTFILE(m_oebps), "toc.xhtml",
            FALSE);
    if (nav == NULL)
    {
        UT_DEBUGMSG(("Can`t create toc.xhtml file\n"));
        return UT_ERROR;
    }
    GsfXMLOut* navXHTML = gsf_xml_out_new(nav);

     gsf_xml_out_start_element(navXHTML, "html");
    gsf_xml_out_add_cstr(navXHTML, "xmlns", XHTML_NS);
    gsf_xml_out_add_cstr(navXHTML, "xmlns:epub", OPS201_NAMESPACE);
    gsf_xml_out_add_cstr(navXHTML, "profile", EPUB3_CONTENT_PROFILE);
    
    
    gsf_xml_out_start_element(navXHTML, "head");
    gsf_xml_out_start_element(navXHTML, "title");
    gsf_xml_out_add_cstr(navXHTML, NULL, "Table of Contents");
    gsf_xml_out_end_element(navXHTML);
    gsf_xml_out_end_element(navXHTML);
    
    gsf_xml_out_start_element(navXHTML, "body");
    gsf_xml_out_start_element(navXHTML, "section");
    gsf_xml_out_add_cstr(navXHTML, "class", "frontmatter TableOfContents");
    gsf_xml_out_start_element(navXHTML, "header");
    gsf_xml_out_start_element(navXHTML, "h1");
    gsf_xml_out_add_cstr(navXHTML, NULL, "Contents");
    gsf_xml_out_end_element(navXHTML);
    gsf_xml_out_end_element(navXHTML);
    gsf_xml_out_start_element(navXHTML, "nav");
    gsf_xml_out_add_cstr(navXHTML, "epub:type", "toc");
    gsf_xml_out_add_cstr(navXHTML, "id", "toc");
    if (m_pHmtlExporter->getNavigationHelper()->hasTOC())
    {
        int lastItemLevel;
        int curItemLevel = 0;
        std::vector<int> tagLevels;
        int tocNum = 0;
        bool newList = true;
        for (int currentItem = 0; 
            currentItem < m_pHmtlExporter->getNavigationHelper()->getNumTOCEntries(); 
            currentItem++)
        {
            lastItemLevel = curItemLevel;
	    UT_UTF8String itemStr = m_pHmtlExporter->getNavigationHelper()
                ->getNthTOCEntry(currentItem, &curItemLevel);
            PT_DocPosition itemPos;
            m_pHmtlExporter->getNavigationHelper()->getNthTOCEntryPos(currentItem, itemPos);
	    
            std::string itemFilename;
            
            if (m_exp_opt.bSplitDocument)
            {
                itemFilename = m_pHmtlExporter->getNavigationHelper()
					->getFilenameByPosition(itemPos).utf8_str();

                if ((itemFilename == "") || itemFilename.length() == 0)
                {
                    itemFilename = "index.xhtml";
                } else
                {
                    itemFilename +=  ".xhtml";
                }
            } else
            {
                itemFilename = "index.xhtml";
            }

            if (std::find(m_opsId.begin(), m_opsId.end(), 
                          escapeForId(itemFilename)) == m_opsId.end())
            {
                m_opsId.push_back(escapeForId(itemFilename));
                tocNum = 0;
            }

            UT_DEBUGMSG(("Item filename %s at pos %d\n", 
                itemFilename.c_str(),itemPos));

            if ((lastItemLevel >= curItemLevel) && (currentItem != 0))
            {
                while ((tagLevels.size() > 0) 
                        && (tagLevels.back() >= curItemLevel))
                {
                    if (tagLevels.back() == curItemLevel)
                    {
                        gsf_xml_out_end_element(navXHTML);
                    } else
                    {
                        closeNTags(navXHTML, 2);
                    }
                    tagLevels.pop_back();
                }

            } else
            if ((lastItemLevel < curItemLevel) || newList) 
            {
                gsf_xml_out_start_element(navXHTML, "ol");
                newList = false;

            }

	    std::string navClass = UT_std_string_sprintf("h%d", curItemLevel);
	    std::string navId = UT_std_string_sprintf("AbiTOC%d",
                    tocNum);
	    std::string navSrc = std::string(itemFilename.c_str()) + "#" + navId;
            gsf_xml_out_start_element(navXHTML, "li");
            gsf_xml_out_add_cstr(navXHTML, "class", navClass.c_str());
            gsf_xml_out_add_cstr(navXHTML, "id", navId.c_str());
            gsf_xml_out_start_element(navXHTML, "a");
            gsf_xml_out_add_cstr(navXHTML, "href", navSrc.c_str());
            gsf_xml_out_add_cstr(navXHTML, NULL, itemStr.utf8_str());
            gsf_xml_out_end_element(navXHTML);
            // gsf_xml_out_end_element(navXHTML);

            tagLevels.push_back(curItemLevel);
            tocNum++;

        }

        closeNTags(navXHTML, tagLevels.size()*2);
    }
    else
    {
        gsf_xml_out_start_element(navXHTML, "ol");
        gsf_xml_out_start_element(navXHTML, "li");
        gsf_xml_out_add_cstr(navXHTML, "class", "h1");
        gsf_xml_out_add_cstr(navXHTML, "id", "index");
        gsf_xml_out_start_element(navXHTML, "a");
        gsf_xml_out_add_cstr(navXHTML, "href", "index.xhtml");
        gsf_xml_out_add_cstr(navXHTML, NULL, getTitle().c_str());
        gsf_xml_out_end_element(navXHTML);
        gsf_xml_out_end_element(navXHTML); 
        gsf_xml_out_end_element(navXHTML); 
    }
   
    gsf_xml_out_end_element(navXHTML);
    // </section>
    gsf_xml_out_end_element(navXHTML);
    gsf_xml_out_end_element(navXHTML);
    
    
    gsf_xml_out_end_element(navXHTML);
    gsf_output_close(nav);
    return UT_OK;
}
Exemplo n.º 20
0
/**
 * Other things we could index
 * - The names of external refernces
 * - functions used
 * - plugins used
 **/
static int
ssindex (char const *file, GOIOContext *ioc)
{
	int i, res = 0;
	GSList	   *objs, *ptr;
	char	   *str = go_shell_arg_to_uri (file);
	IndexerState state;
	GsfOutput  *gsf_stdout;
	Workbook   *wb;

	state.wb_view = workbook_view_new_from_uri (str, NULL,
		ioc, ssindex_import_encoding);
	g_free (str);

	if (state.wb_view == NULL)
		return 1;

	state.sheet = NULL;

	gsf_stdout = gsf_output_stdio_new_FILE ("<stdout>", stdout, TRUE);
	state.output = gsf_xml_out_new (gsf_stdout);
	gsf_xml_out_start_element (state.output, "gnumeric");
	state.wb = wb = wb_view_get_workbook (state.wb_view);

	workbook_foreach_name (wb, TRUE, (GHFunc)cb_index_name, &state);

	for (i = 0; i < workbook_sheet_count (wb); i++) {
		state.sheet = workbook_sheet_by_index (wb, i);
		gsf_xml_out_simple_element (state.output,
			"data", state.sheet->name_unquoted);

		/* cell content */
		sheet_cell_foreach (state.sheet,
			(GHFunc)&cb_index_cell, &state);

		/* now the objects */
		objs = sheet_objects_get (state.sheet, NULL, G_TYPE_NONE);
		for (ptr = objs ; ptr != NULL ; ptr = ptr->next) {
			GObject *obj = ptr->data;
			char *str = NULL;
			if (gnm_object_has_readable_prop (obj, "text",
							  G_TYPE_STRING, &str) &&
			    str) {
				gsf_xml_out_simple_element (state.output,
							    "data", str);
				g_free (str);
			} else if (GNM_IS_SO_GRAPH (obj))
				ssindex_chart (&state,
					       (GogObject *)sheet_object_graph_get_gog (GNM_SO (obj)));
		}
		g_slist_free (objs);

		/* Various stuff in styles.  */
		sheet_style_foreach (state.sheet,
				     (GFunc)cb_index_styles, &state);

		/* Local names.  */
		gnm_sheet_foreach_name (state.sheet,
					(GHFunc)cb_index_name, &state);
	}

	gsf_xml_out_end_element (state.output); /* </gnumeric> */
	gsf_output_close (gsf_stdout);
	g_object_unref (gsf_stdout);

	g_object_unref (wb);

	return res;
}
Exemplo n.º 21
0
UT_Error IE_Exp_EPUB::package()
{
    GsfOutput* opf = gsf_outfile_new_child(GSF_OUTFILE(m_oebps), "book.opf",
            FALSE);
    if (opf == NULL)
    {
        UT_DEBUGMSG(("Can`t create book.opf\n"));
        return UT_ERROR;
    }
    GsfXMLOut* opfXml = gsf_xml_out_new(opf);
    // <package>
    gsf_xml_out_start_element(opfXml, "package");
    if (m_exp_opt.bEpub2)
    {
    gsf_xml_out_add_cstr(opfXml, "version", "2.0");
    } else
    {
       gsf_xml_out_add_cstr(opfXml, "version", "3.0"); 
    }
    gsf_xml_out_add_cstr(opfXml, "xmlns", OPF201_NAMESPACE);
    gsf_xml_out_add_cstr(opfXml, "unique-identifier", "BookId");
    
    if (!m_exp_opt.bEpub2)
    {
       gsf_xml_out_add_cstr(opfXml, "profile", EPUB3_PACKAGE_PROFILE);
       gsf_xml_out_add_cstr(opfXml, "xml:lang", getLanguage().c_str());
    }

    // <metadata>
    gsf_xml_out_start_element(opfXml, "metadata");
    gsf_xml_out_add_cstr(opfXml, "xmlns:dc", DC_NAMESPACE);
    gsf_xml_out_add_cstr(opfXml, "xmlns:opf", OPF201_NAMESPACE);
    // Generation of required Dublin Core metadata
    gsf_xml_out_start_element(opfXml, "dc:title");
    gsf_xml_out_add_cstr(opfXml, NULL, getTitle().c_str());
    gsf_xml_out_end_element(opfXml);
    gsf_xml_out_start_element(opfXml, "dc:identifier");
    gsf_xml_out_add_cstr(opfXml, "id", "BookId");
    gsf_xml_out_add_cstr(opfXml, NULL, getDoc()->getDocUUIDString());
    gsf_xml_out_end_element(opfXml);
    gsf_xml_out_start_element(opfXml, "dc:language");
    gsf_xml_out_add_cstr(opfXml, NULL, getLanguage().c_str());
    gsf_xml_out_end_element(opfXml);
    gsf_xml_out_start_element(opfXml, "dc:creator");
    gsf_xml_out_add_cstr(opfXml, "opf:role", "aut");
    gsf_xml_out_add_cstr(opfXml, NULL, getAuthor().c_str());
    gsf_xml_out_end_element(opfXml);
    // </metadata> 
    gsf_xml_out_end_element(opfXml);

    // <manifest>
    gsf_xml_out_start_element(opfXml, "manifest");
	gchar *basedir = g_filename_from_uri(m_oebpsDir.c_str(),NULL,NULL);
	UT_ASSERT(basedir);
	std::string _baseDir = basedir;
	std::vector<std::string> listing = getFileList(_baseDir);
	FREEP(basedir);

	for (std::vector<std::string>::iterator i = listing.begin(); i
            != listing.end(); i++)
    {
      std::string idStr = escapeForId(*i);
      std::string fullItemPath = m_oebpsDir + G_DIR_SEPARATOR_S + *i;
        gsf_xml_out_start_element(opfXml, "item");
        if (m_pHmtlExporter->hasMathML((*i)))
        {
            gsf_xml_out_add_cstr(opfXml, "mathml", "true");
        }
        gsf_xml_out_add_cstr(opfXml, "id", idStr.c_str());
        gsf_xml_out_add_cstr(opfXml, "href", (*i).c_str());
        gsf_xml_out_add_cstr(opfXml, "media-type",
                getMimeType(fullItemPath).c_str());
        gsf_xml_out_end_element(opfXml);
    }

    // We`ll add navigation files manually
    gsf_xml_out_start_element(opfXml, "item");
    gsf_xml_out_add_cstr(opfXml, "id", "ncx");
    gsf_xml_out_add_cstr(opfXml, "href", "toc.ncx");
    gsf_xml_out_add_cstr(opfXml, "media-type", "application/x-dtbncx+xml");
    gsf_xml_out_end_element(opfXml);
    if (!m_exp_opt.bEpub2)
    {
        gsf_xml_out_start_element(opfXml, "item");
        gsf_xml_out_add_cstr(opfXml, "id", "toc");
        gsf_xml_out_add_cstr(opfXml, "href", "toc.xhtml");
        gsf_xml_out_add_cstr(opfXml, "media-type", "application/xhtml+xml");
        gsf_xml_out_end_element(opfXml);  
    }
    // </manifest>
    gsf_xml_out_end_element(opfXml);

    // <spine>
    gsf_xml_out_start_element(opfXml, "spine");
    gsf_xml_out_add_cstr(opfXml, "toc", "ncx");
    
    
    if (!m_exp_opt.bEpub2)
    {
        gsf_xml_out_start_element(opfXml, "itemref");
        gsf_xml_out_add_cstr(opfXml, "idref","toc");
        gsf_xml_out_end_element(opfXml);
    }
    
    for(std::vector<std::string>::iterator i = m_opsId.begin(); i != m_opsId.end(); i++)
    {
        gsf_xml_out_start_element(opfXml, "itemref");
        gsf_xml_out_add_cstr(opfXml, "idref", (*i).c_str());
        gsf_xml_out_end_element(opfXml);
    }


    
    // </spine>
    gsf_xml_out_end_element(opfXml);

    // </package>
    gsf_xml_out_end_element(opfXml);
    gsf_output_close(opf);
    return compress();
}