1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.parser.xwiki10.macro; |
21 |
|
|
22 |
|
import java.util.LinkedHashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.rendering.parser.xwiki10.FilterContext; |
30 |
|
import org.xwiki.rendering.parser.xwiki10.macro.AbstractRadeoxMacroConverter; |
31 |
|
import org.xwiki.rendering.parser.xwiki10.macro.RadeoxMacroConverter; |
32 |
|
import org.xwiki.rendering.parser.xwiki10.macro.RadeoxMacroParameter; |
33 |
|
import org.xwiki.rendering.parser.xwiki10.macro.RadeoxMacroParameters; |
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
39 |
|
@Component |
40 |
|
@Named("style") |
41 |
|
@Singleton |
|
|
| 80.1% |
Uncovered Elements: 29 (146) |
Complexity: 30 |
Complexity Density: 0.32 |
|
42 |
|
public class StyleRadeoxMacroConverter extends AbstractRadeoxMacroConverter |
43 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
44 |
1
|
public StyleRadeoxMacroConverter()... |
45 |
|
{ |
46 |
1
|
registerParameter("type"); |
47 |
1
|
registerParameter("id", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
48 |
1
|
registerParameter("class", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
49 |
1
|
registerParameter("align", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
50 |
1
|
registerParameter("name", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
51 |
1
|
registerParameter("font-size", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
52 |
1
|
registerParameter("font-family", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
53 |
1
|
registerParameter("color", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
54 |
1
|
registerParameter("background-color", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
55 |
1
|
registerParameter("float", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
56 |
1
|
registerParameter("width", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
57 |
1
|
registerParameter("height", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
58 |
1
|
registerParameter("border", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
59 |
1
|
registerParameter("document"); |
60 |
1
|
registerParameter("icon", RadeoxMacroConverter.PARAMETER_NOTEMPTYNONE); |
61 |
|
} |
62 |
|
|
|
|
| 95.5% |
Uncovered Elements: 1 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
63 |
2
|
@Override... |
64 |
|
public String convert(String name, RadeoxMacroParameters parameters, String content, FilterContext filterContext) |
65 |
|
{ |
66 |
2
|
StringBuffer result = new StringBuffer(); |
67 |
|
|
68 |
2
|
boolean inline = parameters.get("type") != null && parameters.get("type").getValue().equals("span"); |
69 |
|
|
70 |
|
|
71 |
2
|
StringBuffer parametersOpen = new StringBuffer(); |
72 |
2
|
Map<String, String> styleParameters = convertParameters(parameters); |
73 |
2
|
if (styleParameters.size() > 0) { |
74 |
2
|
parametersOpen.append("(% "); |
75 |
2
|
appendParameters(parametersOpen, styleParameters); |
76 |
2
|
parametersOpen.append(" %)"); |
77 |
2
|
result.append(filterContext.addProtectedContent(parametersOpen.toString(), inline)); |
78 |
|
} |
79 |
|
|
80 |
2
|
if (!inline) { |
81 |
|
|
82 |
1
|
result.append(filterContext.addProtectedContent("(((", false)); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
2
|
result.append(convertContent(content.trim(), parameters, filterContext)); |
87 |
|
|
88 |
|
|
89 |
2
|
if (inline) { |
90 |
|
|
91 |
1
|
result.append(filterContext.addProtectedContent("(%%)", true)); |
92 |
|
} else { |
93 |
|
|
94 |
1
|
result.append(filterContext.addProtectedContent(")))", false)); |
95 |
|
} |
96 |
|
|
97 |
2
|
return result.toString(); |
98 |
|
} |
99 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
100 |
2
|
@Override... |
101 |
|
protected String convertContent(String content, RadeoxMacroParameters parameters, FilterContext filterContext) |
102 |
|
{ |
103 |
2
|
StringBuffer result = new StringBuffer(); |
104 |
|
|
105 |
|
|
106 |
2
|
appendIcon(result, parameters, filterContext); |
107 |
|
|
108 |
2
|
if (content.length() > 0) { |
109 |
2
|
result.append(' '); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
2
|
result.append(content); |
114 |
|
|
115 |
2
|
return result.toString(); |
116 |
|
} |
117 |
|
|
|
|
| 70.8% |
Uncovered Elements: 21 (72) |
Complexity: 15 |
Complexity Density: 0.34 |
|
118 |
2
|
@Override... |
119 |
|
protected Map<String, String> convertParameters(RadeoxMacroParameters parameters) |
120 |
|
{ |
121 |
2
|
Map<String, String> boxParameters = new LinkedHashMap<String, String>(); |
122 |
|
|
123 |
2
|
RadeoxMacroParameter classes = parameters.get("class"); |
124 |
2
|
RadeoxMacroParameter icon = parameters.get("icon"); |
125 |
2
|
RadeoxMacroParameter id = parameters.get("id"); |
126 |
2
|
RadeoxMacroParameter align = parameters.get("align"); |
127 |
2
|
RadeoxMacroParameter name = parameters.get("name"); |
128 |
2
|
RadeoxMacroParameter size = parameters.get("font-size"); |
129 |
2
|
RadeoxMacroParameter font = parameters.get("font-family"); |
130 |
2
|
RadeoxMacroParameter color = parameters.get("color"); |
131 |
2
|
RadeoxMacroParameter bgcolor = parameters.get("background-color"); |
132 |
2
|
RadeoxMacroParameter fl = parameters.get("float"); |
133 |
2
|
RadeoxMacroParameter width = parameters.get("width"); |
134 |
2
|
RadeoxMacroParameter height = parameters.get("height"); |
135 |
2
|
RadeoxMacroParameter border = parameters.get("border"); |
136 |
|
|
137 |
|
|
138 |
2
|
if (classes != null) { |
139 |
0
|
boxParameters.put("class", classes.getValue().trim()); |
140 |
2
|
} else if (icon != null) { |
141 |
2
|
boxParameters.put("class", "stylemacro"); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
2
|
if (id != null) { |
146 |
0
|
boxParameters.put("id", id.getValue().trim()); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
2
|
if (name != null) { |
151 |
0
|
boxParameters.put("name", name.getValue().trim()); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
2
|
if (align != null) { |
156 |
0
|
boxParameters.put("align", align.getValue().trim()); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
2
|
StringBuffer styleStr = new StringBuffer(); |
161 |
|
|
162 |
2
|
if (size != null) { |
163 |
0
|
styleStr.append("font-size:" + size.getValue().trim() + "; "); |
164 |
|
} |
165 |
2
|
if (font != null) { |
166 |
0
|
styleStr.append("font-family:" + font.getValue().trim() + "; "); |
167 |
|
} |
168 |
2
|
if (color != null) { |
169 |
2
|
styleStr.append("color:" + color.getValue().trim() + "; "); |
170 |
|
} |
171 |
2
|
if (bgcolor != null) { |
172 |
2
|
styleStr.append("background-color:" + bgcolor.getValue().trim() + "; "); |
173 |
|
} |
174 |
2
|
if (width != null) { |
175 |
2
|
styleStr.append("width:" + width.getValue().trim() + "; "); |
176 |
|
} |
177 |
2
|
if (fl != null) { |
178 |
0
|
styleStr.append("float:" + fl.getValue().trim() + "; "); |
179 |
|
} |
180 |
2
|
if (height != null) { |
181 |
2
|
styleStr.append("height:" + height.getValue().trim() + "; "); |
182 |
|
} |
183 |
2
|
if (border != null) { |
184 |
2
|
styleStr.append("border:" + border.getValue().trim() + "; "); |
185 |
|
} |
186 |
|
|
187 |
2
|
if (styleStr.length() > 0) { |
188 |
2
|
boxParameters.put("style", styleStr.toString()); |
189 |
|
} |
190 |
|
|
191 |
2
|
return boxParameters; |
192 |
|
} |
193 |
|
|
|
|
| 70% |
Uncovered Elements: 6 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
194 |
2
|
private void appendIcon(StringBuffer result, RadeoxMacroParameters parameters, FilterContext filterContext)... |
195 |
|
{ |
196 |
2
|
RadeoxMacroParameter document = parameters.get("document"); |
197 |
2
|
RadeoxMacroParameter icon = parameters.get("icon"); |
198 |
2
|
boolean hasIcon = false; |
199 |
|
|
200 |
2
|
if (document != null && document.getValue().contains("=")) { |
201 |
0
|
document = null; |
202 |
|
} |
203 |
|
|
204 |
2
|
if (icon != null) { |
205 |
2
|
hasIcon = true; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
2
|
if (hasIcon) { |
210 |
2
|
result.append(filterContext.addProtectedContent("image:", true)); |
211 |
2
|
if (document != null) { |
212 |
2
|
result.append(document + "@" + icon); |
213 |
|
} else { |
214 |
0
|
result.append(icon.getValue().trim()); |
215 |
|
} |
216 |
|
} |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
2
|
@Override... |
220 |
|
public boolean protectResult() |
221 |
|
{ |
222 |
2
|
return false; |
223 |
|
} |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
225 |
6
|
public boolean supportContent()... |
226 |
|
{ |
227 |
6
|
return true; |
228 |
|
} |
229 |
|
} |