blob: 39b579fcde0c526c6e31a20e86b02e6479c4ce37 [file] [log] [blame]
<?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=""><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>RundataLocalizationService.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">Apache Turbine</a> &gt; <a href="index.source.html" class="el_package">org.apache.turbine.services.localization</a> &gt; <span class="el_source">RundataLocalizationService.java</span></div><h1>RundataLocalizationService.java</h1><pre class="source lang-java linenums">package org.apache.turbine.services.localization;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.util.Locale;
import org.apache.fulcrum.localization.DefaultLocalizationService;
import org.apache.fulcrum.localization.LocalizationService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.turbine.om.security.User;
import org.apache.turbine.util.RunData;
/**
*
* Instead of reading first the accept-language header in a http request,
* instead this method read the user.getTemp(&quot;locale&quot;)
* from the RunData to obtain the language choice by the user
* without the browser language rule.
* If user.getPerm(&quot;language&quot;) is not set,
* the &quot;Accept-Language&quot; header is read.
*
* Adapted from the Jetspeed-1 implementation of CustomLocalizationService.
*
*/
<span class="nc" id="L43">public class RundataLocalizationService extends DefaultLocalizationService implements RundataLocalizationInterface {</span>
<span class="nc" id="L45"> private static final Logger log = LogManager.getLogger(RundataLocalizationService.class); </span>
@Override
public Locale getLocale(RunData data) {
<span class="nc" id="L49"> User user = data.getUser();</span>
<span class="nc bnc" id="L50" title="All 2 branches missed."> log.debug( &quot;retrieving lang from req header :{}&quot;,</span>
<span class="nc bnc" id="L51" title="All 2 branches missed."> (user == null || user.getTemp(&quot;locale&quot;) == null ) );</span>
<span class="nc bnc" id="L53" title="All 2 branches missed."> if (user == null)</span>
{
<span class="nc" id="L55"> return getLocale(data.getRequest().getHeader(LocalizationService.ACCEPT_LANGUAGE));</span>
}
else
{
try
{
<span class="nc" id="L61"> Locale locale = (Locale) data.getUser().getTemp(&quot;locale&quot;);</span>
<span class="nc bnc" id="L62" title="All 2 branches missed."> if (locale == null)</span>
{
<span class="nc" id="L64"> return getLocale(data.getRequest().getHeader(LocalizationService.ACCEPT_LANGUAGE));</span>
}
else
{
<span class="nc" id="L68"> log.debug( &quot;retrieved lang from temp(locale):{}&quot;, ()-&gt; locale.getLanguage() );</span>
<span class="nc" id="L69"> return locale;</span>
}
}
<span class="nc" id="L72"> catch (Exception use)</span>
{
<span class="nc" id="L74"> return getLocale(data.getRequest().getHeader(LocalizationService.ACCEPT_LANGUAGE));</span>
}
}
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html>