Content of file ShootingDataInterpolator.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>ShootingDataInterpolator.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.source.html" class="el_package">it.tidalwave.northernwind.frontend.media.impl.interpolator</a> &gt; <span class="el_source">ShootingDataInterpolator.java</span></div><h1>ShootingDataInterpolator.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.media.impl.interpolator;

import javax.annotation.Nonnull;
import java.text.DecimalFormat;
import java.util.Optional;
import it.tidalwave.image.metadata.EXIF;
import it.tidalwave.image.metadata.TIFF;
import it.tidalwave.image.metadata.XMP;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
public class ShootingDataInterpolator extends MetadataInterpolatorSupport
  {
    public ShootingDataInterpolator()
      {
<span class="fc" id="L45">        super(&quot;shootingData&quot;);</span>
<span class="fc" id="L46">      }</span>

    @Override @Nonnull
    public String interpolate (@Nonnull final String template, @Nonnull final Context context)
      {
<span class="fc" id="L51">        final var tiff = context.getMetadata().getDirectory(TIFF.class);</span>
<span class="fc" id="L52">        final var exif = context.getMetadata().getDirectory(EXIF.class);</span>
<span class="fc" id="L53">        final var xmp = context.getMetadata().getDirectory(XMP.class);</span>
<span class="fc" id="L54">        final var xmpProperties = xmp.getXmpProperties();</span>
<span class="fc" id="L55">        final var modelMap = context.getModelMap();</span>
<span class="fc" id="L56">        final var lensMap = context.getLensMap();</span>

<span class="fc" id="L58">        final var builder = new StringBuilder();</span>
<span class="fc" id="L59">        final var cameraMake = tiff.getMake()</span>
<span class="fc" id="L60">                                   .or(exif::getMake)</span>
<span class="pc" id="L61">                                   .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;tiff:Make&quot;)))</span>
<span class="fc" id="L62">                                   .orElse(&quot;&quot;);</span>
<span class="fc" id="L63">        final var cameraModel = tiff.getModel()</span>
<span class="fc" id="L64">                                    .or(exif::getModel)</span>
<span class="pc" id="L65">                                    .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;tiff:Model&quot;)))</span>
<span class="fc" id="L66">                                    .orElse(&quot;&quot;);</span>

<span class="pc bpc" id="L68" title="2 of 4 branches missed.">        var camera = (cameraMake + ((!cameraModel.isBlank() &amp;&amp; !cameraMake.isBlank()) ? &quot; &quot; : &quot;&quot;) + cameraModel).trim();</span>
<span class="fc" id="L69">        camera = modelMap.getOrDefault(camera, camera);</span>
<span class="fc" id="L70">        builder.append(camera);</span>
<span class="fc" id="L71">        builder.append(&quot; + &quot;);</span>

<span class="fc" id="L73">        final var lensMake = exif.getLensMake()</span>
<span class="fc" id="L74">                                 .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;exif:LensMake&quot;)))</span>
<span class="fc" id="L75">                                 .orElse(&quot;&quot;);</span>
<span class="fc" id="L76">        final var lensModel = exif.getLensModel()</span>
<span class="fc" id="L77">                                  .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;aux:Lens&quot;)))</span>
<span class="fc" id="L78">                                  .or(() -&gt; Optional.ofNullable(xmpProperties.get(&quot;aux:LensID&quot;)))</span>
<span class="fc" id="L79">                                  .orElse(&quot;&quot;);</span>

<span class="pc bpc" id="L81" title="1 of 4 branches missed.">        var lens = (lensMake + ((!lensModel.isBlank() &amp;&amp; !lensMake.isBlank()) ? &quot; &quot; : &quot;&quot;) + lensModel).trim();</span>
<span class="fc" id="L82">        lens = lensMap.getOrDefault(lens, lens);</span>

<span class="fc" id="L84">        builder.append(lens);</span>
<span class="fc" id="L85">        builder.append(&quot; @ &quot;);</span>
<span class="fc" id="L86">        exif.getFocalLength().ifPresent(fl -&gt; builder.append(fl.intValue()).append(&quot; mm, &quot;));</span>
        // FIXME: eventually teleconverter
eventually teleconverter
<span class="fc" id="L88"> exif.getExposureTime().ifPresent(t -&gt; builder.append(t).append(&quot; sec @ ƒ/&quot;));</span> <span class="fc" id="L89"> exif.getFNumber().map(f -&gt; new DecimalFormat(&quot;0.#&quot;).format(f.floatValue())).ifPresent(builder::append);</span> <span class="fc" id="L91"> exif.getExposureBiasValue().ifPresent(exposureBiasValue -&gt;</span> { <span class="fc bfc" id="L93" title="All 2 branches covered."> if (exposureBiasValue.getNumerator() != 0)</span> { <span class="fc" id="L95"> builder.append(String.format(&quot;, %+.2f EV&quot;, exposureBiasValue.floatValue()));</span> } <span class="fc" id="L97"> });</span> <span class="fc" id="L99"> exif.getISOSpeedRatings().ifPresent(iso -&gt; builder.append(&quot;, ISO &quot;).append(iso.intValue()));</span> <span class="fc" id="L101"> return template.replace(&quot;$&quot; + macro + &quot;$&quot;, builder.toString());</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>