static void gnm_soi_prep_sax_parser (SheetObject *so, GsfXMLIn *xin, xmlChar const **attrs, G_GNUC_UNUSED GnmConventions const *convs) { static GsfXMLInNode const dtd[] = { GSF_XML_IN_NODE (CONTENT, CONTENT, -1, "Content", GSF_XML_CONTENT, &content_start, &content_end), GSF_XML_IN_NODE_END }; static GsfXMLInDoc *doc = NULL; SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so); if (NULL == doc) doc = gsf_xml_in_doc_new (dtd, NULL); gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs); for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) { if (gnm_xml_attr_double (attrs, "crop-top", &soi->crop_top)) ; else if (gnm_xml_attr_double (attrs, "crop-bottom", &soi->crop_bottom)) /* Nothing */ ; else if (gnm_xml_attr_double (attrs, "crop-left", &soi->crop_left)) /* Nothing */ ; else if (gnm_xml_attr_double (attrs, "crop-right", &soi->crop_right)) /* Nothing */ ; } }
/** * 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; }
GogObject * gog_object_new_from_input (GsfInput *input, gpointer user_unserialize) { GogObject *res = NULL; GogXMLReadState *state = g_new0 (GogXMLReadState, 1); if (NULL == gog_sax_doc) { gog_sax_doc = gsf_xml_in_doc_new (gog_dtd, NULL); go_xml_in_doc_dispose_on_exit (&gog_sax_doc); } state->user_unserialize = user_unserialize; if (gsf_xml_in_doc_parse (gog_sax_doc, input, state)) { res = state->obj; } g_free (state); return res; }
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; }
/** * gog_object_sax_push_parser: * @xin: #GsfXMLIn * @attrs: XML attributes * @handler: (scope call): callback * @user_unserialize: user data for #GOData reading * @user_data: user data for @handler * * Unserializes a #GogObject using @handler when done. **/ void gog_object_sax_push_parser (GsfXMLIn *xin, xmlChar const **attrs, GogObjectSaxHandler handler, gpointer user_unserialize, gpointer user_data) { GogXMLReadState *state; if (NULL == gog_sax_doc) { gog_sax_doc = gsf_xml_in_doc_new (gog_dtd, NULL); go_xml_in_doc_dispose_on_exit (&gog_sax_doc); } state = g_new0 (GogXMLReadState, 1); state->handler = handler; state->user_data = user_data; state->user_unserialize = user_unserialize; gsf_xml_in_push_state (xin, gog_sax_doc, state, (GsfXMLInExtDtor) go_sax_parser_done, attrs); }
/** * 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; }
static void gnm_so_path_prep_sax_parser (SheetObject *so, GsfXMLIn *xin, xmlChar const **attrs, G_GNUC_UNUSED GnmConventions const *convs) { static GsfXMLInNode const dtd[] = { GSF_XML_IN_NODE (SOPATH, SOPATH, -1, "SheetObjectPath", GSF_XML_NO_CONTENT, NULL, NULL), GSF_XML_IN_NODE (SOPATH, PATH, -1, "Path", GSF_XML_NO_CONTENT, &sop_sax_path, NULL), GSF_XML_IN_NODE (SOPATH, STYLE, -1, "Style", GSF_XML_NO_CONTENT, &sop_sax_style, NULL), GSF_XML_IN_NODE_END }; static GsfXMLInDoc *doc = NULL; GnmSOPath *sop = GNM_SO_PATH(so); if (NULL == doc) { doc = gsf_xml_in_doc_new (dtd, NULL); gnm_xml_in_doc_dispose_on_exit (&doc); } gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs); for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) if (attr_eq (attrs[0], "Label")) g_object_set (G_OBJECT (sop), "text", attrs[1], NULL); else if (attr_eq (attrs[0], "LabelFormat")) { GOFormat * fmt = go_format_new_from_XL (attrs[1]); if (go_format_is_markup (fmt)) g_object_set (G_OBJECT (sop), "markup", go_format_get_markup (fmt), NULL); go_format_unref (fmt); } else if (attr_eq (attrs[0], "Path")) { GOPath *path = go_path_new_from_svg (attrs[1]); if (path) { g_object_set (G_OBJECT (sop), "path", path, NULL); go_path_free (path); } } }