Content of file DefaultModelFactory.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>DefaultModelFactory.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> > <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">DefaultModelFactory.java</span></div><h1>DefaultModelFactory.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.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import it.tidalwave.northernwind.core.model.Content;
import it.tidalwave.northernwind.core.model.Media;
import it.tidalwave.northernwind.core.model.ModelFactory;
import it.tidalwave.northernwind.core.model.Request;
import it.tidalwave.northernwind.core.model.Resource;
import it.tidalwave.northernwind.core.model.ResourceFile;
import it.tidalwave.northernwind.core.model.ResourceProperties;
import it.tidalwave.northernwind.core.model.Site;
import it.tidalwave.northernwind.core.model.SiteNode;
import it.tidalwave.northernwind.core.model.spi.ModelFactorySupport;
import it.tidalwave.northernwind.frontend.ui.Layout;
import it.tidalwave.northernwind.frontend.impl.ui.DefaultLayout;
import lombok.ToString;
/***********************************************************************************************************************
*
* The default implementation of {@link ModelFactory}.
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc" id="L56">@ToString</span>
<span class="nc" id="L57">public class DefaultModelFactory extends ModelFactorySupport</span>
{
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Resource build (@Nonnull final Resource.Builder builder)
{
<span class="nc" id="L67"> return new DefaultResource(builder);</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Content build (@Nonnull final Content.Builder builder)
{
<span class="nc" id="L78"> return new DefaultContent(builder);</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Media build (@Nonnull final Media.Builder builder)
{
<span class="nc" id="L89"> return new DefaultMedia(builder);</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public SiteNode createSiteNode (@Nonnull final Site site, @Nonnull final ResourceFile folder)
{
<span class="nc" id="L100"> return new DefaultSiteNode(this, (DefaultSite)site, folder);</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Layout build (@Nonnull final Layout.Builder builder)
{
<span class="nc" id="L111"> return new DefaultLayout(builder);</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public DefaultRequest createRequest()
{
<span class="nc" id="L122"> return new DefaultRequest();</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Request createRequestFrom (@Nonnull final HttpServletRequest httpServletRequest)
{
<span class="nc" id="L133"> var relativeUri = httpServletRequest.getRequestURI().substring(httpServletRequest.getContextPath().length());</span>
<span class="nc bnc" id="L134" title="All 2 branches missed."> relativeUri = "".equals(relativeUri) ? "/" : relativeUri;</span>
<span class="nc" id="L135"> return createRequest().withBaseUrl(getBaseUrl(httpServletRequest))</span>
<span class="nc" id="L136"> .withRelativeUri(relativeUri)</span>
<span class="nc" id="L137"> .withParameterMap(httpServletRequest.getParameterMap())</span>
<span class="nc" id="L138"> .withHeaderMap(toMap(httpServletRequest))</span>
<span class="nc" id="L139"> .withPreferredLocales(Collections.list(httpServletRequest.getLocales()));</span>
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public ResourceProperties build (@Nonnull final ResourceProperties.Builder builder)
{
<span class="nc" id="L150"> return new DefaultResourceProperties(builder);</span>
// return new DefaultResourceProperties(id, DefaultResourceProperties.PropertyResolver.DEFAULT);
}
/*******************************************************************************************************************
*
* {@inheritDoc}
*
******************************************************************************************************************/
@Override @Nonnull
public Site build (@Nonnull final Site.Builder builder)
{
<span class="nc" id="L162"> return new DefaultSite(builder);</span>
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
private static String getBaseUrl (@Nonnull final HttpServletRequest httpServletRequest)
{
<span class="nc" id="L172"> return httpServletRequest.getRequestURL().toString().replaceAll(":.*", "")</span>
<span class="nc" id="L173"> + "://" + httpServletRequest.getHeader("Host");</span>
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
private static Map<String, List<String>> toMap (@Nonnull final HttpServletRequest httpServletRequest)
{
<span class="nc" id="L183"> final Map<String, List<String>> headerMap = new HashMap<>();</span>
<span class="nc bnc" id="L185" title="All 2 branches missed."> for (final var e = httpServletRequest.getHeaderNames(); e.hasMoreElements(); )</span>
{
<span class="nc" id="L187"> final var headerName = e.nextElement();</span>
<span class="nc" id="L188"> final var headerValue = httpServletRequest.getHeader(headerName); // FIXME: lacks support for multivalue</span>
| lacks support for multivalue | |
<span class="nc" id="L189"> headerMap.put(headerName, List.of(headerValue));</span>
<span class="nc" id="L190"> }</span>
<span class="nc" id="L192"> return headerMap;</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>