1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.localization.internal.message; |
21 |
|
|
22 |
|
import java.io.StringReader; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Locale; |
26 |
|
|
27 |
|
import org.xwiki.localization.TranslationBundle; |
28 |
|
import org.xwiki.localization.message.TranslationMessageElement; |
29 |
|
import org.xwiki.rendering.block.Block; |
30 |
|
import org.xwiki.rendering.block.CompositeBlock; |
31 |
|
import org.xwiki.rendering.block.XDOM; |
32 |
|
import org.xwiki.rendering.parser.ParseException; |
33 |
|
import org.xwiki.rendering.parser.Parser; |
34 |
|
import org.xwiki.rendering.util.ParserUtils; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 7 |
Complexity Density: 0.37 |
|
42 |
|
public class ParameterTranslationMessageElement implements TranslationMessageElement |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
private static final ParserUtils PARSERUTILS = new ParserUtils(); |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private int index; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private Parser plainParser; |
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
@param |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
63 |
0 |
public ParameterTranslationMessageElement(int index, Parser plainParser)... |
64 |
|
{ |
65 |
0 |
this.index = index; |
66 |
0 |
this.plainParser = plainParser; |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 6 |
Complexity Density: 0.35 |
|
69 |
0 |
@Override... |
70 |
|
public Block render(Locale locale, Collection<TranslationBundle> bundles, Object... parameters) |
71 |
|
{ |
72 |
0 |
Object parameter = parameters[index]; |
73 |
|
|
74 |
0 |
Block block; |
75 |
0 |
if (parameter instanceof Block) { |
76 |
0 |
block = (Block) parameter; |
77 |
0 |
} else if (parameter != null) { |
78 |
0 |
try { |
79 |
0 |
XDOM xdom = this.plainParser.parse(new StringReader(parameter.toString())); |
80 |
|
|
81 |
0 |
List<Block> blocks = xdom.getChildren(); |
82 |
0 |
PARSERUTILS.removeTopLevelParagraph(blocks); |
83 |
0 |
if (blocks.isEmpty()) { |
84 |
0 |
block = null; |
85 |
0 |
} else if (blocks.size() == 1) { |
86 |
0 |
block = blocks.get(0); |
87 |
|
} else { |
88 |
0 |
block = new CompositeBlock(blocks); |
89 |
|
} |
90 |
|
} catch (ParseException e) { |
91 |
|
|
92 |
0 |
block = null; |
93 |
|
} |
94 |
|
} else { |
95 |
0 |
block = null; |
96 |
|
} |
97 |
|
|
98 |
0 |
return block; |
99 |
|
} |
100 |
|
} |