예제 #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;
}
예제 #2
0
/* NOTE : every path through this must push something onto obj_stack. */
static void
gogo_start (GsfXMLIn *xin, xmlChar const **attrs)
{
	GogXMLReadState *state = (GogXMLReadState *)xin->user_state;
	xmlChar const *type = NULL, *role = NULL;
	GogObject *res;
	unsigned i;

	for (i = 0; attrs != NULL && attrs[i] && attrs[i+1] ; i += 2)
		if (0 == strcmp (attrs[i], "type"))
			type = attrs[i+1];
		else if (0 == strcmp (attrs[i], "role"))
			role = attrs[i+1];

	if (NULL != type) {
		GType t = g_type_from_name (type);
		if (t == 0) {
			res = (GogObject *)gog_plot_new_by_name (type);
			if (NULL == res)
				res = (GogObject *)gog_trend_line_new_by_name (type);
		} else if (g_type_is_a (t, GOG_TYPE_OBJECT) && !G_TYPE_IS_ABSTRACT (t))
			res = g_object_new (t, NULL);
		else
			res = NULL;

		if (res == NULL) {
			g_warning ("unknown type '%s'", type);
		}
		if (GOG_IS_GRAPH (res))
			((GogGraph *) res)->doc = (GODoc *) g_object_get_data (G_OBJECT (gsf_xml_in_get_input (xin)), "document");
	} else
		res = NULL;

	if (role != NULL) {
		if (strcmp (role, GOG_BACKPLANE_OLD_ROLE_NAME) == 0)
			res = gog_object_add_by_name (state->obj, GOG_BACKPLANE_NEW_ROLE_NAME, res);
		else
			res = gog_object_add_by_name (state->obj, role, res);
	}
	if (res != NULL) {
		res->explicitly_typed_role = (type != NULL);
		if (GO_IS_PERSIST (res))
			go_persist_prep_sax (GO_PERSIST (res), xin, attrs);
	}

	state->obj_stack = g_slist_prepend (state->obj_stack, state->obj);
	state->obj = res;
}