I have to validate a lot of UUIDs and wrote a small converter for UUID.
If the quite simple implementation is fine for you I would like to
contribute it to the Wicket code base including some tests
public class UUIDConverter implements IConverter<UUID>
{
public static final String UUID_REGEX =
"[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}";
@Override
public UUID convertToObject(String value, Locale locale)
throws ConversionException
{
UUID conversionResult = null;
if (value == null || !value.matches(UUID_REGEX)) {
throw newConversionException(value);
}
try {
conversionResult = UUID.fromString(value);
}
catch (IllegalArgumentException e)
{
throw newConversionException(value);
}
return conversionResult;
}
@Override
public String convertToString(UUID value, Locale locale)
{
String conversionResult = null;
if (value != null) {
conversionResult = value.toString();
}
return conversionResult;
}
protected ConversionException newConversionException(String value)
{
return new ConversionException("Failed to convert " + value +
"to a UUID");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org