Hi,
On Tue, Jan 14, 2014 at 1:29 PM, Oliver B. Fischer <mails...@swe-blog.net>wrote: > 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}"; > This would be better to be compiled Pattern instead. For better performance. > > @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); > Maybe it is a good idea to pass the cause as well. > } > > 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"); > } > } > > It is quite simple. Anyone can write it if it is needed for her application. But also I don't object to add it. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >