Skip to content

Commit a05170b

Browse files
committed
XWIKI-23549: Support several CSS files in icon themes
* Allow several, comma-separated CSS files
1 parent 1962b9c commit a05170b

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/main/java/org/xwiki/icon/internal/DefaultIconRenderer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,14 @@ private void activeCSS(IconSet iconSet) throws IconException
115115
{
116116
String url = this.iconTemplateRendererManager.getRenderer(iconSet.getCss())
117117
.render(null, iconSet.getSourceDocumentReference());
118-
Map<String, Object> parameters = new HashMap<>();
119-
parameters.put("rel", "stylesheet");
120-
this.linkExtension.use(url, parameters);
118+
// Split URL at "," to support multiple CSS files.
119+
// Commas in URLs are not that common, and if needed they can be encoded as %2C.
120+
String[] urls = StringUtils.split(url, ',');
121+
for (String cssUrl : urls) {
122+
Map<String, Object> parameters = new HashMap<>();
123+
parameters.put("rel", "stylesheet");
124+
this.linkExtension.use(cssUrl, parameters);
125+
}
121126
}
122127

123128
private void activeSSX(IconSet iconSet)

xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/test/java/org/xwiki/icon/internal/DefaultIconRendererTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,35 @@ void renderWithCSS() throws Exception
122122
verify(this.jsExtension, never()).use(any());
123123
}
124124

125+
@Test
126+
void renderWithMultipleCSS() throws Exception
127+
{
128+
IconSet iconSet = new IconSet("default");
129+
String template = "image:$icon.png";
130+
iconSet.setRenderWiki(template);
131+
String css = "css1,css2";
132+
iconSet.setCss(css);
133+
iconSet.addIcon("test", new Icon("blabla"));
134+
135+
IconTemplateRenderer mockRenderer = mock();
136+
when(this.rendererManager.getRenderer(css)).thenReturn(mockRenderer);
137+
String parsedCSS = "velocityParsedCSS1,velocityParsedCSS2";
138+
when(mockRenderer.render(null, null)).thenReturn(parsedCSS);
139+
140+
setupSimpleTemplate(template);
141+
142+
// Test
143+
this.iconRenderer.render("test", iconSet);
144+
145+
// Verify
146+
Map<String, Object> parameters = new HashMap<>();
147+
parameters.put("rel", "stylesheet");
148+
verify(this.linkExtension).use("velocityParsedCSS1", parameters);
149+
verify(this.linkExtension).use("velocityParsedCSS2", parameters);
150+
verify(this.skinExtension, never()).use(any());
151+
verify(this.jsExtension, never()).use(any());
152+
}
153+
125154
@Test
126155
void renderWithSSX() throws Exception
127156
{

0 commit comments

Comments
 (0)