Refactored ZakFormElementValidator::xml_parsing.
typedef ZakFormElementFilter *(* FormElementFilterConstructorFunc) (void);
typedef gboolean (* FormElementFilterXmlParsingFunc) (ZakFormElementFilter *, xmlNodePtr);
typedef ZakFormElementValidator *(* FormElementValidatorConstructorFunc) (void);
-typedef gboolean (* FormElementValidatorXmlParsingFunc) (ZakFormElementValidator *, xmlNodePtr);
typedef ZakFormValidator *(* FormValidatorConstructorFunc) (void);
static void zak_form_form_class_init (ZakFormFormClass *class);
FormElementFilterConstructorFunc filter_constructor;
FormElementFilterXmlParsingFunc filter_xml_parsing;
FormElementValidatorConstructorFunc validator_constructor;
- FormElementValidatorXmlParsingFunc validator_xml_parsing;
gboolean to_unlink;
xmlNode *xnode_tmp;
validator = validator_constructor ();
zak_form_element_add_validator (element, validator);
- if (g_module_symbol ((GModule *)g_ptr_array_index (priv->ar_modules, i),
- g_strconcat (type, "_xml_parsing", NULL),
- (gpointer *)&validator_xml_parsing))
- {
- if (validator_xml_parsing != NULL)
- {
- validator_xml_parsing (validator, xnode);
- }
- }
+ zak_form_element_validator_xml_parsing (validator, xnode);
break;
}
enum
{
PROP_0,
+ PROP_ID,
PROP_ENABLED,
PROP_MESSAGE
};
typedef struct
{
+ gchar *id;
gboolean enabled;
gchar *message;
} ZakFormElementValidatorPrivate;
object_class->dispose = zak_form_element_validator_dispose;
object_class->finalize = zak_form_element_validator_finalize;
+ g_object_class_install_property (object_class, PROP_ID,
+ g_param_spec_string ("id",
+ "Id",
+ "Id",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
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));
g_object_class_install_property (object_class, PROP_MESSAGE,
- g_param_spec_string ("message",
- "Message",
- "Message",
- _("Invalid value"),
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_param_spec_string ("message",
+ "Message",
+ "Message",
+ _("Invalid value"),
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (zak_form_element_validator);
}
+gboolean
+zak_form_element_validator_xml_parsing (ZakFormElementValidator *self, xmlNode *xnode)
+{
+ gboolean ret;
+
+ gchar *prop;
+
+ g_return_val_if_fail (ZAK_FORM_IS_ELEMENT_VALIDATOR (self), FALSE);
+
+ ret = TRUE;
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"id");
+ if (prop != NULL)
+ {
+ zak_form_element_validator_set_id (self, prop);
+ g_free (prop);
+ }
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"message");
+ if (prop != NULL)
+ {
+ zak_form_element_validator_set_message (self, prop);
+ g_free (prop);
+ }
+
+ prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"disabled");
+ if (prop != NULL)
+ {
+ zak_form_element_validator_set_enabled (self, FALSE);
+ g_free (prop);
+ }
+
+ if (ZAK_FORM_ELEMENT_VALIDATOR_GET_CLASS (self)->xml_parsing != NULL)
+ {
+ ret = ZAK_FORM_ELEMENT_VALIDATOR_GET_CLASS (self)->xml_parsing (self, xnode);
+ }
+ return ret;
+}
+
gboolean
zak_form_element_validator_validate (ZakFormElementValidator *self, const gchar *value)
{
return ret;
}
+/**
+ * zak_form_element_validator_set_id:
+ * @validator:
+ * @id:
+ *
+ */
+void
+zak_form_element_validator_set_id (ZakFormElementValidator *validator,
+ const gchar *id)
+{
+ ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
+
+ if (id == NULL)
+ {
+ priv->id = g_strdup ("");
+ }
+ else
+ {
+ priv->id = g_strdup (id);
+ }
+}
+
+/**
+ * zak_form_element_validator_get_id:
+ * @validator:
+ *
+ * Returns:
+ */
+gchar
+*zak_form_element_validator_get_id (ZakFormElementValidator *validator)
+{
+ ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
+
+ return g_strdup (priv->id);
+}
+
/**
* zak_form_element_validator_set_message:
* @validator:
*/
void
zak_form_element_validator_set_message (ZakFormElementValidator *validator,
- const gchar *message)
+ const gchar *message)
{
ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
{
ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (validator);
- return g_strdup (priv->message);
+ return g_strdup (priv->message);
}
/**
/* PRIVATE */
static void
zak_form_element_validator_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
ZakFormElementValidator *zak_form_element_validator = (ZakFormElementValidator *)object;
ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (zak_form_element_validator);
switch (property_id)
{
+ case PROP_ID:
+ zak_form_element_validator_set_id (zak_form_element_validator, g_value_dup_string (value));
+ break;
+
case PROP_ENABLED:
zak_form_element_validator_set_enabled (zak_form_element_validator, g_value_get_boolean (value));
break;
static void
zak_form_element_validator_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
ZakFormElementValidator *zak_form_element_validator = (ZakFormElementValidator *)object;
ZakFormElementValidatorPrivate *priv = zak_form_element_validator_get_instance_private (zak_form_element_validator);
switch (property_id)
{
+ case PROP_ID:
+ g_value_set_string (value, zak_form_element_validator_get_id (zak_form_element_validator));
+ break;
+
case PROP_ENABLED:
g_value_set_boolean (value, zak_form_element_validator_get_enabled (zak_form_element_validator));
break;
#include <glib-object.h>
+#include <libxml/xpath.h>
+
G_BEGIN_DECLS
{
GObjectClass parent_class;
+ gboolean (*xml_parsing) (ZakFormElementValidator *self, xmlNode *xnode);
gboolean (*validate) (ZakFormElementValidator *self, const gchar *value);
};
+gboolean zak_form_element_validator_xml_parsing (ZakFormElementValidator *self, xmlNode *xnode);
gboolean zak_form_element_validator_validate (ZakFormElementValidator *self, const gchar *value);
+void zak_form_element_validator_set_id (ZakFormElementValidator *validator,
+ const gchar *id);
+gchar *zak_form_element_validator_get_id (ZakFormElementValidator *validator);
+
void zak_form_element_validator_set_message (ZakFormElementValidator *validator,
- const gchar *message);
+ const gchar *message);
gchar *zak_form_element_validator_get_message (ZakFormElementValidator *validator);
gboolean zak_form_element_validator_get_enabled (ZakFormElementValidator *validator);
static void zak_form_element_validator_date_dispose (GObject *gobject);
static void zak_form_element_validator_date_finalize (GObject *gobject);
+static gboolean zak_form_element_validator_date_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
static gboolean zak_form_element_validator_date_validate (ZakFormElementValidator *validator_date, const gchar *value);
struct _ZakFormElementValidatorDate
object_class->dispose = zak_form_element_validator_date_dispose;
object_class->finalize = zak_form_element_validator_date_finalize;
+ parent_class->xml_parsing = zak_form_element_validator_date_xml_parsing;
parent_class->validate = zak_form_element_validator_date_validate;
g_type_class_add_private (object_class, sizeof (ZakFormElementValidatorDatePrivate));
* @xnode:
*
*/
-gboolean
+static gboolean
zak_form_element_validator_date_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
{
ZakFormElementValidatorDatePrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_DATE_GET_PRIVATE (ZAK_FORM_ELEMENT_VALIDATOR_DATE (validator));
void zak_form_element_validator_date_set_format (ZakFormElementValidatorDate *validator, const gchar *format);
gchar *zak_form_element_validator_date_get_format (ZakFormElementValidatorDate *validator);
-gboolean zak_form_element_validator_date_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-
G_END_DECLS
static void zak_form_element_validator_notempty_dispose (GObject *gobject);
static void zak_form_element_validator_notempty_finalize (GObject *gobject);
+static gboolean zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
static gboolean zak_form_element_validator_notempty_validate (ZakFormElementValidator *validator_notempty, const gchar *value);
struct _ZakFormElementValidatorNotempty
object_class->dispose = zak_form_element_validator_notempty_dispose;
object_class->finalize = zak_form_element_validator_notempty_finalize;
+ parent_class->xml_parsing = zak_form_element_validator_notempty_xml_parsing;
parent_class->validate = zak_form_element_validator_notempty_validate;
g_type_class_add_private (object_class, sizeof (ZakFormElementValidatorNotemptyPrivate));
g_object_class_install_property (object_class, PROP_AS_EMPTY_STRING,
- g_param_spec_string ("as-empty-string",
- "As empty string",
- "As empty string",
- "",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_param_spec_string ("as-empty-string",
+ "As empty string",
+ "As empty string",
+ "",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
* @xnode:
*
*/
-gboolean
+static gboolean
zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
{
ZakFormElementValidatorNotemptyPrivate *priv = ZAK_FORM_ELEMENT_VALIDATOR_NOTEMPTY_GET_PRIVATE (validator);
ZakFormElementValidatorNotempty *zak_form_element_validator_notempty_new (void);
-gboolean zak_form_element_validator_notempty_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
-
void zak_form_element_validator_notempty_set_as_empty_string (ZakFormElementValidatorNotempty *validator, const gchar *as_empty_string);
gchar *zak_form_element_validator_notempty_get_as_empty_string (ZakFormElementValidatorNotempty *validator);
static void zak_form_element_validator_regex_dispose (GObject *gobject);
static void zak_form_element_validator_regex_finalize (GObject *gobject);
+static gboolean zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
static gboolean zak_form_element_validator_regex_validate (ZakFormElementValidator *validator_regex, const gchar *value);
struct _ZakFormElementValidatorRegex
object_class->dispose = zak_form_element_validator_regex_dispose;
object_class->finalize = zak_form_element_validator_regex_finalize;
+ parent_class->xml_parsing = zak_form_element_validator_regex_xml_parsing;
parent_class->validate = zak_form_element_validator_regex_validate;
g_type_class_add_private (object_class, sizeof (ZakFormElementValidatorRegexPrivate));
* @xnode:
*
*/
-gboolean
+static gboolean
zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode)
{
zak_form_element_validator_regex_set_regex (ZAK_FORM_ELEMENT_VALIDATOR_REGEX (validator), (gchar *)xmlNodeGetContent (xnode));
G_DECLARE_FINAL_TYPE (ZakFormElementValidatorRegex, zak_form_element_validator_regex, ZAK_FORM, ELEMENT_VALIDATOR_REGEX, ZakFormElementValidator)
ZakFormElementValidatorRegex *zak_form_element_validator_regex_new (void);
-gboolean zak_form_element_validator_regex_xml_parsing (ZakFormElementValidator *validator, xmlNode *xnode);
void zak_form_element_validator_regex_set_regex (ZakFormElementValidatorRegex *validator, const gchar *regex);
gchar *zak_form_element_validator_regex_get_regex (ZakFormElementValidatorRegex *validator);