Content of file DefaultInheritanceHelper.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>DefaultInheritanceHelper.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> > <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core-default</a> > <a href="index.source.html" class="el_package">it.tidalwave.northernwind.core.impl.model</a> > <span class="el_source">DefaultInheritanceHelper.java</span></div><h1>DefaultInheritanceHelper.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 "License"); 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 "AS IS" 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.core.impl.model;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.northernwind.core.model.ResourceFile;
import lombok.extern.slf4j.Slf4j;
/***********************************************************************************************************************
*
* Implements the default inheritance policy for properties. The sequence of loaded file is:
*
* <ul>
* <li>parent default</li>
* <li>parent localized</li>
* <li>this level default</li>
* <li>this level localized</li>
* <li>override default</li>
* <li>override localized</li>
* </ul>
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L54">@Slf4j</span>
<span class="nc" id="L55">public class DefaultInheritanceHelper implements InheritanceHelper</span>
{
/*******************************************************************************************************************
*
******************************************************************************************************************/
@Override @Nonnull
public List<ResourceFile> getInheritedPropertyFiles (@Nonnull final ResourceFile folder,
@Nonnull final Locale locale,
@Nonnull final String propertyFileName)
{
<span class="nc" id="L65"> log.trace("getInheritedPropertyFiles({}, {})", folder.getPath(), propertyFileName);</span>
<span class="nc" id="L67"> final List<String> suffixes = new ArrayList<>();</span>
<span class="nc" id="L68"> suffixes.add("");</span>
<span class="nc" id="L69"> suffixes.add("_" + locale.getLanguage());</span>
<span class="nc" id="L70"> final List<ResourceFile> files = new ArrayList<>();</span>
<span class="nc bnc" id="L72" title="All 2 branches missed."> for (final var parentFolder : getHierarchyFolders(folder))</span>
{
<span class="nc" id="L74"> files.addAll(getFiles("", propertyFileName, parentFolder, suffixes));</span>
<span class="nc" id="L75"> }</span>
<span class="nc" id="L77"> files.addAll(getFiles("Override", propertyFileName, folder, suffixes));</span>
<span class="nc" id="L79"> log.trace(">>>> property file candidates: {}", files);</span>
<span class="nc" id="L81"> return files;</span>
}
/*******************************************************************************************************************
*
******************************************************************************************************************/
private static List<ResourceFile> getFiles (@Nonnull final String prefix,
@Nonnull final String propertyFileName,
@Nonnull final ResourceFile folder,
@Nonnull final List<String> suffixes)
{
<span class="nc" id="L92"> final List<ResourceFile> files = new ArrayList<>();</span>
<span class="nc bnc" id="L94" title="All 2 branches missed."> for (final var localeSuffix : suffixes)</span>
{
<span class="nc" id="L96"> final var fileName = prefix + propertyFileName + localeSuffix + ".xml";</span>
<span class="nc" id="L97"> log.trace(">>>> probing {} ...", folder.getPath().asString() + "/" + fileName);</span>
try
{
<span class="nc" id="L101"> files.add(folder.findChildren().withName(fileName).result());</span>
}
<span class="nc" id="L103"> catch (NotFoundException e)</span>
{
// ok. do nothing
<span class="nc" id="L106"> }</span>
<span class="nc" id="L107"> }</span>
<span class="nc" id="L109"> return files;</span>
}
/*******************************************************************************************************************
*
******************************************************************************************************************/
@Nonnull
private static List<ResourceFile> getHierarchyFolders (@Nonnull final ResourceFile folder)
{
<span class="nc" id="L118"> final List<ResourceFile> folders = new ArrayList<>();</span>
<span class="nc bnc" id="L120" title="All 2 branches missed."> for (var parent = folder; parent.getParent() != null; parent = parent.getParent()) // TODO: refactor with recursion?</span>
{
<span class="nc" id="L122"> folders.add(parent);</span>
}
<span class="nc" id="L125"> Collections.reverse(folders);</span>
<span class="nc" id="L127"> return folders;</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>