Content of file DefaultRssFeedViewController.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>DefaultRssFeedViewController.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">NorthernWind :: Frontend :: Spring MVC</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.ui.component.rssfeed</a> > <span class="el_source">DefaultRssFeedViewController.java</span></div><h1>DefaultRssFeedViewController.java</h1><pre class="source lang-java linenums">/*
* #%L
* *********************************************************************************************************************
*
* NorthernWind - lightweight CMS
* http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
* %%
* Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
* %%
* *********************************************************************************************************************
*
* 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.
*
* *********************************************************************************************************************
*
*
* *********************************************************************************************************************
* #L%
*/
package it.tidalwave.northernwind.frontend.ui.component.rssfeed;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Content;
import com.sun.syndication.feed.rss.Guid;
import com.sun.syndication.feed.rss.Item;
import com.sun.syndication.io.WireFeedOutput;
import it.tidalwave.util.Finder;
import it.tidalwave.util.Key;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.northernwind.core.model.HttpStatusException;
import it.tidalwave.northernwind.core.model.RequestLocaleManager;
import it.tidalwave.northernwind.core.model.ResourceProperties;
import it.tidalwave.northernwind.core.model.SiteNode;
import it.tidalwave.northernwind.core.model.SiteProvider;
import it.tidalwave.northernwind.frontend.ui.RenderContext;
import it.tidalwave.northernwind.frontend.ui.component.blog.DefaultBlogViewController;
import it.tidalwave.northernwind.core.impl.model.DefaultSiteFinder;
import lombok.extern.slf4j.Slf4j;
import static java.util.Collections.emptyMap;
import static it.tidalwave.northernwind.core.model.Content.*;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L60">@Slf4j</span>
public class DefaultRssFeedViewController extends DefaultBlogViewController implements RssFeedViewController
{
@Nonnull
private final SiteProvider siteProvider;
@Nonnull
private final SiteNode siteNode;
@Nonnull
private final RssFeedView view;
<span class="nc" id="L72"> private final List<Item> items = new ArrayList<>();</span>
private final String linkBase;
private final Channel feed;
private final ResourceProperties properties;
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
public DefaultRssFeedViewController (@Nonnull final RssFeedView view,
@Nonnull final SiteNode siteNode,
@Nonnull final SiteProvider siteProvider,
@Nonnull final RequestLocaleManager requestLocaleManager)
{
<span class="nc" id="L90"> super(siteNode, view, requestLocaleManager);</span>
<span class="nc" id="L91"> this.siteProvider = siteProvider;</span>
<span class="nc" id="L92"> this.siteNode = siteNode;</span>
<span class="nc" id="L93"> this.view = view;</span>
<span class="nc" id="L94"> feed = new Channel("rss_2.0");</span>
<span class="nc" id="L95"> properties = siteNode.getPropertyGroup(view.getId());</span>
<span class="nc" id="L96"> linkBase = properties.getProperty(P_LINK).orElse("");</span>
<span class="nc" id="L97"> feed.setTitle(properties.getProperty(P_TITLE).orElse(""));</span>
<span class="nc" id="L98"> feed.setDescription(properties.getProperty(P_DESCRIPTION).orElse(""));</span>
<span class="nc" id="L99"> feed.setLink(linkBase); // FIXME: why not site.createLink()?</span>
<span class="nc" id="L100"> feed.setCopyright(properties.getProperty(P_CREATOR).orElse(""));</span>
<span class="nc" id="L101"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
public void prepareRendering (@Nonnull final RenderContext context)
throws HttpStatusException
{
// do not call super!
<span class="nc" id="L113"> log.info("prepareRendering(RenderContext) for {}", siteNode);</span>
<span class="nc" id="L114"> prepareBlogPosts(context, getViewProperties());</span>
<span class="nc" id="L115"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
* RSS must not present their inner contents to the sitemap.
*
******************************************************************************************************************/
@Override @Nonnull
public Finder<SiteNode> findVirtualSiteNodes()
{
<span class="nc" id="L127"> return new DefaultSiteFinder<>("empty", emptyMap(), null); // TODO: HierarchicFinderSupport.emptyFinder();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
protected void renderPosts (@Nonnull final List<? extends it.tidalwave.northernwind.core.model.Content> fullPosts,
@Nonnull final List<? extends it.tidalwave.northernwind.core.model.Content> leadinPosts,
@Nonnull final List<? extends it.tidalwave.northernwind.core.model.Content> linkedPosts)
throws Exception
{
<span class="nc" id="L141"> fullPosts.forEach (post -> renderPost(post, Optional.of(P_FULL_TEXT)));</span>
<span class="nc" id="L142"> leadinPosts.forEach(post -> renderPost(post, Optional.of(P_LEADIN_TEXT)));</span>
<span class="nc" id="L143"> linkedPosts.forEach(post -> renderPost(post, Optional.empty()));</span>
<span class="nc" id="L145"> feed.setGenerator("NorthernWind v" + siteProvider.getVersionString());</span>
<span class="nc" id="L146"> feed.setItems(items);</span>
// if (!StringUtils.hasText(feed.getEncoding()))
// {
// feed.setEncoding("UTF-8");
// }
<span class="nc" id="L153"> final var feedOutput = new WireFeedOutput();</span>
<span class="nc" id="L154"> view.setContent(feedOutput.outputString(feed));</span>
<span class="nc" id="L155"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
protected void renderPost (@Nonnull final it.tidalwave.northernwind.core.model.Content post,
@Nonnull final Optional<? extends Key<String>> textProperty)
{
<span class="nc" id="L165"> final var blogDateTime = post.getProperty(DATE_KEYS).orElse(TIME0);</span>
// FIXME: compute the latest date, which is not necessarily the first
| compute the latest date, which is not necessarily the first | |
<span class="nc bnc" id="L167" title="All 2 branches missed."> if (feed.getLastBuildDate() == null)</span>
{
<span class="nc" id="L169"> feed.setLastBuildDate(Date.from(blogDateTime.toInstant()));</span>
}
<span class="nc" id="L172"> final var postProperties = post.getProperties();</span>
<span class="nc" id="L173"> final var item = new Item();</span>
<span class="nc" id="L174"> final var content = new Content();</span>
// FIXME: text/xhtml?
<span class="nc" id="L176"> content.setType("text/html"); // FIXME: should use post.getResourceFile().getMimeType()?</span>
<span class="nc" id="L177"> textProperty.flatMap(postProperties::getProperty).ifPresent(content::setValue);</span>
<span class="nc" id="L178"> item.setTitle(postProperties.getProperty(P_TITLE).orElse(""));</span>
// item.setAuthor("author " + i); TODO
<span class="nc" id="L180"> item.setPubDate(Date.from(blogDateTime.toInstant()));</span>
<span class="nc" id="L181"> item.setContent(content);</span>
try
{
// FIXME: manipulate through site.createLink()
<span class="nc" id="L186"> final var link = linkBase.replaceAll("/$", "") + post.getExposedUri().orElseThrow(NotFoundException::new).asString() + "/";</span>
<span class="nc" id="L187"> final var guid = new Guid();</span>
<span class="nc" id="L188"> guid.setPermaLink(true);</span>
<span class="nc" id="L189"> guid.setValue(link);</span>
<span class="nc" id="L190"> item.setGuid(guid);</span>
<span class="nc" id="L191"> item.setLink(link);</span>
}
<span class="nc" id="L193"> catch (NotFoundException e)</span>
{
// ok. no link
<span class="nc" id="L196"> }</span>
<span class="nc" id="L198"> items.add(item);</span>
<span class="nc" id="L199"> }</span>
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override
protected void renderTagCloud (@Nonnull final Collection<? extends TagAndCount> tagsAndCount)
{
// not meaningful for RSS
<span class="nc" id="L210"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.9.202303310957</span></div></body></html>