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.transformation.wikiword; |
21 |
|
|
22 |
|
import java.util.regex.Matcher; |
23 |
|
import java.util.regex.Pattern; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.rendering.block.Block; |
30 |
|
import org.xwiki.rendering.block.LinkBlock; |
31 |
|
import org.xwiki.rendering.block.WordBlock; |
32 |
|
import org.xwiki.rendering.internal.block.ProtectedBlockFilter; |
33 |
|
import org.xwiki.rendering.listener.reference.DocumentResourceReference; |
34 |
|
import org.xwiki.rendering.listener.reference.ResourceReference; |
35 |
|
import org.xwiki.rendering.transformation.AbstractTransformation; |
36 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
37 |
|
import org.xwiki.rendering.transformation.TransformationException; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Named("wikiword") |
47 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.4 |
|
48 |
|
public class WikiWordTransformation extends AbstractTransformation |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private static final Pattern WIKIWORD_PATTERN = Pattern.compile( |
54 |
|
"\\p{javaUpperCase}+\\p{javaLowerCase}+(\\p{javaUpperCase}\\p{javaLowerCase}*)+"); |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private ProtectedBlockFilter filter = new ProtectedBlockFilter(); |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
61 |
2 |
@Override... |
62 |
|
public void transform(Block block, TransformationContext transformationContext) throws TransformationException |
63 |
|
{ |
64 |
|
|
65 |
2 |
for (WordBlock wordBlock : this.filter.getChildrenByType(block, WordBlock.class, true)) { |
66 |
9 |
Matcher matcher = WIKIWORD_PATTERN.matcher(wordBlock.getWord()); |
67 |
9 |
if (matcher.matches()) { |
68 |
3 |
ResourceReference linkReference = new DocumentResourceReference(wordBlock.getWord()); |
69 |
3 |
wordBlock.getParent().replaceChild(new LinkBlock(wordBlock.getChildren(), linkReference, false), |
70 |
|
wordBlock); |
71 |
|
} |
72 |
|
} |
73 |
|
} |
74 |
|
} |