Exemple #1
0
/**
 * gsf_open_pkg_parse_rel_by_id:
 * @xin: #GsfXMLIn
 * @id: target id
 * @dtd: #GsfXMLInNode
 * @ns: #GsfXMLInNS
 *
 * Convenience function to parse a related part.
 *
 * Returns: (transfer full): %NULL on success or a #GError on failure.
 **/
GError *
gsf_open_pkg_parse_rel_by_id (GsfXMLIn *xin, char const *id,
			      GsfXMLInNode const *dtd,
			      GsfXMLInNS const *ns)
{
	GError *res = NULL;
	GsfInput *cur_stream, *part_stream;

	g_return_val_if_fail (xin != NULL, NULL);

	cur_stream = gsf_xml_in_get_input (xin);

	if (NULL == id)
		return g_error_new (gsf_input_error_id(), gsf_open_pkg_error_id (),
			_("Missing id for part in '%s'"),
			gsf_input_name (cur_stream) );

	part_stream = gsf_open_pkg_open_rel_by_id (cur_stream, id, &res);
	if (NULL != part_stream) {
		GsfXMLInDoc *doc = gsf_xml_in_doc_new (dtd, ns);

		if (!gsf_xml_in_doc_parse (doc, part_stream, xin->user_state))
			res = g_error_new (gsf_input_error_id(), gsf_open_pkg_error_id (),
				_("Part '%s' in '%s' from '%s' is corrupt!"),
				id,
				gsf_input_name (part_stream),
				gsf_input_name (cur_stream) );
		gsf_xml_in_doc_free (doc);

		g_object_unref (part_stream);
	}
	return res;
}
Exemple #2
0
static GsfOpenPkgRels *
gsf_open_pkg_get_rels (GsfInput *opkg)
{
	GsfOpenPkgRels *rels = NULL;

	g_return_val_if_fail (opkg != NULL, NULL);

	if (NULL == (rels = g_object_get_data (G_OBJECT (opkg), "OpenPkgRels"))) {
		char const *part_name = gsf_input_name (opkg);
		GsfXMLInDoc *rel_doc;
		GsfInput *rel_stream;

		if (NULL != part_name) {
			GsfInfile *container = gsf_input_container (opkg);
			char *rel_name;

			g_return_val_if_fail (container != NULL, NULL);

			rel_name = g_strconcat (part_name, ".rels", NULL);
			rel_stream = gsf_infile_child_by_vname (container, "_rels", rel_name, NULL);
			g_free (rel_name);
		} else /* the root */
			rel_stream = gsf_infile_child_by_vname (GSF_INFILE (opkg), "_rels", ".rels", NULL);

		if (NULL != rel_stream) {
			rels = g_new (GsfOpenPkgRels, 1);
			rels->by_id = g_hash_table_new_full (g_str_hash, g_str_equal,
				NULL, (GDestroyNotify)gsf_open_pkg_rel_free);
			rels->by_type = g_hash_table_new (g_str_hash, g_str_equal);

			rel_doc = gsf_xml_in_doc_new (open_pkg_rel_dtd, open_pkg_ns);
			(void) gsf_xml_in_doc_parse (rel_doc, rel_stream, rels);

			gsf_xml_in_doc_free (rel_doc);
			g_object_unref (rel_stream);
		}

		g_object_set_data_full (G_OBJECT (opkg), "OpenPkgRels", rels,
			(GDestroyNotify) gsf_open_pkg_rels_free);
	}

	return rels;
}
Exemple #3
0
/**
 * gnm_ft_new_from_file:
 * @context:
 * @filename: The filename to load from
 *
 * Create a new GnmFT and load a template file
 * into it.
 *
 * Return value: (transfer full): a new GnmFT (or NULL on error)
 **/
GnmFT *
gnm_ft_new_from_file (char const *filename, GOCmdContext *cc)
{
	GnmFT *ft = NULL;
	GsfXMLInDoc *doc = NULL;
	GnmLocale *locale;
	gboolean ok = FALSE;
	GsfInput *input = NULL;

	g_return_val_if_fail (filename != NULL, NULL);

	input = gsf_input_stdio_new (filename, NULL);
	if (!input) {
		go_cmd_context_error_import
			(cc,
			 _("Error while opening autoformat template"));
		goto done;
	}

	doc = gsf_xml_in_doc_new (template_dtd, template_ns);
	if (doc == NULL)
		goto done;
	gsf_xml_in_doc_set_unknown_handler (doc, &template_sax_unknown);

	ft = gnm_ft_new ();
	ft->filename = g_strdup (filename);

	locale = gnm_push_C_locale ();
	ok = gsf_xml_in_doc_parse (doc, input, ft);
	gnm_pop_C_locale (locale);

 done:
	if (input) g_object_unref (input);
	if (doc) gsf_xml_in_doc_free (doc);

	if (ft && !ok) {
		gnm_ft_free (ft);
		ft = NULL;
	}

	return ft;
}