]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Refactored ZakFormElementFilter::xml_parsing.
authorAndrea Zagli <azagli@libero.it>
Sat, 22 Apr 2017 08:55:36 +0000 (10:55 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 22 Apr 2017 08:55:36 +0000 (10:55 +0200)
src/form.c
src/formelement.c
src/formelementfilter.c
src/formelementfilter.h
src/formelementfilterluc.c
src/formelementfilterluc.h
src/formelementfiltertrim.c
src/formelementfiltertrim.h

index c58bbeb64da2efca17a2357214fa0fcab3920f38..c14a23567b067d55bdbcad9ae462f25bbd3feaf1 100644 (file)
@@ -38,7 +38,6 @@ typedef gboolean (* FormElementXmlParsingFunc) (ZakFormElement *, xmlNodePtr);
 typedef GObject *(* FormElementExtensionConstructorFunc) (void);
 typedef gboolean (* FormElementExtensionXmlParsingFunc) (GObject *, xmlNodePtr);
 typedef ZakFormElementFilter *(* FormElementFilterConstructorFunc) (void);
-typedef gboolean (* FormElementFilterXmlParsingFunc) (ZakFormElementFilter *, xmlNodePtr);
 typedef ZakFormElementValidator *(* FormElementValidatorConstructorFunc) (void);
 typedef ZakFormValidator *(* FormValidatorConstructorFunc) (void);
 
@@ -167,7 +166,6 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element
        FormElementExtensionConstructorFunc extension_constructor;
        FormElementExtensionXmlParsingFunc extension_xml_parsing;
        FormElementFilterConstructorFunc filter_constructor;
-       FormElementFilterXmlParsingFunc filter_xml_parsing;
        FormElementValidatorConstructorFunc validator_constructor;
 
        gboolean to_unlink;
@@ -233,15 +231,7 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element
                                                                                        filter = filter_constructor ();
                                                                                        zak_form_element_add_filter (element, filter);
 
-                                                                                       if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
-                                                                                                            g_strconcat (type, "_xml_parsing", NULL),
-                                                                                                            (gpointer *)&filter_xml_parsing))
-                                                                                               {
-                                                                                                       if (filter_xml_parsing != NULL)
-                                                                                                               {
-                                                                                                                       filter_xml_parsing (filter, xnode);
-                                                                                                               }
-                                                                                               }
+                                                                                       zak_form_element_filter_xml_parsing (filter, xnode);
 
                                                                                        break;
                                                                                }
@@ -254,7 +244,7 @@ zak_form_form_element_xml_parsing (ZakFormForm *zakform, ZakFormElement *element
 
                                        to_unlink = TRUE;
                                }
-                   else if (xmlStrcmp (xnode->name, (const xmlChar *)"validator") == 0)
+                       else if (xmlStrcmp (xnode->name, (const xmlChar *)"validator") == 0)
                                {
                                        type = xmlGetProp (xnode, (const xmlChar *)"type");
 
index bac1f7ecceaace4b692f45acf55d1d83bd3379ee..f94eb62f56f2e6e2330210f925c61ed09967c378 100644 (file)
@@ -304,7 +304,7 @@ zak_form_element_filter (ZakFormElement *element)
                        value = zak_form_element_get_value (element);
 
                        val = zak_form_element_filter_filter ((ZakFormElementFilter *)g_ptr_array_index (priv->pa_filters, i),
-                                                                                                 value);
+                                                             value);
                        zak_form_element_set_value (element, val);
                }
 }
index fe3ce9ad7baebb8a0b6e39ae09f3bf1c3360a4d5..3439ac97f85e6bc0c88bfa941596aaf1e2237849 100644 (file)
@@ -32,13 +32,13 @@ static void zak_form_element_filter_class_init (ZakFormElementFilterClass *class
 static void zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter);
 
 static void zak_form_element_filter_set_property (GObject *object,
-                               guint property_id,
-                               const GValue *value,
-                               GParamSpec *pspec);
+                                                  guint property_id,
+                                                  const GValue *value,
+                                                  GParamSpec *pspec);
 static void zak_form_element_filter_get_property (GObject *object,
-                               guint property_id,
-                               GValue *value,
-                               GParamSpec *pspec);
+                                                  guint property_id,
+                                                  GValue *value,
+                                                  GParamSpec *pspec);
 
 static void zak_form_element_filter_dispose (GObject *gobject);
 static void zak_form_element_filter_finalize (GObject *gobject);
