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.block; |
21 |
|
|
22 |
|
import java.lang.reflect.Type; |
23 |
|
|
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.properties.converter.AbstractConverter; |
28 |
|
import org.xwiki.properties.converter.ConversionException; |
29 |
|
import org.xwiki.rendering.block.Block; |
30 |
|
import org.xwiki.rendering.block.match.BlockMatcher; |
31 |
|
import org.xwiki.rendering.block.match.ClassBlockMatcher; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
39 |
|
@Component |
40 |
|
@Singleton |
|
|
| 85.7% |
Uncovered Elements: 4 (28) |
Complexity: 8 |
Complexity Density: 0.5 |
|
41 |
|
public class BlockMatcherConverter extends AbstractConverter<BlockMatcher> |
42 |
|
{ |
43 |
|
|
|
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
44 |
6 |
@Override... |
45 |
|
protected BlockMatcher convertToType(Type targetType, Object value) |
46 |
|
{ |
47 |
6 |
if (value == null) { |
48 |
0 |
return null; |
49 |
|
} |
50 |
6 |
String matcherName = value.toString().trim(); |
51 |
|
|
52 |
6 |
BlockMatcher matcher = null; |
53 |
6 |
if (matcherName.startsWith("class:")) { |
54 |
5 |
String blockClassName = matcherName.substring(6); |
55 |
5 |
if (blockClassName.indexOf('.') == -1) { |
56 |
2 |
blockClassName = "org.xwiki.rendering.block." + blockClassName; |
57 |
|
} |
58 |
5 |
try { |
59 |
5 |
Class<?> blockClass = Class.forName(blockClassName); |
60 |
3 |
if (Block.class.isAssignableFrom(blockClass)) { |
61 |
2 |
matcher = new ClassBlockMatcher((Class<Block>) blockClass); |
62 |
|
} |
63 |
|
} catch (ClassNotFoundException c) { |
64 |
|
|
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
6 |
if (matcher == null) { |
70 |
4 |
throw new ConversionException(String.format("Unknown BlockMatcher [%s]", matcherName)); |
71 |
|
} |
72 |
2 |
return matcher; |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
@Override... |
76 |
|
protected String convertToString(BlockMatcher value) |
77 |
|
{ |
78 |
0 |
throw new ConversionException("not implemented yet"); |
79 |
|
} |
80 |
|
} |