// Path: src/main/java/eu/euregjug/site/posts/Post.java
// @Getter
// public final class Post implements Serializable {
// 
//     private static final long serialVersionUID = 5598037121835514804L;
// 
//     private final LocalDate publishedOn;
// 
//     private final String slug;
// 
//     private final String title;
// 
//     private final String content;
// 
//     public Post(final Date publishedOn, final String slug, final String title, final String content) {
//         this.publishedOn = publishedOn instanceof java.sql.Date ? ((java.sql.Date) publishedOn).toLocalDate() : publishedOn.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//         this.slug = slug;
//         this.title = title;
//         this.content = content;
//     }
// 
//     /**
//      * Maps an entity to a post without rendering the content.
//      *
//      * @param postEntity
//      */
//     public Post(final PostEntity postEntity) {
//         this(postEntity.getPublishedOn(), postEntity.getSlug(), postEntity.getTitle(), null);
//     }
// }


import ac.simons.syndication.utils.SyndicationGuid;
import ac.simons.syndication.utils.SyndicationLink;
import com.rometools.modules.atom.modules.AtomLinkModuleImpl;
import com.rometools.rome.feed.atom.Link;
import com.rometools.rome.feed.rss.Channel;
import com.rometools.rome.feed.rss.Content;
import com.rometools.rome.feed.rss.Item;
import eu.euregjug.site.posts.Post;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.MessageSource;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
                request.isSecure() ? "https" : "http",
                request.getServerName(),
                Arrays.asList(80, 443).contains(port) ? "" : String.format(":%d", port)
        );
        return String.format("%s%s%s", hostWithPort, request.getContextPath(), relativeUrl);
    }

    @Override
    protected void buildFeedMetadata(final Map<String, Object> model, final Channel feed, final HttpServletRequest request) {
        final Page<Post> posts = (Page<Post>) model.get("posts");

        final Locale locale = request.getLocale();
        feed.setEncoding("UTF-8");
        feed.setTitle(String.format("%s - %s", messageSource.getMessage("siteTitle", null, locale), messageSource.getMessage("siteSubTitle", null, locale)));
        feed.setDescription(messageSource.getMessage("feedDescription", null, locale));
        feed.setLink(getAbsoluteUrl(request, ""));
        if (posts.hasContent()) {
            final Date pubDate = Date.from(posts.getContent().get(0).getPublishedOn().atStartOfDay(UTC).toInstant());
            feed.setLastBuildDate(pubDate);
            feed.setPubDate(pubDate);
        }
        feed.setGenerator("https://github.com/EuregJUG-Maas-Rhine/site");

        final String hrefFormat = "%s?page=%d";
        final String self = getAbsoluteUrl(request, "/feed.rss");
        final List<Link> atomLinks = new ArrayList<>();
        atomLinks.add(new SyndicationLink().withRel("self").withType(super.getContentType()).withHref(String.format(hrefFormat, self, posts.getNumber())).getLink());
        if (posts.hasPrevious()) {
            atomLinks.add(new SyndicationLink()
                    .withRel("previous")
// Path: src/main/java/eu/euregjug/site/posts/Post.java
// @Getter
// public final class Post implements Serializable {
// 
//     private static final long serialVersionUID = 5598037121835514804L;
// 
//     private final LocalDate publishedOn;
// 
//     private final String slug;
// 
//     private final String title;
// 
//     private final String content;
// 
//     public Post(final Date publishedOn, final String slug, final String title, final String content) {
//         this.publishedOn = publishedOn instanceof java.sql.Date ? ((java.sql.Date) publishedOn).toLocalDate() : publishedOn.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//         this.slug = slug;
//         this.title = title;
//         this.content = content;
//     }
// 
//     /**
//      * Maps an entity to a post without rendering the content.
//      *
//      * @param postEntity
//      */
//     public Post(final PostEntity postEntity) {
//         this(postEntity.getPublishedOn(), postEntity.getSlug(), postEntity.getTitle(), null);
//     }
// }


// Path: src/main/java/eu/euregjug/site/web/IndexRssView.java
import ac.simons.syndication.utils.SyndicationGuid;
import ac.simons.syndication.utils.SyndicationLink;
import com.rometools.modules.atom.modules.AtomLinkModuleImpl;
import com.rometools.rome.feed.atom.Link;
import com.rometools.rome.feed.rss.Channel;
import com.rometools.rome.feed.rss.Content;
import com.rometools.rome.feed.rss.Item;
import eu.euregjug.site.posts.Post;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.MessageSource;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.feed.AbstractRssFeedView;

                request.isSecure() ? "https" : "http",
                request.getServerName(),
                Arrays.asList(80, 443).contains(port) ? "" : String.format(":%d", port)
        );
        return String.format("%s%s%s", hostWithPort, request.getContextPath(), relativeUrl);
    }

    @Override
    protected void buildFeedMetadata(final Map<String, Object> model, final Channel feed, final HttpServletRequest request) {
        final Page<Post> posts = (Page<Post>) model.get("posts");

        final Locale locale = request.getLocale();
        feed.setEncoding("UTF-8");
        feed.setTitle(String.format("%s - %s", messageSource.getMessage("siteTitle", null, locale), messageSource.getMessage("siteSubTitle", null, locale)));
        feed.setDescription(messageSource.getMessage("feedDescription", null, locale));
        feed.setLink(getAbsoluteUrl(request, ""));
        if (posts.hasContent()) {
            final Date pubDate = Date.from(posts.getContent().get(0).getPublishedOn().atStartOfDay(UTC).toInstant());
            feed.setLastBuildDate(pubDate);
            feed.setPubDate(pubDate);
        }
        feed.setGenerator("https://github.com/EuregJUG-Maas-Rhine/site");

        final String hrefFormat = "%s?page=%d";
        final String self = getAbsoluteUrl(request, "/feed.rss");
        final List<Link> atomLinks = new ArrayList<>();
        atomLinks.add(new SyndicationLink().withRel("self").withType(super.getContentType()).withHref(String.format(hrefFormat, self, posts.getNumber())).getLink());
        if (posts.hasPrevious()) {
            atomLinks.add(new SyndicationLink()
                    .withRel("previous")
                    .withType(super.getContentType())