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

File AbstractTranslation.java

 

Coverage histogram

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

Code metrics

4
12
9
1
125
62
11
0.92
1.33
9
1.22

Classes

Class Line # Actions
AbstractTranslation 37 12 0% 11 3
0.8888%
 

Contributing tests

This file is covered by 17 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 org.xwiki.localization.internal;
21   
22    import java.util.Collection;
23    import java.util.Locale;
24   
25    import org.xwiki.localization.TranslationBundle;
26    import org.xwiki.localization.TranslationBundleContext;
27    import org.xwiki.localization.Translation;
28    import org.xwiki.localization.message.TranslationMessage;
29    import org.xwiki.rendering.block.Block;
30   
31    /**
32    * Base class for all {@link Translation} implementations.
33    *
34    * @version $Id: dfef161eb321989ffc5a9bbec1766424a80c6c6f $
35    * @since 4.3M2
36    */
 
37    public abstract class AbstractTranslation implements Translation
38    {
39    /**
40    * Used to resolve variables.
41    */
42    private TranslationBundleContext context;
43   
44    /**
45    * The bundle containing the translation.
46    */
47    private LocalizedTranslationBundle localeBundle;
48   
49    /**
50    * The key associated to the translation.
51    */
52    private String key;
53   
54    /**
55    * The actual translation message.
56    */
57    private TranslationMessage message;
58   
59    /**
60    * @param context used to resolve variables
61    * @param localeBundle the bundle containing the translation
62    * @param key the key associated to the translation
63    * @param message the actual translation message
64    */
 
65  297863 toggle public AbstractTranslation(TranslationBundleContext context, LocalizedTranslationBundle localeBundle, String key,
66    TranslationMessage message)
67    {
68  297863 this.context = context;
69  297863 this.localeBundle = localeBundle;
70  297863 this.key = key;
71  297863 this.message = message;
72    }
73   
 
74  0 toggle @Override
75    public TranslationBundle getBundle()
76    {
77  0 return this.localeBundle.getBundle();
78    }
79   
 
80  159912 toggle @Override
81    public Locale getLocale()
82    {
83  159913 return this.localeBundle.getLocale();
84    }
85   
 
86  301322 toggle @Override
87    public String getKey()
88    {
89  301322 return this.key;
90    }
91   
 
92  18 toggle @Override
93    public Object getRawSource()
94    {
95  18 return this.message.getRawSource();
96    }
97   
98    // Render
99   
100    /**
101    * @return the bundle to search other translations
102    */
 
103  76308 toggle private Collection<TranslationBundle> getCurrentBundles()
104    {
105  76303 return this.context != null ? this.context.getBundles() : null;
106    }
107   
 
108  76306 toggle @Override
109    public Block render(Locale locale, Object... parameters)
110    {
111  76303 return this.message.render(locale != null ? locale : getLocale(), getCurrentBundles(), parameters);
112    }
113   
 
114  4363 toggle @Override
115    public Block render(Object... parameters)
116    {
117  4363 return render(null, parameters);
118    }
119   
 
120  3459 toggle @Override
121    public String toString()
122    {
123  3459 return getKey() + ':' + this.message.toString();
124    }
125    }