Skip to content

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

/***********************************************************************************************************************
 *
 * Specific for the format of SlideShowPro Player for Lightroom 1.9.8.5
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="nc" id="L64">@Slf4j</span>
public class SlideShowProPlayerGalleryLoader extends GalleryLoaderSupport
  {
<span class="nc" id="L67">    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="L74">        super(beanFactory, properties);</span>
<span class="nc" id="L75">      }</span>

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

        try
          {
<span class="nc" id="L84">            final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // FIXME: inject</span>
inject
<span class="nc" id="L85"> final DocumentBuilder db = dbf.newDocumentBuilder(); // FIXME: inject</span> <span class="nc" id="L86"> final XPathFactory xPathFactory = XPathFactory.newInstance(); // FIXME: inject</span> <span class="nc" id="L88"> final String s = siteNode.getProperty(P_IMAGES).orElseThrow(NotFoundException::new); // FIXME</span> <span class="nc" id="L89"> final Document document = db.parse(new InputSource(new StringReader(s)));</span> <span class="nc" id="L90"> final XPath xPath = xPathFactory.newXPath();</span> <span class="nc" id="L91"> final XPathExpression jx1 = xPath.compile(XPATH_IMG);</span> <span class="nc" id="L92"> final NodeList nodes = (NodeList)jx1.evaluate(document, XPathConstants.NODESET);</span> <span class="nc bnc" id="L94" title="All 2 branches missed."> for (int i = 0; i &lt; nodes.getLength(); i++)</span> { <span class="nc" id="L96"> final Node node = nodes.item(i);</span> <span class="nc" id="L97"> final String src = node.getAttributes().getNamedItem(&quot;src&quot;).getNodeValue().replaceAll(&quot;_&quot;, &quot;-&quot;).replaceAll(&quot;\\.jpg$&quot;, &quot;&quot;);</span> <span class="nc" id="L98"> items.add(createItem(new Id(src)));</span> } } <span class="nc" id="L101"> catch (ParserConfigurationException | NotFoundException | IOException |</span> SAXException | XPathExpressionException | DOMException e) { <span class="nc" id="L104"> log.warn(&quot;&quot;, e);</span> <span class="nc" id="L105"> }</span> <span class="nc" id="L107"> return items;</span> } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>