1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.icon.internal; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.Reader; |
24 |
|
import java.io.StringReader; |
25 |
|
import java.util.Properties; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
31 |
|
import org.xwiki.bridge.DocumentModelBridge; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.icon.Icon; |
34 |
|
import org.xwiki.icon.IconException; |
35 |
|
import org.xwiki.icon.IconSet; |
36 |
|
import org.xwiki.icon.IconSetLoader; |
37 |
|
import org.xwiki.icon.IconType; |
38 |
|
import org.xwiki.model.reference.DocumentReference; |
39 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@since |
45 |
|
@version |
46 |
|
|
47 |
|
@Component |
48 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (44) |
Complexity: 10 |
Complexity Density: 0.33 |
|
49 |
|
public class DefaultIconSetLoader implements IconSetLoader |
50 |
|
{ |
51 |
|
private static final String CSS_PROPERTY_NAME = "xwiki.iconset.css"; |
52 |
|
|
53 |
|
private static final String SSX_PROPERTY_NAME = "xwiki.iconset.ssx"; |
54 |
|
|
55 |
|
private static final String JSX_PROPERTY_NAME = "xwiki.iconset.jsx"; |
56 |
|
|
57 |
|
private static final String RENDER_WIKI_PROPERTY_NAME = "xwiki.iconset.render.wiki"; |
58 |
|
|
59 |
|
private static final String RENDER_HTML_PROPERTY_NAME = "xwiki.iconset.render.html"; |
60 |
|
|
61 |
|
private static final String ICON_TYPE_PROPERTY_NAME = "xwiki.iconset.type"; |
62 |
|
|
63 |
|
private static final String ERROR_MSG = "Failed to load the IconSet [%s]."; |
64 |
|
|
65 |
|
@Inject |
66 |
|
private DocumentAccessBridge documentAccessBridge; |
67 |
|
|
68 |
|
@Inject |
69 |
|
private WikiDescriptorManager wikiDescriptorManager; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
71 |
4 |
@Override... |
72 |
|
public IconSet loadIconSet(DocumentReference iconSetReference) throws IconException |
73 |
|
{ |
74 |
4 |
try { |
75 |
|
|
76 |
4 |
DocumentModelBridge doc = documentAccessBridge.getDocument(iconSetReference); |
77 |
3 |
String content = doc.getContent(); |
78 |
|
|
79 |
3 |
DocumentReference iconClassRef = new DocumentReference(wikiDescriptorManager.getCurrentWikiId(), |
80 |
|
"IconThemesCode", "IconThemeClass"); |
81 |
3 |
String name = (String) documentAccessBridge.getProperty(iconSetReference, iconClassRef, "name"); |
82 |
|
|
83 |
3 |
return loadIconSet(new StringReader(content), name); |
84 |
|
} catch (Exception e) { |
85 |
1 |
throw new IconException(String.format(ERROR_MSG, iconSetReference), e); |
86 |
|
} |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 8 |
Complexity Density: 0.35 |
|
89 |
33 |
@Override... |
90 |
|
public IconSet loadIconSet(Reader input, String name) throws IconException |
91 |
|
{ |
92 |
33 |
try { |
93 |
33 |
IconSet iconSet = new IconSet(name); |
94 |
|
|
95 |
33 |
Properties properties = new Properties(); |
96 |
33 |
properties.load(input); |
97 |
|
|
98 |
|
|
99 |
32 |
for (String key : properties.stringPropertyNames()) { |
100 |
32009 |
String value = properties.getProperty(key); |
101 |
32009 |
if (key.equals(CSS_PROPERTY_NAME)) { |
102 |
2 |
iconSet.setCss(value); |
103 |
32007 |
} else if (key.equals(SSX_PROPERTY_NAME)) { |
104 |
3 |
iconSet.setSsx(value); |
105 |
32004 |
} else if (key.equals(JSX_PROPERTY_NAME)) { |
106 |
3 |
iconSet.setJsx(value); |
107 |
32001 |
} else if (key.equals(RENDER_WIKI_PROPERTY_NAME)) { |
108 |
32 |
iconSet.setRenderWiki(value); |
109 |
31969 |
} else if (key.equals(RENDER_HTML_PROPERTY_NAME)) { |
110 |
32 |
iconSet.setRenderHTML(value); |
111 |
31937 |
} else if (key.equals(ICON_TYPE_PROPERTY_NAME)) { |
112 |
32 |
iconSet.setType(IconType.valueOf(value.toUpperCase())); |
113 |
|
} else { |
114 |
31905 |
Icon icon = new Icon(); |
115 |
31905 |
icon.setValue(properties.getProperty(key)); |
116 |
31905 |
iconSet.addIcon(key, icon); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
32 |
return iconSet; |
122 |
|
} catch (IOException e) { |
123 |
1 |
throw new IconException(String.format(ERROR_MSG, name), e); |
124 |
|
} |
125 |
|
} |
126 |
|
} |