package org.semper.reformanda.syndication.rss;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.InputStream;
import java.io.StringReader;
import java.util.Objects;
import java.util.Optional;

@XmlRootElement
public class Rss {

    public static Optional<Rss> fromXmlStream(final InputStream inputStream) {
        if (Objects.isNull(inputStream)) {
            return Optional.empty();
        }

        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(Rss.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            return Optional.of((Rss) jaxbUnmarshaller.unmarshal(inputStream));
        } catch (JAXBException e) {
            // TODO not sure I want to put logging in this library - perhaps slf4j or commons if I need to...
        }

        return Optional.empty();
    }

    public static Optional<Rss> fromXmlStream(final InputStream inputStream) {
        if (Objects.isNull(inputStream)) {
            return Optional.empty();
        }

        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(Rss.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            return Optional.of((Rss) jaxbUnmarshaller.unmarshal(inputStream));
        } catch (JAXBException e) {
            // TODO not sure I want to put logging in this library - perhaps slf4j or commons if I need to...
        }

        return Optional.empty();
    }

    private Channel channel;

    public Channel getChannel() {
        return channel;
    }

    @XmlElement
    public Rss setChannel(Channel channel) {
        this.channel = channel;
        return this;
    }

    @XmlAttribute
    public String getVersion() {
        return "2.0";
    }
}
@@ -1053,620 +1053,8 @@
  %7D%0A%0A
-    public static Optional%3CRss%3E fromXmlStream(final InputStream inputStream) %7B%0A        if (Objects.isNull(inputStream)) %7B%0A            return Optional.empty();%0A        %7D%0A%0A        try %7B%0A            JAXBContext jaxbContext = JAXBContext.newInstance(Rss.class);%0A            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();%0A            return Optional.of((Rss) jaxbUnmarshaller.unmarshal(inputStream));%0A        %7D catch (JAXBException e) %7B%0A            // TODO not sure I want to put logging in this library - perhaps slf4j or commons if I need to...%0A        %7D%0A%0A        return Optional.empty();%0A    %7D%0A%0A
     

fix duplicate static method in Rss from merge