Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
static void
go_plugin_service_file_saver_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error)
{
	xmlNode *information_node;
	gchar *description;

	GO_INIT_RET_ERROR_INFO (ret_error);
	information_node = go_xml_get_child_by_name (tree, "information");
	if (information_node != NULL) {
		xmlNode *node = go_xml_get_child_by_name_by_lang
			(information_node, "description");
		description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
	} else {
		description = NULL;
	}

	if (description != NULL) {
		int scope = GO_FILE_SAVE_WORKBOOK;
		int level = GO_FILE_FL_WRITE_ONLY;
		GOPluginServiceFileSaver *psfs =
			GO_PLUGIN_SERVICE_FILE_SAVER (service);

		psfs->file_extension =
			xml2c (go_xml_node_get_cstr (tree, "file_extension"));

		psfs->mime_type =
			xml2c (go_xml_node_get_cstr (tree, "mime_type"));

		psfs->description = description;

		(void)go_xml_node_get_enum
			(tree, "format_level",
			 GO_TYPE_FILE_FORMAT_LEVEL, &level);
		psfs->format_level = (GOFileFormatLevel)level;

		if (!go_xml_node_get_int (tree, "default_saver_priority", &(psfs->default_saver_priority)))
			psfs->default_saver_priority = -1;

		(void)go_xml_node_get_enum
			(tree, "save_scope",
			 GO_TYPE_FILE_SAVE_SCOPE, &scope);
		psfs->save_scope = (GOFileSaveScope)scope;

		if (!go_xml_node_get_bool (tree, "overwrite_files", &(psfs->overwrite_files)))
			psfs->overwrite_files = TRUE;
	} else {
		*ret_error = go_error_info_new_str (_("File saver has no description"));
	}
}
Ejemplo n.º 3
0
static void
go_plugin_service_file_opener_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo **ret_error)
{
	int priority;
	gboolean has_probe;
	gboolean encoding_dependent;
	xmlNode *information_node;
	gchar *description;

	GO_INIT_RET_ERROR_INFO (ret_error);
	if (go_xml_node_get_int (tree, "priority", &priority))
		priority = CLAMP (priority, 0, 100);
	else
		priority = 50;

	if (!go_xml_node_get_bool (tree, "probe", &has_probe))
		has_probe = TRUE;
	if (!go_xml_node_get_bool (tree, "encoding_dependent", &encoding_dependent))
		encoding_dependent = FALSE;

	information_node = go_xml_get_child_by_name (tree, "information");
	if (information_node != NULL) {
		xmlNode *node = go_xml_get_child_by_name_by_lang
			(information_node, "description");
		description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
	} else {
		description = NULL;
	}
	if (description != NULL) {
		GSList *suffixes = NULL, *mimes = NULL;
		xmlNode *list, *node;
		GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (service);

		list = go_xml_get_child_by_name (tree, "suffixes");
		if (list != NULL) {
			for (node = list->xmlChildrenNode; node != NULL; node = node->next) {
				char *tmp;

				if (strcmp (node->name, "suffix"))
					continue;

				tmp = xml2c (xmlNodeGetContent (node));
				if (!tmp)
					continue;

				GO_SLIST_PREPEND (suffixes, tmp);
			}
		}
		GO_SLIST_REVERSE (suffixes);

		list = go_xml_get_child_by_name (tree, "mime-types");
		if (list != NULL) {
			for (node = list->xmlChildrenNode; node != NULL; node = node->next) {
				char *tmp;

				if (strcmp (node->name, "mime-type"))
					continue;

				tmp = xml2c (xmlNodeGetContent (node));
				if (!tmp)
					continue;

				GO_SLIST_PREPEND (mimes, tmp);
			}
		}
		GO_SLIST_REVERSE (mimes);

		service_file_opener->priority = priority;
		service_file_opener->has_probe = has_probe;
		service_file_opener->encoding_dependent	= encoding_dependent;
		service_file_opener->description = description;
		service_file_opener->suffixes	= suffixes;
		service_file_opener->mimes	= mimes;
	} else {
		*ret_error = go_error_info_new_str (_("File opener has no description"));
	}
}