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.linkchecker; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.List; |
25 |
|
import java.util.regex.Pattern; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
import org.xwiki.component.manager.ComponentLookupException; |
32 |
|
import org.xwiki.component.manager.ComponentManager; |
33 |
|
import org.xwiki.component.phase.Initializable; |
34 |
|
import org.xwiki.component.phase.InitializationException; |
35 |
|
import org.xwiki.configuration.ConfigurationSource; |
36 |
|
import org.xwiki.configuration.internal.MemoryConfigurationSource; |
37 |
|
import org.xwiki.rendering.transformation.linkchecker.LinkCheckerTransformationConfiguration; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Singleton |
|
|
| 85.2% |
Uncovered Elements: 4 (27) |
Complexity: 8 |
Complexity Density: 0.44 |
|
47 |
|
public class DefaultLinkCheckerTransformationConfiguration implements LinkCheckerTransformationConfiguration, |
48 |
|
Initializable |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private static final String PREFIX = "rendering.transformation.linkchecker."; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
private static final long TIMEOUT = 3600000L; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private Long checkTimeout; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@Inject |
70 |
|
private ComponentManager componentManager; |
71 |
|
|
72 |
|
private ConfigurationSource configurationSource; |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
74 |
8 |
@Override... |
75 |
|
public void initialize() throws InitializationException |
76 |
|
{ |
77 |
8 |
try { |
78 |
8 |
this.configurationSource = this.componentManager.getInstance(ConfigurationSource.class); |
79 |
|
} catch (ComponentLookupException e) { |
80 |
7 |
this.configurationSource = new MemoryConfigurationSource(); |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
84 |
64 |
@Override... |
85 |
|
public long getCheckTimeout() |
86 |
|
{ |
87 |
64 |
long result; |
88 |
|
|
89 |
64 |
if (this.checkTimeout != null) { |
90 |
3 |
result = this.checkTimeout; |
91 |
|
} else { |
92 |
61 |
result = this.configurationSource.getProperty(PREFIX + "timeout", TIMEOUT); |
93 |
|
} |
94 |
|
|
95 |
63 |
return result; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
@param |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
1 |
@Override... |
102 |
|
public void setCheckTimeout(long checkTimeout) |
103 |
|
{ |
104 |
1 |
this.checkTimeout = checkTimeout; |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
@return |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
12 |
protected List<Pattern> getDefaultExcludedReferencePatterns()... |
113 |
|
{ |
114 |
12 |
return Collections.emptyList(); |
115 |
|
} |
116 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
117 |
64 |
@Override... |
118 |
|
public List<Pattern> getExcludedReferencePatterns() |
119 |
|
{ |
120 |
64 |
List<Pattern> patterns; |
121 |
|
|
122 |
64 |
List<String> patternsAsString = |
123 |
|
this.configurationSource.getProperty(PREFIX + "excludedReferencePatterns", List.class); |
124 |
64 |
if (patternsAsString.isEmpty()) { |
125 |
64 |
patterns = getDefaultExcludedReferencePatterns(); |
126 |
|
} else { |
127 |
0 |
patterns = new ArrayList<Pattern>(); |
128 |
0 |
for (String patternAsString : patternsAsString) { |
129 |
0 |
patterns.add(Pattern.compile(patternAsString)); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
64 |
return patterns; |
134 |
|
} |
135 |
|
} |