From: Andrea Zagli Date: Mon, 12 Jun 2017 20:03:25 +0000 (+0200) Subject: Moved function ZakFormForm::element_xml_parsing in ZakFormElement. X-Git-Tag: v0.1.0~1^2~6^2~1 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=62383b18f6e62971de1bdc94942ebde570e57ce4;p=zakform%2Flibzakform Moved function ZakFormForm::element_xml_parsing in ZakFormElement. --- diff --git a/src/form.c b/src/form.c index 309a2b4..1c90d3a 100644 --- a/src/form.c +++ b/src/form.c @@ -142,105 +142,6 @@ zak_form_form_init (ZakFormForm *zak_form_form) zak_form_load_modules (); } -void -zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element, xmlNode *xnode) -{ - ZakFormFormPrivate *priv; - - gchar *type; - guint i; - - ZakFormElementExtension *extension; - ZakFormElementFilter *filter; - ZakFormElementValidator *validator; - - ZakFormElementExtensionConstructorFunc extension_constructor; - ZakFormElementFilterConstructorFunc filter_constructor; - ZakFormElementValidatorConstructorFunc validator_constructor; - - gboolean to_unlink; - xmlNode *xnode_tmp; - - priv = zak_form_form_get_instance_private (zakform); - - xnode = xnode->children; - while (xnode) - { - to_unlink = FALSE; - - if (xmlStrcmp (xnode->name, (const xmlChar *)"extension") == 0) - { - type = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type"); - - extension_constructor = zak_form_get_form_element_extension (type); - if (extension_constructor != NULL) - { - extension = extension_constructor (); - zak_form_element_add_extension (element, extension); - - zak_form_element_extension_xml_parsing (extension, xnode); - } - else - { - g_warning ("Extension «%s» not found.", type); - } - - to_unlink = TRUE; - } - else if (xmlStrcmp (xnode->name, (const xmlChar *)"filter") == 0) - { - type = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type"); - - filter_constructor = zak_form_get_form_element_filter (type); - if (filter_constructor != NULL) - { - filter = filter_constructor (); - zak_form_element_add_filter (element, filter); - - zak_form_element_filter_xml_parsing (filter, xnode); - } - else - { - g_warning ("Filter «%s» not found.", type); - } - - to_unlink = TRUE; - } - else if (xmlStrcmp (xnode->name, (const xmlChar *)"validator") == 0) - { - type = (gchar *)xmlGetProp (xnode, (const xmlChar *)"type"); - - validator_constructor = zak_form_get_form_element_validator (type); - if (validator_constructor != NULL) - { - validator = validator_constructor (); - zak_form_element_add_validator (element, validator); - - zak_form_element_validator_xml_parsing (validator, xnode); - } - else - { - g_warning ("Validator «%s» not found.", type); - } - - to_unlink = TRUE; - } - - if (to_unlink) - { - xnode_tmp = xnode; - } - - xnode = xnode->next; - - if (to_unlink) - { - xmlUnlinkNode (xnode_tmp); - xmlFreeNode (xnode_tmp); - } - } -} - /** * zak_form_form_load_from_xml: * @zakform: @@ -302,7 +203,6 @@ zak_form_form_load_from_xml (ZakFormForm *zakform, xmlDoc *xmldoc) zak_form_form_add_element (zakform, element); cur_clean = xmlCopyNode (cur, 1); - zak_form_form_element_xml_parsing (zakform, element, cur_clean); zak_form_element_xml_parsing (element, cur_clean); xmlUnlinkNode (cur_clean); diff --git a/src/formelement.c b/src/formelement.c index 47d5bce..824952f 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -24,8 +24,11 @@ #include +#include "commons.h" #include "zakformmarshal.h" #include "formelement.h" +#include "formelementfilter.h" +#include "formelementvalidator.h" enum { @@ -1600,6 +1603,16 @@ zak_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode) { xmlNode *cur; + gchar *type; + + ZakFormElementExtension *extension; + ZakFormElementFilter *filter; + ZakFormElementValidator *validator; + + ZakFormElementExtensionConstructorFunc extension_constructor; + ZakFormElementFilterConstructorFunc filter_constructor; + ZakFormElementValidatorConstructorFunc validator_constructor; + gboolean to_unlink; xmlNode *xnode_tmp; @@ -1608,7 +1621,64 @@ zak_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode) { to_unlink = FALSE; - if (xmlStrEqual (cur->name, (const xmlChar *)"name")) + if (xmlStrEqual (cur->name, (const xmlChar *)"extension")) + { + type = (gchar *)xmlGetProp (cur, (const xmlChar *)"type"); + + extension_constructor = zak_form_get_form_element_extension (type); + if (extension_constructor != NULL) + { + extension = extension_constructor (); + zak_form_element_add_extension (element, extension); + + zak_form_element_extension_xml_parsing (extension, cur); + } + else + { + g_warning ("Extension «%s» not found.", type); + } + + to_unlink = TRUE; + } + else if (xmlStrEqual (cur->name, (const xmlChar *)"filter")) + { + type = (gchar *)xmlGetProp (cur, (const xmlChar *)"type"); + + filter_constructor = zak_form_get_form_element_filter (type); + if (filter_constructor != NULL) + { + filter = filter_constructor (); + zak_form_element_add_filter (element, filter); + + zak_form_element_filter_xml_parsing (filter, cur); + } + else + { + g_warning ("Filter «%s» not found.", type); + } + + to_unlink = TRUE; + } + else if (xmlStrEqual (cur->name, (const xmlChar *)"validator")) + { + type = (gchar *)xmlGetProp (cur, (const xmlChar *)"type"); + + validator_constructor = zak_form_get_form_element_validator (type); + if (validator_constructor != NULL) + { + validator = validator_constructor (); + zak_form_element_add_validator (element, validator); + + zak_form_element_validator_xml_parsing (validator, cur); + } + else + { + g_warning ("Validator «%s» not found.", type); + } + + to_unlink = TRUE; + } + else if (xmlStrEqual (cur->name, (const xmlChar *)"name")) { zak_form_element_set_name (element, (const gchar *)xmlNodeGetContent (cur)); to_unlink = TRUE;