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

File JARTranslationBundleFactory.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
6
1
1
81
39
3
0.5
6
1
3

Classes

Class Line # Actions
JARTranslationBundleFactory 44 6 0% 3 9
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.jar.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.slf4j.Logger;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.localization.TranslationBundle;
32    import org.xwiki.localization.TranslationBundleDoesNotExistsException;
33    import org.xwiki.localization.TranslationBundleFactory;
34   
35    /**
36    * Generate and manage resource based translations bundles.
37    *
38    * @version $Id: 8f43f16845a6edf944e73572d9ffd7e75f4d19f7 $
39    * @since 4.5M1
40    */
41    @Component
42    @Named(JARTranslationBundleFactory.ID)
43    @Singleton
 
44    public class JARTranslationBundleFactory implements TranslationBundleFactory
45    {
46    /**
47    * The identifier of this {@link TranslationBundleFactory}.
48    */
49    public static final String ID = "jar";
50   
51    /**
52    * Used to access the right {@link ComponentManager} depending on the current context.
53    */
54    @Inject
55    @Named("context")
56    private Provider<ComponentManager> contextComponentManagerProvider;
57   
58    /**
59    * Used to log.
60    */
61    @Inject
62    private Logger logger;
63   
 
64  0 toggle @Override
65    public TranslationBundle getBundle(String bundleId) throws TranslationBundleDoesNotExistsException
66    {
67  0 String id = ID + ':' + bundleId;
68   
69  0 if (this.contextComponentManagerProvider.get().hasComponent(TranslationBundle.class, id)) {
70  0 try {
71  0 return this.contextComponentManagerProvider.get().getInstance(TranslationBundle.class, id);
72    } catch (ComponentLookupException e) {
73  0 this.logger.debug("Failed to lookup component [{}] with hint [{}].", TranslationBundle.class, bundleId,
74    e);
75    }
76    }
77   
78  0 throw new TranslationBundleDoesNotExistsException(String.format("Can't find any JAR resource for jar [%s]",
79    bundleId));
80    }
81    }