// 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;
/*
 * Copyright 2015-2016 EuregJUG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.euregjug.site.web;


/**
 * @author Michael J. Simons, 2015-12-30
 */
@Component("index.rss")
@SuppressWarnings({"squid:MaximumInheritanceDepth"}) // Cannot change this...
class IndexRssView extends AbstractRssFeedView {

    private static final ZoneId UTC = ZoneId.of("UTC");

    private final MessageSource messageSource;

    private final DateTimeFormatter permalinkDateFormatter;

    IndexRssView(final MessageSource messageSource) {
        this.messageSource = messageSource;
        this.permalinkDateFormatter = DateTimeFormatter.ofPattern("/y/M/d", Locale.ENGLISH);
    }

    String getAbsoluteUrl(final HttpServletRequest request, final String relativeUrl) {
        final int port = request.getServerPort();
        final String hostWithPort = String.format("%s://%s%s",
                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) {
// 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;

/*
 * Copyright 2015-2016 EuregJUG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.euregjug.site.web;


/**
 * @author Michael J. Simons, 2015-12-30
 */
@Component("index.rss")
@SuppressWarnings({"squid:MaximumInheritanceDepth"}) // Cannot change this...
class IndexRssView extends AbstractRssFeedView {

    private static final ZoneId UTC = ZoneId.of("UTC");

    private final MessageSource messageSource;

    private final DateTimeFormatter permalinkDateFormatter;

    IndexRssView(final MessageSource messageSource) {
        this.messageSource = messageSource;
        this.permalinkDateFormatter = DateTimeFormatter.ofPattern("/y/M/d", Locale.ENGLISH);
    }

    String getAbsoluteUrl(final HttpServletRequest request, final String relativeUrl) {
        final int port = request.getServerPort();
        final String hostWithPort = String.format("%s://%s%s",
                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");