1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.icon.internal; |
21 |
|
|
22 |
|
import java.io.StringWriter; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
|
29 |
|
import org.apache.commons.lang.StringUtils; |
30 |
|
import org.xwiki.icon.Icon; |
31 |
|
import org.xwiki.icon.IconException; |
32 |
|
import org.xwiki.icon.IconRenderer; |
33 |
|
import org.xwiki.icon.IconSet; |
34 |
|
import org.xwiki.skinx.SkinExtension; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@since |
40 |
|
@version |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (39) |
Complexity: 11 |
Complexity Density: 0.46 |
|
42 |
|
public class DefaultIconRenderer implements IconRenderer |
43 |
|
{ |
44 |
|
@Inject |
45 |
|
@Named("ssx") |
46 |
|
private SkinExtension skinExtension; |
47 |
|
|
48 |
|
@Inject |
49 |
|
@Named("linkx") |
50 |
|
private SkinExtension linkExtension; |
51 |
|
|
52 |
|
@Inject |
53 |
|
@Named("jsx") |
54 |
|
private SkinExtension jsExtension; |
55 |
|
|
56 |
|
@Inject |
57 |
|
private VelocityRenderer velocityRenderer; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
147 |
@Override... |
60 |
|
public String render(String iconName, IconSet iconSet) throws IconException |
61 |
|
{ |
62 |
147 |
return render(iconSet, iconName, iconSet.getRenderWiki()); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
2534 |
@Override... |
66 |
|
public String renderHTML(String iconName, IconSet iconSet) throws IconException |
67 |
|
{ |
68 |
2535 |
return render(iconSet, iconName, iconSet.getRenderHTML()); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
71 |
2681 |
private String render(IconSet iconSet, String iconName, String renderer) throws IconException... |
72 |
|
{ |
73 |
2681 |
if (!StringUtils.isBlank(iconSet.getCss())) { |
74 |
2 |
activeCSS(iconSet); |
75 |
|
} |
76 |
2681 |
if (!StringUtils.isBlank(iconSet.getSsx())) { |
77 |
11 |
activeSSX(iconSet); |
78 |
|
} |
79 |
2682 |
if (!StringUtils.isBlank(iconSet.getJsx())) { |
80 |
11 |
activeJSX(iconSet); |
81 |
|
} |
82 |
2681 |
return renderIcon(iconSet, iconName, renderer); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
85 |
2 |
private void activeCSS(IconSet iconSet) throws IconException... |
86 |
|
{ |
87 |
2 |
String url = velocityRenderer.render(iconSet.getCss()); |
88 |
2 |
Map<String, Object> parameters = new HashMap(); |
89 |
2 |
parameters.put("rel", "stylesheet"); |
90 |
2 |
linkExtension.use(url, parameters); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
11 |
private void activeSSX(IconSet iconSet)... |
94 |
|
{ |
95 |
11 |
skinExtension.use(iconSet.getSsx()); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
11 |
private void activeJSX(IconSet iconSet)... |
99 |
|
{ |
100 |
11 |
jsExtension.use(iconSet.getJsx()); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
103 |
2681 |
private String renderIcon(IconSet iconSet, String iconName, String renderer) throws IconException... |
104 |
|
{ |
105 |
|
|
106 |
2681 |
Icon icon = iconSet.getIcon(iconName); |
107 |
|
|
108 |
|
|
109 |
2681 |
if (icon == null) { |
110 |
|
|
111 |
1 |
return ""; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
2680 |
StringWriter contentToParse = new StringWriter(); |
116 |
2680 |
contentToParse.write("#set($icon = \""); |
117 |
2681 |
contentToParse.write(icon.getValue()); |
118 |
2681 |
contentToParse.write("\")\n"); |
119 |
2681 |
contentToParse.write(renderer); |
120 |
|
|
121 |
2680 |
return velocityRenderer.render(contentToParse.toString()); |
122 |
|
} |
123 |
|
} |