com.databasesandlife.util.wicket.InternetAddressConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
The newest version!
package com.databasesandlife.util.wicket;
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;
import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;
import java.util.Locale;
/**
* Converts user input into {@link InternetAddress} email address.
*
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
public class InternetAddressConverter implements IConverter {
@Override
public InternetAddress convertToObject(String str, Locale arg1) {
if (str == null)
return null;
else try {
return new InternetAddress(str, true);
} catch (AddressException e) {
throw new ConversionException(e).setResourceKey("invalidEmailAddress").setVariable("email-address", str);
}
}
@Override
public String convertToString(InternetAddress val, Locale arg1) {
if(val == null) return null;
else return val.toString();
}
}