Content of file LayeredResourceFileSystem.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>LayeredResourceFileSystem.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 :: Filesystems :: SCM :: Git</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core-filesystem-basic</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.frontend.filesystem.basic.layered</a> &gt; <span class="el_source">LayeredResourceFileSystem.java</span></div><h1>LayeredResourceFileSystem.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.filesystem.basic.layered;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.ListIterator;
import java.io.IOException;
import it.tidalwave.util.As;
import it.tidalwave.northernwind.core.model.ResourceFile;
import it.tidalwave.northernwind.core.model.ResourceFileSystemProvider;
import it.tidalwave.northernwind.core.model.spi.DecoratedResourceFileSystem;
import it.tidalwave.northernwind.frontend.filesystem.basic.FileSystemProvidersProvider;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;

/***********************************************************************************************************************
 *
 * @author Fabrizio Giudici
 *
 **********************************************************************************************************************/
<span class="fc" id="L49">@RequiredArgsConstructor @Slf4j</span>
public class LayeredResourceFileSystem implements DecoratedResourceFileSystem
  {
    @Nonnull
    private final List&lt;ResourceFileSystemProvider&gt; delegates;

    private final FileSystemProvidersProvider fileSystemProvidersProvider;

<span class="fc" id="L57">    private final IdentityHashMap&lt;ResourceFile, ResourceFile&gt; delegateLightWeightMap = new IdentityHashMap&lt;&gt;();</span>

<span class="pc" id="L59">    @Delegate</span>
<span class="fc" id="L60">    private final As asSupport = As.forObject(this);</span>

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public ResourceFile getRoot()
      {
<span class="fc" id="L70">        return findFileByPath(&quot;&quot;);</span>
      }

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override @CheckForNull
    public ResourceFile findFileByPath (@Nonnull final String name)
      {
<span class="fc" id="L81">        log.trace(&quot;findResource({})&quot;, name);</span>
<span class="fc" id="L82">        ResourceFile result = null;</span>

        // FIXME: move to init!
move to init!
<span class="pc bpc" id="L85" title="1 of 2 branches missed."> if (fileSystemProvidersProvider != null)</span> { <span class="nc" id="L87"> delegates.clear();</span> <span class="nc" id="L88"> final var fileSystemProviders = fileSystemProvidersProvider.getFileSystemProviders();</span> <span class="nc" id="L89"> delegates.addAll(fileSystemProviders);</span> } <span class="fc" id="L92"> for (final ListIterator&lt;? extends ResourceFileSystemProvider&gt; i = delegates.listIterator(delegates.size());</span> <span class="pc bpc" id="L93" title="1 of 2 branches missed."> i.hasPrevious(); )</span> { try { <span class="fc" id="L97"> final var fileSystem = i.previous().getFileSystem();</span> <span class="fc" id="L98"> final var fileObject = fileSystem.findFileByPath(name);</span> <span class="pc bpc" id="L100" title="1 of 2 branches missed."> if (fileObject != null)</span> { <span class="fc" id="L102"> log.trace(&quot;&gt;&gt;&gt;&gt; fileSystem: {}, fileObject: {}&quot;, fileSystem, fileObject.getPath());</span> <span class="fc" id="L103"> result = createDecoratorFile(fileObject);</span> <span class="fc" id="L104"> break;</span> } } <span class="nc" id="L107"> catch (IOException e)</span> { <span class="nc" id="L109"> log.warn(&quot;&quot;, e);</span> <span class="nc" id="L110"> }</span> } <span class="fc" id="L113"> log.trace(&quot;&gt;&gt;&gt;&gt; returning {}&quot;, result);</span> <span class="fc" id="L115"> return result;</span> } /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public synchronized ResourceFile createDecoratorFile (@Nonnull final ResourceFile delegateFile) { <span class="pc bpc" id="L126" title="1 of 2 branches missed."> if (delegateFile == null)</span> { <span class="nc" id="L128"> return null;</span> } <span class="fc" id="L131"> var decorator = delegateLightWeightMap.get(delegateFile);</span> <span class="pc bpc" id="L133" title="1 of 2 branches missed."> if (decorator == null)</span> { <span class="fc bfc" id="L135" title="All 2 branches covered."> decorator = (delegateFile.isData() ? new DecoratorResourceFile(this, delegateFile)</span> <span class="fc" id="L136"> : new DecoratorResourceFolder(this,</span> delegates, <span class="fc" id="L138"> delegateFile.getPath(),</span> delegateFile)); <span class="fc" id="L140"> delegateLightWeightMap.put(delegateFile, decorator);</span> } <span class="fc" id="L143"> return decorator;</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>