1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.localization

File XWikiLocalizationContext.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

6
9
1
1
69
33
4
0.44
9
1
4

Classes

Class Line # Actions
XWikiLocalizationContext 43 9 0% 4 3
0.812581.2%
 

Contributing tests

This file is covered by 19 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal.localization;
21   
22    import java.util.Locale;
23   
24    import javax.inject.Inject;
25    import javax.inject.Provider;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.localization.LocaleUtils;
30    import org.xwiki.localization.LocalizationContext;
31   
32    import com.xpn.xwiki.XWiki;
33    import com.xpn.xwiki.XWikiContext;
34   
35    /**
36    * Default implementation of {@link LocalizationContext}.
37    *
38    * @version $Id: d640e3199cf950d6fb346cdf836a29404575fc57 $
39    * @since 4.3M2
40    */
41    @Component
42    @Singleton
 
43    public class XWikiLocalizationContext implements LocalizationContext
44    {
45    /**
46    * Used to access the configured locale.
47    */
48    @Inject
49    private Provider<XWikiContext> xcontextProvider;
50   
 
51  85038 toggle @Override
52    public Locale getCurrentLocale()
53    {
54  85039 Locale currentLocale = Locale.getDefault();
55   
56  85041 XWikiContext xcontext = this.xcontextProvider.get();
57  85040 if (xcontext != null) {
58  85040 XWiki xwiki = xcontext.getWiki();
59  85039 if (xwiki != null) {
60  85038 String locale = xwiki.getLanguagePreference(xcontext);
61  85040 if (locale != null) {
62  85038 currentLocale = LocaleUtils.toLocale(locale);
63    }
64    }
65    }
66   
67  85039 return currentLocale;
68    }
69    }