1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.url.internal.standard; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
|
24 |
|
import org.xwiki.context.Execution; |
25 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
26 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
27 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
@version |
33 |
|
@since |
34 |
|
|
|
|
| 93.1% |
Uncovered Elements: 2 (29) |
Complexity: 11 |
Complexity Density: 0.65 |
|
35 |
|
public abstract class AbstractWikiReferenceExtractor implements WikiReferenceExtractor |
36 |
|
{ |
37 |
|
@Inject |
38 |
|
private StandardURLConfiguration configuration; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@Inject |
44 |
|
private WikiDescriptorManager wikiDescriptorManager; |
45 |
|
|
46 |
|
@Inject |
47 |
|
private Execution execution; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
53 |
75 |
protected String normalizeWikiIdForNonExistentWikiDescriptor(String alias)... |
54 |
|
{ |
55 |
74 |
String normalizedWikiId = alias; |
56 |
73 |
String mainWiki = getMainWikiId(); |
57 |
76 |
if (!mainWiki.equals(normalizedWikiId) |
58 |
|
&& this.configuration.getWikiNotFoundBehavior() == WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI) |
59 |
|
{ |
60 |
70 |
if (getWikiDescriptorById(normalizedWikiId) == null) { |
61 |
|
|
62 |
68 |
normalizedWikiId = mainWiki; |
63 |
|
} |
64 |
|
} |
65 |
75 |
return normalizedWikiId; |
66 |
|
} |
67 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
68 |
21118 |
protected WikiDescriptor getWikiDescriptorByAlias(String alias)... |
69 |
|
{ |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
21113 |
if (this.execution.getContext() == null) { |
74 |
9480 |
return null; |
75 |
|
} |
76 |
|
|
77 |
11603 |
try { |
78 |
11602 |
return this.wikiDescriptorManager.getByAlias(alias); |
79 |
|
} catch (WikiManagerException e) { |
80 |
0 |
throw new RuntimeException(String.format("Failed to locate wiki descriptor for alias [%s]", alias), e); |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
84 |
69 |
protected WikiDescriptor getWikiDescriptorById(String wikiId)... |
85 |
|
{ |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
70 |
if (this.execution.getContext() == null) { |
90 |
65 |
return null; |
91 |
|
} |
92 |
|
|
93 |
5 |
try { |
94 |
5 |
return this.wikiDescriptorManager.getById(wikiId); |
95 |
|
} catch (WikiManagerException e) { |
96 |
0 |
throw new RuntimeException(String.format("Failed to locate wiki descriptor for wiki [%s]", wikiId), e); |
97 |
|
} |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
9493 |
protected String getMainWikiId()... |
101 |
|
{ |
102 |
9505 |
return this.wikiDescriptorManager.getMainWikiId(); |
103 |
|
} |
104 |
|
} |