Content of file DefaultContentRequestProcessor.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>DefaultContentRequestProcessor.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</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.model.spi</a> &gt; <span class="el_source">DefaultContentRequestProcessor.java</span></div><h1>DefaultContentRequestProcessor.java</h1><pre class="source lang-java linenums"><span class="nc" id="L1">/*</span>
 * #%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.model.spi;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Provider;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Scope;
import org.springframework.core.annotation.Order;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.northernwind.core.model.HttpStatusException;
import it.tidalwave.northernwind.core.model.Request;
import it.tidalwave.northernwind.core.model.RequestContext;
import it.tidalwave.northernwind.core.model.RequestProcessor;
import it.tidalwave.northernwind.core.model.Site;
import it.tidalwave.northernwind.core.model.SiteProvider;
import it.tidalwave.northernwind.frontend.ui.SiteView;
import static org.springframework.core.Ordered.LOWEST_PRECEDENCE;
import static it.tidalwave.northernwind.core.model.RequestProcessor.Status.*;
import static it.tidalwave.northernwind.core.model.SiteNode._SiteNode_;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 *
 **********************************************************************************************************************/
@Configurable @Scope(&quot;session&quot;) @Order(LOWEST_PRECEDENCE)
<span class="nc bnc" id="L53" title="All 22 branches missed.">public class DefaultContentRequestProcessor implements RequestProcessor</span>
  {
    @Inject
    private Provider&lt;SiteProvider&gt; siteProvider;

    @Inject
    private SiteView siteView;

    @Inject
    private RequestHolder requestHolder;

    @Inject
    private RequestContext requestContext;

    /*******************************************************************************************************************
     *
     * {@inheritDoc}
     *
     ******************************************************************************************************************/
    @Override @Nonnull
    public Status process (@Nonnull final Request request)
      throws NotFoundException, HttpStatusException
      {
        try
          {
<span class="nc" id="L78">            final var relativeUri = request.getRelativeUri();</span>
<span class="nc" id="L79">            final var site = siteProvider.get().getSite();</span>
<span class="nc" id="L80">            final var node = site.find(_SiteNode_).withRelativeUri(relativeUri).result();</span>
<span class="nc" id="L81">            requestContext.setNode(node);</span>
<span class="nc" id="L82">            siteView.renderSiteNode(request, node);</span>
            //
            // Check *after* finding the SiteNode, since a &quot;not found&quot; must have been already handled here.
            //
<span class="nc" id="L86">            enforceTrailingSlash(relativeUri, site);</span>
<span class="nc" id="L87">            return BREAK;</span>
          }
        finally
          {
<span class="nc" id="L91">            requestContext.clearNode();</span>
          }
      }

    /*******************************************************************************************************************
     *
     * If relativeUri doesn't end with a trailing slash, send a redirect to the proper Uri.
     * FIXME: could be dropped and replaced with a configurable redirect?
could be dropped and replaced with a configurable redirect?
* ******************************************************************************************************************/ private void enforceTrailingSlash (@Nonnull final String relativeUri, @Nonnull final Site site) throws HttpStatusException { <span class="nc" id="L104"> final var originalRelativeUri = requestHolder.get().getOriginalRelativeUri();</span> <span class="nc bnc" id="L106" title="All 4 branches missed."> if (!relativeUri.contains(&quot;.&quot;) &amp;&amp; !originalRelativeUri.endsWith(&quot;/&quot;))</span> { <span class="nc" id="L108"> throw HttpStatusException.temporaryRedirect(site, relativeUri); // TODO: temporary or permanent?</span> } <span class="nc" id="L110"> }</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>