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

File DefaultIconManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
22
10
1
131
83
17
0.77
2.2
10
1.7

Classes

Class Line # Actions
DefaultIconManager 42 22 0% 17 0
1.0100%
 

Contributing tests

This file is covered by 6 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.icon.internal;
21   
22    import java.util.List;
23   
24    import javax.inject.Inject;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.icon.IconException;
29    import org.xwiki.icon.IconManager;
30    import org.xwiki.icon.IconRenderer;
31    import org.xwiki.icon.IconSet;
32    import org.xwiki.icon.IconSetManager;
33   
34    /**
35    * Default implementation of {@link org.xwiki.icon.IconManager}.
36    *
37    * @since 6.2M1
38    * @version $Id: 5ea453793f49e20fd7e55bfb50017bd18c79d7a5 $
39    */
40    @Component
41    @Singleton
 
42    public class DefaultIconManager implements IconManager
43    {
44    @Inject
45    private IconSetManager iconSetManager;
46   
47    @Inject
48    private IconRenderer iconRenderer;
49   
 
50  125 toggle @Override
51    public String render(String iconName) throws IconException
52    {
53  125 return iconRenderer.render(iconName, getIconSet(iconName));
54    }
55   
 
56  21 toggle @Override
57    public String render(String iconName, String iconSetName) throws IconException
58    {
59  21 return this.render(iconName, iconSetName, true);
60    }
61   
 
62  27 toggle @Override
63    public String render(String iconName, String iconSetName, boolean fallback) throws IconException
64    {
65  27 IconSet iconSet = getIconSet(iconName, iconSetName, fallback);
66  27 if (iconSet == null) {
67  1 return "";
68    }
69  26 return iconRenderer.render(iconName, iconSet);
70    }
71   
 
72  2533 toggle @Override
73    public String renderHTML(String iconName) throws IconException
74    {
75  2533 return iconRenderer.renderHTML(iconName, getIconSet(iconName));
76    }
77   
 
78  3 toggle @Override
79    public String renderHTML(String iconName, String iconSetName) throws IconException
80    {
81  3 return this.renderHTML(iconName, iconSetName, true);
82    }
83   
 
84  9 toggle @Override
85    public String renderHTML(String iconName, String iconSetName, boolean fallback) throws IconException
86    {
87  9 IconSet iconSet = getIconSet(iconName, iconSetName, fallback);
88  9 if (iconSet == null) {
89  1 return "";
90    }
91  8 return iconRenderer.renderHTML(iconName, iconSet);
92    }
93   
 
94  1 toggle @Override
95    public List<String> getIconNames() throws IconException
96    {
97  1 return iconSetManager.getCurrentIconSet().getIconNames();
98    }
99   
 
100  1 toggle @Override
101    public List<String> getIconNames(String iconSetName) throws IconException
102    {
103  1 return iconSetManager.getIconSet(iconSetName).getIconNames();
104    }
105   
 
106  2657 toggle private IconSet getIconSet(String iconName) throws IconException
107    {
108    // First: try to render with the current icon set
109  2657 IconSet currentIconSet = iconSetManager.getCurrentIconSet();
110  2658 if (currentIconSet != null && currentIconSet.getIcon(iconName) != null) {
111  2 return currentIconSet;
112    }
113   
114    // Fallback to the default icon set
115  2655 return iconSetManager.getDefaultIconSet();
116    }
117   
 
118  36 toggle private IconSet getIconSet(String iconName, String iconSetName, boolean fallback) throws IconException
119    {
120    // Get the specified icon set
121  36 IconSet iconSet = iconSetManager.getIconSet(iconSetName);
122   
123    // Fallback if necessary
124  36 if ((iconSet == null || iconSet.getIcon(iconName) == null) && fallback) {
125  8 return iconSetManager.getDefaultIconSet();
126    }
127   
128    // Return the icon set
129  28 return iconSet;
130    }
131    }