@@ -61,11 +61,11 @@ zak_form_element_filter_class_init (ZakFormElementFilterClass *class)
        object_class->finalize = zak_form_element_filter_finalize;
 
        g_object_class_install_property (object_class, PROP_ENABLED,
-                                                                        g_param_spec_boolean ("enabled",
-                                                                                                                  "Enabled",
-                                                                                                                  "Enabled",
-                                                                                                                  TRUE,
-                                                                                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+                                        g_param_spec_boolean ("enabled",
+                                                              "Enabled",
+                                                              "Enabled",
+                                                              TRUE,
+                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 }
 
 static void
@@ -74,6 +74,25 @@ zak_form_element_filter_init (ZakFormElementFilter *zak_form_element_filter)
        ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
 }
 
+gboolean
+zak_form_element_filter_xml_parsing (ZakFormElementFilter *self, xmlNode *xnode)
+{
+       gboolean ret;
+
+       g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_FILTER (self), FALSE);
+
+       if (ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->xml_parsing!= NULL)
+               {
+                       ret = ZAK_FORM_ELEMENT_FILTER_GET_CLASS (self)->xml_parsing (self, xnode);
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
+}
+
 gchar
 *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value)
 {
@@ -125,9 +144,9 @@ zak_form_element_filter_set_enabled (ZakFormElementFilter *filter, gboolean enab
 /* PRIVATE */
 static void
 zak_form_element_filter_set_property (GObject *object,
-                   guint property_id,
-                   const GValue *value,
-                   GParamSpec *pspec)
+                                      guint property_id,
+                                      const GValue *value,
+                                      GParamSpec *pspec)
 {
        ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)object;
        ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
@@ -146,9 +165,9 @@ zak_form_element_filter_set_property (GObject *object,
 
 static void
 zak_form_element_filter_get_property (GObject *object,
-                   guint property_id,
-                   GValue *value,
-                   GParamSpec *pspec)
+                                      guint property_id,
+                                      GValue *value,
+                                      GParamSpec *pspec)
 {
        ZakFormElementFilter *zak_form_element_filter = (ZakFormElementFilter *)object;
        ZakFormElementFilterPrivate *priv = zak_form_element_filter_get_instance_private (zak_form_element_filter);
index 1dffefbb26352073d99274a6c05b5edf3ff6425e..8ae7f3c767b14064eb30083cf5186bbcf4464122 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/xpath.h>
+
 
 G_BEGIN_DECLS
 
@@ -32,9 +34,11 @@ struct _ZakFormElementFilterClass
 {
        GObjectClass parent_cleass;
 
+       gboolean (*xml_parsing) (ZakFormElementFilter *filter, xmlNode *xnode);
        gchar *(*filter) (ZakFormElementFilter *self, const gchar *value);
 };
 
+gboolean zak_form_element_filter_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode);
 gchar *zak_form_element_filter_filter (ZakFormElementFilter *self, const gchar *value);
 
 gboolean zak_form_element_filter_get_enabled (ZakFormElementFilter *filter);
index 543043a693b72b9648d0f3174f0755f61b4f874c..ee9d928288436fc46c54ee0ae68d1d03c6db2e3d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,6 +42,7 @@ static void zak_form_element_filter_luc_get_property (GObject *object,
 static void zak_form_element_filter_luc_dispose (GObject *gobject);
 static void zak_form_element_filter_luc_finalize (GObject *gobject);
 
+static gboolean zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode);
 static gchar *zak_form_element_filter_luc_filter (ZakFormElementFilter *filter_luc, const gchar *value);
 
 enum
@@ -79,6 +80,7 @@ zak_form_element_filter_luc_class_init (ZakFormElementFilterLucClass *class)
        object_class->dispose = zak_form_element_filter_luc_dispose;
        object_class->finalize = zak_form_element_filter_luc_finalize;
 
+       parent_class->xml_parsing = zak_form_element_filter_luc_xml_parsing;
        parent_class->filter = zak_form_element_filter_luc_filter;
 
        g_type_class_add_private (object_class, sizeof (ZakFormElementFilterLucPrivate));
@@ -111,7 +113,7 @@ ZakFormElementFilterLuc
  * @xnode:
  *
  */
-gboolean
+static gboolean
 zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode)
 {
        gchar *content;
@@ -138,9 +140,9 @@ zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *
 /* PRIVATE */
 static void
 zak_form_element_filter_luc_set_property (GObject *object,
-                   guint property_id,
-                   const GValue *value,
-                   GParamSpec *pspec)
+                                          guint property_id,
+                                          const GValue *value,
+                                          GParamSpec *pspec)
 {
        ZakFormElementFilterLuc *zak_form_element = (ZakFormElementFilterLuc *)object;
        ZakFormElementFilterLucPrivate *priv = ZAK_FORM_ELEMENT_FILTER_LUC_GET_PRIVATE (zak_form_element);
@@ -155,9 +157,9 @@ zak_form_element_filter_luc_set_property (GObject *object,
 
 static void
 zak_form_element_filter_luc_get_property (GObject *object,
-                   guint property_id,
-                   GValue *value,
-                   GParamSpec *pspec)
+                                          guint property_id,
+                                          GValue *value,
+                                          GParamSpec *pspec)
 {
        ZakFormElementFilterLuc *zak_form_element = (ZakFormElementFilterLuc *)object;
        ZakFormElementFilterLucPrivate *priv = ZAK_FORM_ELEMENT_FILTER_LUC_GET_PRIVATE (zak_form_element);
@@ -196,7 +198,7 @@ zak_form_element_filter_luc_finalize (GObject *gobject)
 
 static gchar
 *zak_form_element_filter_luc_filter (ZakFormElementFilter *filter_luc,
-                                                                         const gchar *value)
+                                     const gchar *value)
 {
        gchar *ret;
        gchar *_value;
index eb00250df1199767c4fcb0548cac38f5edf133ff..6710a1509a639e98ab34b3c1fe61d70d41f1c06b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -34,7 +34,6 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (ZakFormElementFilterLuc, zak_form_element_filter_luc, ZAK_FORM, ELEMENT_FILTER_LUC, ZakFormElementFilter)
 
 ZakFormElementFilterLuc *zak_form_element_filter_luc_new (void);
-gboolean zak_form_element_filter_luc_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode);
 
 
 G_END_DECLS
index 6acafbd59f5ea52b75ed329bc7ebb698ac7e2567..1a891a86313f6f3e54936085f8f0563b4ae42411 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -27,17 +27,18 @@ static void zak_form_element_filter_trim_class_init (ZakFormElementFilterTrimCla
 static void zak_form_element_filter_trim_init (ZakFormElementFilterTrim *zak_form_element);
 
 static void zak_form_element_filter_trim_set_property (GObject *object,
-                               guint property_id,
-                               const GValue *value,
-                               GParamSpec *pspec);
+                                                       guint property_id,
+                                                       const GValue *value,
+                                                       GParamSpec *pspec);
 static void zak_form_element_filter_trim_get_property (GObject *object,
-                               guint property_id,
-                               GValue *value,
-                               GParamSpec *pspec);
+                                                       guint property_id,
+                                                       GValue *value,
+                                                       GParamSpec *pspec);
 
 static void zak_form_element_filter_trim_dispose (GObject *gobject);
 static void zak_form_element_filter_trim_finalize (GObject *gobject);
 
