Class AbstractRssReader<C extends Channel,​I extends Item>

  • Direct Known Subclasses:
    RssReader

    public abstract class AbstractRssReader<C extends Channel,​I extends Item>
    extends java.lang.Object
    Abstract base class for implementing modules or extensions of RSS / Atom feeds with custom tags and attributes.
    • Constructor Detail

      • AbstractRssReader

        protected AbstractRssReader()
      • AbstractRssReader

        protected AbstractRssReader​(java.net.http.HttpClient httpClient)
    • Method Detail

      • createChannel

        protected abstract C createChannel()
        Returns an object of a Channel implementation.
        Returns:
        channel
      • createItem

        protected abstract I createItem()
        Returns an object of an Item implementation.
        Returns:
        item
      • init

        protected void init()
      • registerChannelTags

        protected void registerChannelTags()
      • registerChannelAttributes

        protected void registerChannelAttributes()
      • registerItemTags

        protected void registerItemTags()
      • registerItemAttributes

        protected void registerItemAttributes()
      • registerImageTags

        protected void registerImageTags()
      • setUserAgent

        public AbstractRssReader<C,​I> setUserAgent​(java.lang.String userAgent)
        Sets the user-agent of the HttpClient. This is completely optional and if not set then it will not send a user-agent header.
        Parameters:
        userAgent - the user-agent to use.
        Returns:
        updated RSSReader.
      • addHeader

        public AbstractRssReader<C,​I> addHeader​(java.lang.String key,
                                                      java.lang.String value)
        Adds a header to the HttpClient. This is completely optional and if no headers are set then it will not add anything.
        Parameters:
        key - the key name of the header.
        value - the value of the header.
        Returns:
        updated RSSReader.
      • addItemExtension

        public AbstractRssReader<C,​I> addItemExtension​(java.lang.String tag,
                                                             java.util.function.BiConsumer<I,​java.lang.String> consumer)
        Add item extension for tags
        Parameters:
        tag - - tag name
        consumer - - setter method in Item class to use for mapping
        Returns:
        this instance
      • addItemExtension

        public AbstractRssReader<C,​I> addItemExtension​(java.lang.String tag,
                                                             java.lang.String attribute,
                                                             java.util.function.BiConsumer<I,​java.lang.String> consumer)
        Add item extension for attributes
        Parameters:
        tag - - tag name
        attribute - - attribute name
        consumer - - setter method in Item class to use for mapping
        Returns:
        this instance
      • addChannelExtension

        public AbstractRssReader<C,​I> addChannelExtension​(java.lang.String tag,
                                                                java.util.function.BiConsumer<C,​java.lang.String> consumer)
        Add channel extension for tags
        Parameters:
        tag - - tag name
        consumer - - setter method in Channel class to use for mapping
        Returns:
        this instance
      • addChannelExtension

        public AbstractRssReader<C,​I> addChannelExtension​(java.lang.String tag,
                                                                java.lang.String attribute,
                                                                java.util.function.BiConsumer<C,​java.lang.String> consumer)
        Add channel extension for attributes
        Parameters:
        tag - - tag name
        attribute - - attribute name
        consumer - - setter method in Channel class to use for mapping
        Returns:
        this instance
      • read

        public java.util.stream.Stream<I> read​(java.lang.String url)
                                        throws java.io.IOException
        Read RSS feed with the given URL.
        Parameters:
        url - URL to RSS feed.
        Returns:
        Stream of items
        Throws:
        java.io.IOException - Fail to read url or its content
      • read

        public java.util.stream.Stream<I> read​(java.io.InputStream inputStream)
        Read RSS feed from input stream.
        Parameters:
        inputStream - inputStream containing the RSS feed.
        Returns:
        Stream of items
      • readAsync

        public java.util.concurrent.CompletableFuture<java.util.stream.Stream<I>> readAsync​(java.lang.String url)
        Read RSS feed asynchronous with the given URL.
        Parameters:
        url - URL to RSS feed.
        Returns:
        Stream of items
      • sendAsyncRequest

        protected java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<java.io.InputStream>> sendAsyncRequest​(java.lang.String url)