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

net.fortuna.ical4j.model.rfc5545.AttendeePropertyRule Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package net.fortuna.ical4j.model.rfc5545;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.commons.lang3.StringUtils;

import net.fortuna.ical4j.model.Rfc5545PropertyRule;
import net.fortuna.ical4j.model.property.Attendee;

public class AttendeePropertyRule implements Rfc5545PropertyRule {

    private static final String MAILTO = "mailto";
    private static final String APOSTROPHE = "'";
    private static final int MIN_LENGTH = 3;

    @Override
    public void applyTo(Attendee element) {
        if (element == null) {
            return;
        }
        URI calAddress = element.getCalAddress();
        if (calAddress == null) {
            return;
        }
        String scheme = calAddress.getScheme();
        if (scheme != null && StringUtils.startsWithIgnoreCase(scheme, MAILTO)) {
            String part = calAddress.getSchemeSpecificPart();
            if (part != null && part.length() >= MIN_LENGTH && StringUtils.startsWith(part, APOSTROPHE)
                    && StringUtils.endsWith(part, APOSTROPHE)) {
                String newPart = part.substring(1, part.length() - 1);
                safelySetNewValue(element, newPart);
            }
        }
    }

    private static void safelySetNewValue(Attendee element, String newPart) {
        try {
            element.setValue(MAILTO + ":" + newPart);
        } catch (URISyntaxException e) {

        }
    }

    @Override
    public Class getSupportedType() {
        return Attendee.class;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy