Moved to draft

This commit is contained in:
Severin Münger
2013-09-24 15:18:14 +02:00
parent f51201eae1
commit 83329ca4b7
41 changed files with 11 additions and 24 deletions

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {WSF_DECIMAL_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_DECIMAL_VALIDATOR
inherit
WSF_REGEXP_VALIDATOR
create
make_decimal_validator
feature {NONE} -- Initialization
make_decimal_validator (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e)
end
end

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {WSF_EMAIL_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_EMAIL_VALIDATOR
inherit
WSF_REGEXP_VALIDATOR
create
make_email_validator
feature {NONE} -- Initialization
make_email_validator (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("^[a-zA-Z0-9._%%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$", e)
end
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WSF_MAX_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_max_VALIDATOR [G]
inherit
WSF_VALIDATOR [LIST [G]]
redefine
state
end
create
make_max_validator
feature {NONE} -- Initialization
make_max_validator (m: INTEGER; e: STRING)
-- Initialize with specified maximum and error message which will be displayed on validation failure
do
make (e)
max := m
end
feature -- Implementation
is_valid (input: LIST [G]): BOOLEAN
do
Result := input.count < max or input.count = max
end
feature -- State
state: JSON_OBJECT
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (max), "max")
end
feature -- Properties
max: INTEGER
-- The maximal allowed value
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WSF_MIN_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_MIN_VALIDATOR [G]
inherit
WSF_VALIDATOR [LIST [G]]
redefine
state
end
create
make_min_validator
feature {NONE} -- Initialization
make_min_validator (m: INTEGER; e: STRING)
-- Initialize with specified minimum and error message which will be displayed on validation failure
do
make (e)
min := m
end
feature -- Implementation
is_valid (input: LIST [G]): BOOLEAN
do
Result := input.count > min or input.count = min
end
feature -- State
state: JSON_OBJECT
do
Result := Precursor
Result.put (create {JSON_NUMBER}.make_integer (min), "min")
end
feature -- Properties
min: INTEGER
-- The minimal allowed value
end

View File

@@ -0,0 +1,25 @@
note
description: "Summary description for {WSF_PHONE_NUMBER_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_PHONE_NUMBER_VALIDATOR
inherit
WSF_REGEXP_VALIDATOR
create
make_with_message
feature {NONE} -- Initialization
make_with_message (e: STRING)
-- Initialize with specified error message which will be displayed on validation failure
do
make_regexp_validator ("", e)
end
end

View File

@@ -0,0 +1,57 @@
note
description: "Summary description for {WSF_REGEXP_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WSF_REGEXP_VALIDATOR
inherit
WSF_VALIDATOR [STRING]
redefine
state
end
create
make_regexp_validator
feature {NONE} -- Initialization
make_regexp_validator (r, e: STRING)
-- Initialize with specified regular expression and error message which will be displayed on validation failure
do
make (e)
regexp_string := r
create regexp
end
feature -- Implementation
is_valid (input: STRING): BOOLEAN
do
--Only compile when used
if not regexp.is_compiled then
regexp.compile (regexp_string)
end
Result := regexp.matches (input)
end
feature -- State
state: JSON_OBJECT
do
create Result.make
Result.put (create {JSON_STRING}.make_json ("WSF_REGEXP_VALIDATOR"), "name")
Result.put (create {JSON_STRING}.make_json (regexp_string), "expression")
Result.put (create {JSON_STRING}.make_json (error), "error")
end
feature -- Properties
regexp_string: STRING
regexp: REGULAR_EXPRESSION
end

View File

@@ -0,0 +1,22 @@
note
description: "Summary description for {WSF_VALIDATABLE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALIDATABLE
feature -- Specification
validate
-- Perform validation
deferred
end
is_valid: BOOLEAN
-- Result of last validation
deferred
end
end

View File

@@ -0,0 +1,37 @@
note
description: "Summary description for {WSF_VALIDATOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WSF_VALIDATOR [G]
feature {NONE} -- Initialization
make (e: STRING)
-- Initialize with specified error message to be displayed on validation failure
do
error := e
end
feature -- Access
state: JSON_OBJECT
-- JSON state of this validator
do
create Result.make
Result.put (create {JSON_STRING}.make_json (generator), "name")
Result.put (create {JSON_STRING}.make_json (error), "error")
end
is_valid (input: G): BOOLEAN
-- Perform validation on given input and tell whether validation was successful or not
deferred
end
feature -- Properties
error: STRING
end