1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.internal.output; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.OutputStream; |
24 |
|
import java.io.Writer; |
25 |
|
import java.lang.reflect.Type; |
26 |
|
|
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.filter.output.DefaultFileOutputTarget; |
31 |
|
import org.xwiki.filter.output.DefaultOutputStreamOutputTarget; |
32 |
|
import org.xwiki.filter.output.DefaultWriterOutputTarget; |
33 |
|
import org.xwiki.filter.output.OutputTarget; |
34 |
|
import org.xwiki.filter.output.StringWriterOutputTarget; |
35 |
|
import org.xwiki.properties.converter.AbstractConverter; |
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
41 |
|
@Component |
42 |
|
@Singleton |
|
|
| 62.5% |
Uncovered Elements: 12 (32) |
Complexity: 8 |
Complexity Density: 0.44 |
|
43 |
|
public class OutputTargetConverter extends AbstractConverter<OutputTarget> |
44 |
|
{ |
|
|
| 56.5% |
Uncovered Elements: 10 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
45 |
1 |
@Override... |
46 |
|
protected <G extends OutputTarget> G convertToType(Type targetType, Object value) |
47 |
|
{ |
48 |
1 |
if (value == null) { |
49 |
0 |
return null; |
50 |
|
} |
51 |
|
|
52 |
1 |
if (value instanceof OutputTarget) { |
53 |
0 |
return (G) value; |
54 |
|
} |
55 |
|
|
56 |
1 |
OutputTarget outputTarget; |
57 |
|
|
58 |
1 |
if (value instanceof OutputStream) { |
59 |
0 |
outputTarget = new DefaultOutputStreamOutputTarget((OutputStream) value); |
60 |
1 |
} else if (value instanceof File) { |
61 |
0 |
outputTarget = new DefaultFileOutputTarget((File) value); |
62 |
1 |
} else if (value instanceof Writer) { |
63 |
0 |
outputTarget = new DefaultWriterOutputTarget((Writer) value); |
64 |
|
} else { |
65 |
1 |
outputTarget = fromString(value.toString()); |
66 |
|
} |
67 |
|
|
68 |
1 |
return (G) outputTarget; |
69 |
|
} |
70 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
71 |
1 |
private OutputTarget fromString(String target)... |
72 |
|
{ |
73 |
1 |
OutputTarget outputTarget; |
74 |
|
|
75 |
|
|
76 |
1 |
if (target.startsWith("file:")) { |
77 |
1 |
outputTarget = new DefaultFileOutputTarget(new File(target.substring("file:".length()))); |
78 |
|
} else { |
79 |
0 |
outputTarget = new StringWriterOutputTarget(); |
80 |
|
} |
81 |
|
|
82 |
1 |
return outputTarget; |
83 |
|
} |
84 |
|
} |