Hey guys,
i've been successfull with lift so far, now i want to do some more in
depth stuff. anyway, i am missing the postgresql cidr/ip datatypes.
Since they mostly work like strings i did the following:
import _root_.net.liftweb.mapper._
import _root_.net.liftweb.http.{S, FieldError}
import _root_.java.sql.{ResultSet, Types}
import _root_.java.util.regex._
import _root_.scala.xml.Text
object MappedCIDR {
val ipv4 = Pattern.compile("^25[0-5]|2[0-4]\\d|[01]\\d{2}|\\d{1,2})(\
\.(25[0-5]|2[0-4]\\d|[01]\\d{2}|\\d{1,2})){3}(/(3[012]|[12]\\d|\\d)$")
val ipv6 = Pattern.compile("^\\w*\\:\\w*\\:\\w*$")
def valid(ip: String): Boolean = ipv4.matcher(ip).matches ||
ipv6.matcher(ip).matches
def validIPAddr_?(ip: String) = valid(ip)
}
class MappedCIDR[T<:Mapper[T]](owner: T, maxLen: Int) extends
MappedString[T](owner, maxLen) {
/**
* Get the JDBC SQL Type for this field
*/
def targetSQLType = Types.VARCHAR
override def setFilter = notNull _ :: toLower _ :: trim _ ::
super.setFilter
override def validate = {
(
if (MappedCIDR.ipv4.matcher(i_is_!).matches ||
MappedCIDR.ipv6.matcher(i_is_!).matches()) Nil
else List(FieldError(this,
Text(S.??("invalid.ip.address"))))
) ::: super.validate
}
}
The question is, how would one go about implementing a type which is
not in sql.Types? ;)
I found some jdbc driver extensions for that:
http://oak.cats.ohiou.edu/~rf358197/jdbc/2/
Patching the current driver is painless, but i am still not sure how
to go on.
Can anyone gimme some advice at what code i should look which would
give me the best example for this?
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---