Content of file SlideShowProPlayerGalleryLoader.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>SlideShowProPlayerGalleryLoader.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 :: Media</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-frontend-components</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.ui.component.gallery.spi.loader</a> &gt; <span class="el_source">SlideShowProPlayerGalleryLoader.java</span></div><h1>SlideShowProPlayerGalleryLoader.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.spi.loader;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.springframework.beans.factory.BeanFactory;
import org.w3c.dom.DOMException;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.northernwind.core.model.ResourceProperties;
import it.tidalwave.northernwind.core.model.SiteNode;
import it.tidalwave.northernwind.frontend.ui.component.gallery.GalleryViewController.GalleryItem;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * Specific for the format of SlideShowPro Player for Lightroom 1.9.8.5
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="nc" id="L59">@Slf4j</span>
public class SlideShowProPlayerGalleryLoader extends GalleryLoaderSupport
  {
<span class="nc" id="L62">    public static final Key&lt;String&gt; P_IMAGES = Key.of(&quot;images&quot;, String.class);</span>

    private static final String XPATH_IMG = &quot;/gallery/album/img&quot;;

    public SlideShowProPlayerGalleryLoader (@Nonnull final BeanFactory beanFactory,
                                            @Nonnull final ResourceProperties properties)
      {
<span class="nc" id="L69">        super(beanFactory, properties);</span>
<span class="nc" id="L70">      }</span>

    @Override @Nonnull
    public List&lt;GalleryItem&gt; loadGallery (@Nonnull final SiteNode siteNode)
      {
<span class="nc" id="L75">        final List&lt;GalleryItem&gt; items = new ArrayList&lt;&gt;();</span>

        try
          {
<span class="nc" id="L79">            final var dbf = DocumentBuilderFactory.newInstance(); // FIXME: inject</span>
inject
<span class="nc" id="L80"> final var db = dbf.newDocumentBuilder(); // FIXME: inject</span> <span class="nc" id="L81"> final var xPathFactory = XPathFactory.newInstance(); // FIXME: inject</span> <span class="nc" id="L83"> final var s = siteNode.getProperty(P_IMAGES).orElseThrow(NotFoundException::new); // FIXME</span> <span class="nc" id="L84"> final var document = db.parse(new InputSource(new StringReader(s)));</span> <span class="nc" id="L85"> final var xPath = xPathFactory.newXPath();</span> <span class="nc" id="L86"> final var jx1 = xPath.compile(XPATH_IMG);</span> <span class="nc" id="L87"> final var nodes = (NodeList)jx1.evaluate(document, XPathConstants.NODESET);</span> <span class="nc bnc" id="L89" title="All 2 branches missed."> for (var i = 0; i &lt; nodes.getLength(); i++)</span> { <span class="nc" id="L91"> final var node = nodes.item(i);</span> <span class="nc" id="L92"> final var src = node.getAttributes().getNamedItem(&quot;src&quot;).getNodeValue().replaceAll(&quot;_&quot;, &quot;-&quot;).replaceAll(&quot;\\.jpg$&quot;, &quot;&quot;);</span> <span class="nc" id="L93"> items.add(createItem(new Id(src)));</span> } } <span class="nc" id="L96"> catch (ParserConfigurationException | NotFoundException | IOException |</span> SAXException | XPathExpressionException | DOMException e) { <span class="nc" id="L99"> log.warn(&quot;&quot;, e);</span> <span class="nc" id="L100"> }</span> <span class="nc" id="L102"> return items;</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>