1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss.internal.colortheme; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.lesscss.compiler.LESSCompilerException; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
30 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
31 |
|
import org.xwiki.model.reference.WikiReference; |
32 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
33 |
|
|
34 |
|
import com.xpn.xwiki.XWiki; |
35 |
|
import com.xpn.xwiki.XWikiContext; |
36 |
|
import com.xpn.xwiki.XWikiException; |
37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@since |
43 |
|
@version |
44 |
|
|
45 |
|
@Component |
46 |
|
@Singleton |
|
|
| 95.8% |
Uncovered Elements: 1 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
47 |
|
public class DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory |
48 |
|
{ |
49 |
|
@Inject |
50 |
|
private Provider<XWikiContext> xcontextProvider; |
51 |
|
|
52 |
|
@Inject |
53 |
|
private DocumentReferenceResolver<String> documentReferenceResolver; |
54 |
|
|
55 |
|
@Inject |
56 |
|
private WikiDescriptorManager wikiDescriptorManager; |
57 |
|
|
58 |
|
@Inject |
59 |
|
private EntityReferenceSerializer<String> entityReferenceSerializer; |
60 |
|
|
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
61 |
2165 |
@Override... |
62 |
|
public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException |
63 |
|
{ |
64 |
|
|
65 |
2165 |
XWikiContext xcontext = xcontextProvider.get(); |
66 |
2166 |
XWiki xwiki = xcontext.getWiki(); |
67 |
|
|
68 |
2166 |
String currentWikiId = wikiDescriptorManager.getCurrentWikiId(); |
69 |
|
|
70 |
2166 |
DocumentReference colorThemeDocRef = |
71 |
|
documentReferenceResolver.resolve(colorThemeName, new WikiReference(currentWikiId)); |
72 |
|
|
73 |
2166 |
if (xwiki.exists(colorThemeDocRef, xcontext)) { |
74 |
238 |
try { |
75 |
238 |
XWikiDocument colorThemeDoc = xwiki.getDocument(colorThemeDocRef, xcontext); |
76 |
|
|
77 |
|
|
78 |
238 |
DocumentReference colorThemeClassRef = |
79 |
|
new DocumentReference(colorThemeDocRef.getWikiReference().getName(), |
80 |
|
"ColorThemes", "ColorThemeClass"); |
81 |
238 |
if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { |
82 |
1 |
return createReference(colorThemeDocRef); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
237 |
DocumentReference flamingoThemeClassRef = |
87 |
|
new DocumentReference(colorThemeDocRef.getWikiReference().getName(), |
88 |
|
"FlamingoThemesCode", "ThemeClass"); |
89 |
237 |
if (colorThemeDoc.getXObjectSize(flamingoThemeClassRef) > 0) { |
90 |
25 |
return createReference(colorThemeDocRef); |
91 |
|
} |
92 |
|
|
93 |
|
} catch (XWikiException e) { |
94 |
0 |
throw new LESSCompilerException(String.format("Unable to read document [%s]", colorThemeDocRef)); |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
2140 |
return new NamedColorThemeReference(colorThemeName); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
32 |
@Override... |
103 |
|
public ColorThemeReference createReference(DocumentReference documentReference) |
104 |
|
{ |
105 |
32 |
return new DocumentColorThemeReference(documentReference, entityReferenceSerializer); |
106 |
|
} |
107 |
|
} |