Content of file DefaultContent.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>DefaultContent.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 :: Components :: HTML Template</a> &gt; <a href="../index.html" class="el_bundle">it-tidalwave-northernwind-core-default</a> &gt; <a href="index.source.html" class="el_package">it.tidalwave.northernwind.core.impl.model</a> &gt; <span class="el_source">DefaultContent.java</span></div><h1>DefaultContent.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.core.impl.model;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.text.Normalizer;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Configurable;
import it.tidalwave.util.Finder;
import it.tidalwave.util.Key;
import it.tidalwave.northernwind.core.model.Content;
import it.tidalwave.northernwind.core.model.RequestContext;
import it.tidalwave.northernwind.core.model.ResourcePath;
import it.tidalwave.northernwind.core.model.ResourceProperties;
import it.tidalwave.northernwind.core.model.spi.ContentSupport;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;

// FIXME: reimplement with an Aspect
reimplement with an Aspect
<span class="nc" id="L49">@RequiredArgsConstructor</span> class ResourcePropertiesDelegate implements ResourceProperties { @Nonnull private final RequestContext requestContext; @Nonnull private final Content content; interface Exclusions { public &lt;T&gt; Optional&lt;T&gt; getProperty (Key&lt;? extends T&gt; key); public &lt;T&gt; Optional&lt;T&gt; getProperty (List&lt;Key&lt;? extends T&gt;&gt; keys); } <span class="nc" id="L64"> @Nonnull @Delegate(types=ResourceProperties.class, excludes=Exclusions.class)</span> private final ResourceProperties delegate; @Nonnull @Override public &lt;T&gt; Optional&lt;T&gt; getProperty (@Nonnull final Key&lt;? extends T&gt; key) { try { <span class="nc" id="L73"> requestContext.setContent(content);</span> <span class="nc" id="L74"> return delegate.getProperty(key);</span> } finally { <span class="nc" id="L78"> requestContext.clearContent();</span> } } } /*********************************************************************************************************************** * * A piece of content to be composed into a {@code Node}. * * @author Fabrizio Giudici * **********************************************************************************************************************/ <span class="nc" id="L90">@Configurable @Slf4j @ToString(callSuper = true, exclude=&quot;requestContext&quot;)</span> /* package */ class DefaultContent extends ContentSupport { @Inject private RequestContext requestContext; /******************************************************************************************************************* * * Creates a new {@code DefaultContent} with the given {@link Content.Builder}. * * @param builder the builder * ******************************************************************************************************************/ public DefaultContent (@Nonnull final Content.Builder builder) { <span class="nc bnc" id="L105" title="All 18 branches missed."> super(builder);</span> <span class="nc bnc" id="L106" title="All 4 branches missed."> }</span> /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Finder&lt;Content&gt; findChildren() { <span class="nc" id="L116"> return new PathFinderSupport&lt;&gt;(this);</span> } /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Optional&lt;ResourcePath&gt; getExposedUri() { <span class="nc" id="L127"> final var exposedUri = getProperty(P_EXPOSED_URI);</span> <span class="nc bnc" id="L128" title="All 2 branches missed."> return exposedUri.isPresent() ? exposedUri.map(ResourcePath::of) : getDefaultExposedUri();</span> // return getProperty(P_EXPOSED_URI).map(ResourcePath::of).orElseGet(() -&gt; getDefaultExposedUri()); TODO } /******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull private Optional&lt;ResourcePath&gt; getDefaultExposedUri() { <span class="nc" id="L140"> return getResource().getProperty(P_TITLE)</span> <span class="nc" id="L141"> .map(DefaultContent::deAccent)</span> <span class="nc" id="L142"> .map(t -&gt; t.replaceAll(&quot; &quot;, &quot;-&quot;)</span> <span class="nc" id="L143"> .replaceAll(&quot;,&quot;, &quot;&quot;)</span> <span class="nc" id="L144"> .replaceAll(&quot;\\.&quot;, &quot;&quot;)</span> <span class="nc" id="L145"> .replaceAll(&quot;;&quot;, &quot;&quot;)</span> <span class="nc" id="L146"> .replaceAll(&quot;/&quot;, &quot;&quot;)</span> <span class="nc" id="L147"> .replaceAll(&quot;!&quot;, &quot;&quot;)</span> <span class="nc" id="L148"> .replaceAll(&quot;\\?&quot;, &quot;&quot;)</span> <span class="nc" id="L149"> .replaceAll(&quot;:&quot;, &quot;&quot;)</span> <span class="nc" id="L150"> .replaceAll(&quot;[^\\w-]*&quot;, &quot;&quot;))</span> <span class="nc" id="L151"> .map(String::toLowerCase)</span> <span class="nc" id="L152"> .map(ResourcePath::of);</span> } /******************************************************************************************************************* * * See http://stackoverflow.com/questions/1008802/converting-symbols-accent-letters-to-english-alphabet * ******************************************************************************************************************/ @Nonnull public static String deAccent (@Nonnull final String string) { <span class="nc" id="L163"> final var nfdNormalizedString = Normalizer.normalize(string, Normalizer.Form.NFD);</span> <span class="nc" id="L164"> final var pattern = Pattern.compile(&quot;\\p{InCombiningDiacriticalMarks}+&quot;);</span> <span class="nc" id="L165"> return pattern.matcher(nfdNormalizedString).replaceAll(&quot;&quot;);</span> } @Override @Nonnull public ResourceProperties getProperties() { <span class="nc" id="L171"> return new ResourcePropertiesDelegate(requestContext, this, getResource().getProperties());</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>