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

com.maileon.api.mailings.LinkAdaptor Maven / Gradle / Ivy

Go to download

Client for Customer API of Maileon. The API Documentation is avalable under https://dev.maileon.com

The newest version!
package com.maileon.api.mailings;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.maileon.api.MaileonException;

class LinkAdaptor {

    static Link fromXML(Element e) throws MaileonException {
        Link link = new Link();
        link.setId(parseLongSafe(e.elementText("id")));
        link.setFormat(e.elementText("format"));
        link.setLayout(e.elementText("layout"));
        link.setUrl(e.elementText("url"));
        List tags = new ArrayList<>();
        Element tagsE = e.element("tags");
        if (tagsE != null) {
            List ee = tagsE.elements("tag");
            for (Element tagE : ee) {
                tags.add(tagE.getText());
            }
        }
        link.setTags(tags);
        return link;
    }

    static List fromXML(List elements) throws MaileonException {
        List links = new ArrayList<>();
        for (Element e : elements) {
            links.add(fromXML(e));
        }
        return links;
    }

    private static Long parseLongSafe(String str) {
        if (str == null) {
            return null;
        }
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException e) {
            return null;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy