Content of file HtmlTemplateGalleryViewController.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>HtmlTemplateGalleryViewController.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> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-frontend-components-htmltemplate</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.ui.component.gallery.htmltemplate</a> &gt; <span class="el_source">HtmlTemplateGalleryViewController.java</span></div><h1>HtmlTemplateGalleryViewController.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 &quot;License&quot;); 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 &quot;AS IS&quot; 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.gallery.htmltemplate;

import javax.annotation.Nonnull;
import org.springframework.beans.factory.BeanFactory;
import it.tidalwave.util.Id;
import it.tidalwave.northernwind.core.model.HttpStatusException;
import it.tidalwave.northernwind.core.model.ModelFactory;
import it.tidalwave.northernwind.core.model.RequestLocaleManager;
import it.tidalwave.northernwind.core.model.ResourcePath;
import it.tidalwave.northernwind.core.model.ResourceProperties;
import it.tidalwave.northernwind.core.model.SiteNode;
import it.tidalwave.northernwind.frontend.ui.RenderContext;
import it.tidalwave.northernwind.frontend.ui.component.htmltemplate.TextHolder;
import it.tidalwave.northernwind.frontend.ui.component.gallery.DefaultGalleryViewController;
import it.tidalwave.northernwind.frontend.ui.component.gallery.GalleryView;
import it.tidalwave.northernwind.frontend.ui.component.gallery.htmltemplate.bluette.BluetteGalleryAdapter;
import lombok.extern.slf4j.Slf4j;
import static javax.servlet.http.HttpServletResponse.*;
import static it.tidalwave.northernwind.core.model.Content.P_TITLE;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="nc" id="L52">@Slf4j</span>
public class HtmlTemplateGalleryViewController extends DefaultGalleryViewController
  {
    @Nonnull
    private final GalleryView view;

    @Nonnull
    private final SiteNode siteNode;

    /*******************************************************************************************************************
     *
     *
     *
     ******************************************************************************************************************/
    public HtmlTemplateGalleryViewController (@Nonnull final GalleryView view,
                                              @Nonnull final SiteNode siteNode,
                                              @Nonnull final RequestLocaleManager requestLocaleManager,
                                              @Nonnull final ModelFactory modelFactory,
                                              @Nonnull final BeanFactory beanFactory)
      {
<span class="nc" id="L72">        super(view, siteNode, requestLocaleManager, beanFactory);</span>
<span class="nc" id="L73">        this.view = view;</span>
<span class="nc" id="L74">        this.siteNode = siteNode;</span>
<span class="nc" id="L75">        galleryAdapter = new BluetteGalleryAdapter(siteNode, view, modelFactory); // FIXME: get implementation from configuration</span>
get implementation from configuration
<span class="nc" id="L76"> }</span> /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public void prepareRendering (@Nonnull final RenderContext context) throws Exception { <span class="nc" id="L87"> super.prepareRendering(context);</span> <span class="nc" id="L88"> final var param = getParam(context);</span> <span class="nc" id="L89"> log.info(&quot;&gt;&gt;&gt;&gt; pathParams: *{}*&quot;, param);</span> <span class="nc" id="L90"> final var textHolder = (TextHolder)view;</span> <span class="nc" id="L91"> final var siteNodeTitle = siteNode.getProperty(P_TITLE).orElse(&quot;&quot;);</span> <span class="nc bnc" id="L93" title="All 3 branches missed."> switch (param.getSegmentCount())</span> { case 0: // no args, full JS gallery <span class="nc" id="L96"> galleryAdapter.prepareGallery(items.get(0), items);</span> <span class="nc" id="L97"> textHolder.addAttribute(&quot;title&quot;, siteNodeTitle);</span> <span class="nc" id="L98"> break;</span> case 1: <span class="nc bnc" id="L101" title="All 3 branches missed."> switch (param.getLeading())</span> { case &quot;images.xml&quot;: <span class="nc" id="L104"> galleryAdapter.prepareCatalog(items);</span> <span class="nc" id="L105"> break;</span> case &quot;lightbox&quot;: <span class="nc" id="L108"> galleryAdapter.prepareFallbackLightbox(items);</span> <span class="nc" id="L109"> textHolder.addAttribute(&quot;title&quot;, siteNodeTitle);</span> <span class="nc" id="L110"> break;</span> default: // id of the gallery item to render, fallback mode <span class="nc" id="L113"> final var id = new Id(param.getLeading());</span> <span class="nc" id="L114"> final var item = itemMapById.get(id);</span> <span class="nc bnc" id="L116" title="All 2 branches missed."> if (item == null)</span> { <span class="nc" id="L118"> log.warn(&quot;Gallery item not found: {}&quot;, id);</span> <span class="nc" id="L119"> log.debug(&quot;Gallery item not found: {}, available: {}&quot;, id, itemMapById.keySet());</span> <span class="nc" id="L120"> throw new HttpStatusException(SC_NOT_FOUND);</span> } <span class="nc" id="L123"> galleryAdapter.prepareFallbackGallery(item, items);</span> <span class="nc" id="L124"> textHolder.addAttribute(&quot;title&quot;, item.getDescription());</span> break; } <span class="nc" id="L128"> break;</span> default: <span class="nc" id="L131"> throw new HttpStatusException(SC_BAD_REQUEST);</span> } <span class="nc" id="L133"> }</span> /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public void renderView (@Nonnull final RenderContext context) throws Exception { <span class="nc" id="L144"> super.renderView(context);</span> <span class="nc" id="L145"> galleryAdapter.render(context);</span> <span class="nc" id="L146"> }</span> @Nonnull private ResourcePath getParam (@Nonnull final RenderContext context) { <span class="nc" id="L151"> return context.getQueryParam(&quot;_escaped_fragment_&quot;).map(ResourcePath::of)</span> <span class="nc" id="L152"> .orElse(context.getPathParams(siteNode));</span> } /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull protected final String computeInlinedScriptsSection() { <span class="nc" id="L163"> return super.computeInlinedScriptsSection() + &quot;\n&quot; + galleryAdapter.getInlinedScript();</span> } /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull protected ResourceProperties getViewProperties() { <span class="nc" id="L174"> return super.getViewProperties().merged(galleryAdapter.getExtraViewProperties(view.getId()));</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>