+static gboolean zak_form_element_filter_trim_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode);
 static gchar *zak_form_element_filter_trim_filter (ZakFormElementFilter *filter_trim, const gchar *value);
 
 struct _ZakFormElementFilterTrim
@@ -68,6 +69,7 @@ zak_form_element_filter_trim_class_init (ZakFormElementFilterTrimClass *class)
        object_class->dispose = zak_form_element_filter_trim_dispose;
        object_class->finalize = zak_form_element_filter_trim_finalize;
 
+       parent_class->xml_parsing = zak_form_element_filter_trim_xml_parsing;
        parent_class->filter = zak_form_element_filter_trim_filter;
 
        g_type_class_add_private (object_class, sizeof (ZakFormElementFilterTrimPrivate));
@@ -100,7 +102,7 @@ ZakFormElementFilterTrim
  * @xnode:
  *
  */
-gboolean
+static gboolean
 zak_form_element_filter_trim_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode)
 {
        /* nothing to do */
@@ -172,7 +174,7 @@ zak_form_element_filter_trim_finalize (GObject *gobject)
 
 static gchar
 *zak_form_element_filter_trim_filter (ZakFormElementFilter *filter_trim,
-                                                                         const gchar *value)
+                                      const gchar *value)
 {
        gchar *ret;
        gchar *_value;
@@ -181,7 +183,7 @@ static gchar
 
        _value = g_strdup (value);
 
-    ret = g_strdup (g_strstrip (_value));
+       ret = g_strdup (g_strstrip (_value));
 
        return ret;
 }
index d74e0bf4c63489d1733923a4791af836b1a3f414..aa5029678eaf0b95e79dd7145f5139bfa9e2ef8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -34,7 +34,6 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (ZakFormElementFilterTrim, zak_form_element_filter_trim, ZAK_FORM, ELEMENT_FILTER_TRIM, ZakFormElementFilter)
 
 ZakFormElementFilterTrim *zak_form_element_filter_trim_new (void);
-gboolean zak_form_element_filter_trim_xml_parsing (ZakFormElementFilter *filter, xmlNode *xnode);
 
 
 G_END_DECLS