Skip to content

petercowan/recursivity-commons

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Various Java- and Scala utilities with no outside library dependencies.
Built with SBT (Simple-Build-Tool)

Java classes: not written by me, but stuff I often use and compiled from various books and open source sources.

MVN/SBT repo: https://oss.sonatype.org/content/repositories/releases (built against Scala 2.8.1 & 2.9.0.RC2)
Dependency definition (sbt): "com.recursivity" %% "recursivity-commons" % "0.5.2"

SCALA VALIDATOR (com.recursivity.commons.validator-package)
Simple and extensible Scala validation framework that makes use of Scala function passing to provide a more powerful validation framework.
Supports:
- Custom validators
- Localised error messages
- hooking in at various level of granularity, depending on your needs.

Example usage:
// setup a bean to validate
val bean = new MyBean("hello", 5, new Date, None)

// new ValidationGroup with a ClassPathMessageResolver
val group = new ValidationGroup(new ClasspathMessageResolver(this.getClass))

// add the validators to the ValidationGroup, note how we pass an anonymous function that will get the value/variable we want to validate.
group.add(new MinLengthValidator("hello", 8, {bean.text}))
group.add(new MaxIntValidator("max", 3, {bean.number}))
group.add(new MinIntValidator("min", 6, {bean.number}))
group.add(new NotNullOrNoneValidator("null", {bean.value}))

// validate and return error messages, a List of Tuple2's with (key, errorMessage) format.
val failures = group.validateAndReturnErrorMessages

Assumes property-files in the same package with the same name as "this"-class, for instance com.mypackage.MyClass would be:
/com/mypackage/MyClass.properties // for the default messages
/com/mypackage/MyClass_se.properties // for messages localized in Swedish

Contents of property-file might be:
# Validator messages
MinLengthValidator={key} must be at least {min} characters long
# {key} is replaced for either property value of key, for instance "hello", or simply the raw key.
# {min} in this example would be replaced by 8 from the code above.

# property key-values
hello='your text'

About

Common utility classes and simple validation framework, built with sbt (simple-build-tool)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published