All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.wicket.InternetAddressConverter Maven / Gradle / Ivy

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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy