gboolean go_xml_node_get_bool (xmlNodePtr node, char const *name, gboolean *val) { xmlChar *buf = go_xml_node_get_cstr (node, name); if (buf == NULL) return FALSE; *val = (!strcmp (CXML2C (buf), "1") || 0 == g_ascii_strcasecmp (CXML2C (buf), "true")); xmlFree (buf); return TRUE; }
static void sax_information (GsfXMLIn *xin, xmlChar const **attrs) { GnmFT *ft = (GnmFT *)xin->user_state; for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) { if (attr_eq (attrs[0], "author")) gnm_ft_set_author (ft, CXML2C (attrs[1])); else if (attr_eq (attrs[0], "name")) gnm_ft_set_name (ft, CXML2C (attrs[1])); else if (attr_eq (attrs[0], "description")) gnm_ft_set_description (ft, CXML2C (attrs[1])); } }
static void go_plugin_service_resource_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error) { GOPluginServiceResource *sr = GO_PLUGIN_SERVICE_RESOURCE (service); char *data = NULL; gsize length; xmlChar *file; GO_INIT_RET_ERROR_INFO (ret_error); sr->id = xml2c (go_xml_node_get_cstr (tree, "id")); if (!sr->id) goto error; file = go_xml_node_get_cstr (tree, "file"); if (file) { char *absfile; gboolean ok; if (!g_path_is_absolute (CXML2C (file))) { char const *dir = go_plugin_get_dir_name (go_plugin_service_get_plugin (service)); absfile = g_build_filename (dir, CXML2C (file), NULL); } else absfile = g_strdup (CXML2C (file)); xmlFree (file); ok = g_file_get_contents (absfile, &data, &length, NULL); g_free (absfile); if (!ok) goto error; } else { data = xml2c (go_xml_node_get_cstr (tree, "data")); length = strlen (data); } if (!data) goto error; /* No encoding case */ sr->value = g_string_sized_new (length); g_string_append_len (sr->value, data, length); g_free (data); return; error: *ret_error = go_error_info_new_str (_("Invalid resource service")); g_free (data); }
static char * xml2c (xmlChar *src) { char *dst = g_strdup (CXML2C (src)); xmlFree (src); return dst; }
/** * gnumeric_xml_read_format_template_category : * Open an XML file and read a FormatTemplateCategory */ static FormatTemplateCategory * gnumeric_xml_read_format_template_category (char const *dir_name) { gchar *file_name; xmlDocPtr doc; xmlNodePtr node; FormatTemplateCategory *category = NULL; g_return_val_if_fail (dir_name != NULL, NULL); file_name = g_build_filename (dir_name, ".category", NULL); doc = xmlParseFile (file_name); if (doc != NULL && doc->xmlRootNode != NULL && xmlSearchNsByHref (doc, doc->xmlRootNode, (xmlChar *)"http://www.gnome.org/gnumeric/format-template-category/v1") != NULL && strcmp (CXML2C (doc->xmlRootNode->name), "FormatTemplateCategory") == 0 && (node = go_xml_get_child_by_name (doc->xmlRootNode, "Information")) != NULL) { xmlChar *name = xmlGetProp (node, (xmlChar *)"name"); if (name != NULL) { xmlChar *description = xmlGetProp (node, (xmlChar *)"description"); category = g_new (FormatTemplateCategory, 1); category->directory = g_strdup (dir_name); category->name = g_strdup ((gchar *)name); category->description = g_strdup ((gchar *)description); category->is_writable = (access (dir_name, W_OK) == 0); if (description != NULL) xmlFree (description); xmlFree (name); } } xmlFreeDoc (doc); g_free (file_name); return category; }
static void content_start (GsfXMLIn *xin, xmlChar const **attrs) { SheetObject *so = gnm_xml_in_cur_obj (xin); SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so); char const *image_type = NULL, *image_name = NULL; for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) if (attr_eq (attrs[0], "image-type")) image_type = CXML2C (attrs[1]); else if (attr_eq (attrs[0], "name")) image_name = CXML2C (attrs[1]); soi->type = g_strdup (image_type); if (image_name) soi->name = g_strdup (image_name); }
gboolean go_xml_node_get_double (xmlNodePtr node, char const *name, double *val) { xmlChar *buf; char *end; gboolean ok; buf = go_xml_node_get_cstr (node, name); if (buf == NULL) return FALSE; errno = 0; /* strto(ld) sets errno, but does not clear it. */ *val = strtod (CXML2C (buf), &end); ok = (CXML2C (buf) != end) && *end == 0 && errno != ERANGE; xmlFree (buf); return ok; }
gboolean go_xml_node_get_int (xmlNodePtr node, char const *name, int *val) { xmlChar *buf; char *end; gboolean ok; long l; buf = go_xml_node_get_cstr (node, name); if (buf == NULL) return FALSE; errno = 0; /* strto(ld) sets errno, but does not clear it. */ *val = l = strtol (CXML2C (buf), &end, 10); ok = (CXML2C (buf) != end) && *end == 0 && errno != ERANGE && (*val == l); xmlFree (buf); return ok; }
gboolean go_xml_node_get_gocolor (xmlNodePtr node, char const *name, GOColor *res) { xmlChar *color; int r, g, b; color = xmlGetProp (node, CC2XML (name)); if (color == NULL) return FALSE; if (sscanf (CXML2C (color), "%X:%X:%X", &r, &g, &b) == 3) { r >>= 8; g >>= 8; b >>= 8; *res = GO_COLOR_FROM_RGBA (r,g,b,0xff); xmlFree (color); return TRUE; }
static gboolean template_sax_unknown (GsfXMLIn *xin, xmlChar const *elem, xmlChar const **attrs) { g_return_val_if_fail (xin != NULL, FALSE); g_return_val_if_fail (xin->doc != NULL, FALSE); g_return_val_if_fail (xin->node != NULL, FALSE); if (GMR == xin->node->ns_id && 0 == strcmp (xin->node->id, "MEMBERS_MEMBER")) { char const *type_name = gsf_xml_in_check_ns (xin, CXML2C (elem), GNM); if (type_name && strcmp (type_name, "Style") == 0) { gnm_xml_prep_style_parser (xin, attrs, sax_style_handler, NULL); return TRUE; } } return FALSE; }
static void html_read_table (htmlNodePtr cur, htmlDocPtr doc, WorkbookView *wb_view, GnmHtmlTableCtxt *tc) { Workbook *wb; htmlNodePtr ptr, ptr2; g_return_if_fail (cur != NULL); g_return_if_fail (wb_view != NULL); wb = wb_view_get_workbook (wb_view); for (ptr = cur->children; ptr != NULL ; ptr = ptr->next) { if (ptr->type != XML_ELEMENT_NODE) continue; if (xmlStrEqual (ptr->name, CC2XML ("caption"))) { xmlBufferPtr buf; buf = xmlBufferCreate (); for (ptr2 = ptr->children; ptr2 != NULL ; ptr2 = ptr2->next) { htmlNodeDump (buf, doc, ptr2); } if (buf->use > 0) { char *name; name = g_strndup (CXML2C (buf->content), buf->use); tc->sheet = html_get_sheet (name, wb); g_free (name); } xmlBufferFree (buf); } else if (xmlStrEqual (ptr->name, CC2XML ("thead")) || xmlStrEqual (ptr->name, CC2XML ("tfoot")) || xmlStrEqual (ptr->name, CC2XML ("tbody"))) { html_read_rows (ptr, doc, wb, tc); } else if (xmlStrEqual (ptr->name, CC2XML ("tr"))) { html_read_rows (cur, doc, wb, tc); break; } } }
static inline gboolean attr_eq (const xmlChar *a, const char *s) { return !strcmp (CXML2C (a), s); }
static void html_read_row (htmlNodePtr cur, htmlDocPtr doc, GnmHtmlTableCtxt *tc) { htmlNodePtr ptr; int col = -1; for (ptr = cur->children; ptr != NULL ; ptr = ptr->next) { if (xmlStrEqual (ptr->name, CC2XML ("td")) || xmlStrEqual (ptr->name, CC2XML ("th"))) { GString *buf; xmlBufferPtr a_buf; xmlAttrPtr props; int colspan = 1; int rowspan = 1; GnmCellPos pos; GnmStyle *mstyle; GSList *hrefs = NULL; GnmHLink *lnk = NULL; /* Check whether we need to skip merges from above */ pos.row = tc->row; pos.col = col + 1; while (gnm_sheet_merge_contains_pos (tc->sheet, &pos)) { col++; pos.col++; } /* Do we span across multiple rows or cols? */ props = ptr->properties; while (props) { if (xmlStrEqual (props->name, CC2XML ("colspan")) && props->children) colspan = atoi (CXML2C (props->children->content)); if (xmlStrEqual (props->name, CC2XML ("rowspan")) && props->children) rowspan = atoi (CXML2C (props->children->content)); props = props->next; } if (colspan < 1) colspan = 1; if (rowspan < 1) rowspan = 1; /* Let's figure out the content of the cell */ buf = g_string_new (NULL); a_buf = xmlBufferCreate (); mstyle = gnm_style_new_default (); if (xmlStrEqual (ptr->name, CC2XML ("th"))) gnm_style_set_font_bold (mstyle, TRUE); html_read_content (ptr, buf, mstyle, a_buf, &hrefs, TRUE, doc, tc); if (g_slist_length (hrefs) >= 1 && buf->len > 0) { /* One hyperlink, and text to make it * visible */ char *url; xmlBufferPtr h_buf = xmlBufferCreate (); hrefs = g_slist_reverse (hrefs); htmlNodeDump ( h_buf, doc, (htmlNodePtr)hrefs->data); url = g_strndup ( CXML2C (h_buf->content), h_buf->use); if (strncmp (url, "mailto:", strlen ("mailto:")) == 0) lnk = gnm_hlink_new ( gnm_hlink_email_get_type (), tc->sheet); else lnk = gnm_hlink_new ( gnm_hlink_url_get_type (), tc->sheet); gnm_hlink_set_target (lnk, url); gnm_style_set_hlink (mstyle, lnk); gnm_style_set_font_uline (mstyle, UNDERLINE_SINGLE); gnm_style_set_font_color (mstyle, gnm_color_new_go (GO_COLOR_BLUE)); g_free (url); xmlBufferFree (h_buf); } if (g_slist_length (hrefs) > 1 || buf->len <= 0) { /* Multiple links, * or no text to give hyperlink style, * so put them in a comment */ GSList *l; for (l = hrefs; l != NULL; l = l->next) { htmlNodeDump (a_buf, doc, (htmlNodePtr)l->data); xmlBufferAdd (a_buf, CC2XML ("\n"), -1); } } g_slist_free (hrefs); if (buf->len > 0) { GnmCell *cell = sheet_cell_fetch (tc->sheet, col + 1, tc->row); sheet_style_set_pos (tc->sheet, col + 1, tc->row, mstyle); gnm_cell_set_text (cell, buf->str); } else gnm_style_unref (mstyle); if (a_buf->use > 0) { char *name; name = g_strndup (CXML2C (a_buf->content), a_buf->use); cell_set_comment (tc->sheet, &pos, NULL, name, NULL); g_free (name); } g_string_free (buf, TRUE); xmlBufferFree (a_buf); /* If necessary create the merge */ if (colspan > 1 || rowspan > 1) { GnmRange range; GnmRange *r = ⦥ range_init (r, col + 1, tc->row, col + colspan, tc->row + rowspan - 1); gnm_sheet_merge_add (tc->sheet, r, FALSE, NULL); } col += colspan; } } }