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.converter; |
21 |
|
|
22 |
|
import java.io.Reader; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Provider; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.rendering.block.XDOM; |
33 |
|
import org.xwiki.rendering.converter.ConversionException; |
34 |
|
import org.xwiki.rendering.converter.Converter; |
35 |
|
import org.xwiki.rendering.parser.ParseException; |
36 |
|
import org.xwiki.rendering.parser.Parser; |
37 |
|
import org.xwiki.rendering.renderer.BlockRenderer; |
38 |
|
import org.xwiki.rendering.renderer.printer.WikiPrinter; |
39 |
|
import org.xwiki.rendering.syntax.Syntax; |
40 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
41 |
|
import org.xwiki.rendering.transformation.TransformationException; |
42 |
|
import org.xwiki.rendering.transformation.TransformationManager; |
43 |
|
|
44 |
|
|
45 |
|
@link |
46 |
|
|
47 |
|
@version |
48 |
|
|
49 |
|
@Component |
50 |
|
@Singleton |
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 5 |
Complexity Density: 0.31 |
|
51 |
|
public class DefaultConverter implements Converter |
52 |
|
{ |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@Inject |
57 |
|
@Named("context") |
58 |
|
private Provider<ComponentManager> componentManagerProvider; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@Inject |
64 |
|
private TransformationManager transformationManager; |
65 |
|
|
|
|
| 75% |
Uncovered Elements: 4 (16) |
Complexity: 5 |
Complexity Density: 0.31 |
|
66 |
10 |
@Override... |
67 |
|
public void convert(Reader source, Syntax sourceSyntax, Syntax targetSyntax, WikiPrinter printer) |
68 |
|
throws ConversionException |
69 |
|
{ |
70 |
|
|
71 |
10 |
XDOM xdom; |
72 |
10 |
try { |
73 |
10 |
Parser parser = this.componentManagerProvider.get().getInstance(Parser.class, sourceSyntax.toIdString()); |
74 |
10 |
xdom = parser.parse(source); |
75 |
|
} catch (ComponentLookupException e) { |
76 |
0 |
throw new ConversionException("Failed to locate Parser for syntax [" + sourceSyntax + "]", e); |
77 |
|
} catch (ParseException e) { |
78 |
0 |
throw new ConversionException("Failed to parse input source", e); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
10 |
try { |
83 |
10 |
TransformationContext context = new TransformationContext(xdom, sourceSyntax); |
84 |
10 |
context.setTargetSyntax(targetSyntax); |
85 |
10 |
this.transformationManager.performTransformations(xdom, context); |
86 |
|
} catch (TransformationException e) { |
87 |
0 |
throw new ConversionException("Failed to execute some transformations", e); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
10 |
BlockRenderer renderer; |
92 |
10 |
try { |
93 |
10 |
renderer = this.componentManagerProvider.get().getInstance(BlockRenderer.class, targetSyntax.toIdString()); |
94 |
|
} catch (ComponentLookupException e) { |
95 |
0 |
throw new ConversionException("Failed to locate Renderer for syntax [" + targetSyntax + "]", e); |
96 |
|
} |
97 |
10 |
renderer.render(xdom, printer); |
98 |
|
} |
99 |
|
} |