use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.
the class DefaultIconSetLoader method loadIconSet.
@Override
public IconSet loadIconSet(Reader input, String name) throws IconException {
try {
IconSet iconSet = new IconSet(name);
Properties properties = new Properties();
properties.load(input);
// Load all the keys
for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
if (key.equals(CSS_PROPERTY_NAME)) {
iconSet.setCss(value);
} else if (key.equals(SSX_PROPERTY_NAME)) {
iconSet.setSsx(value);
} else if (key.equals(JSX_PROPERTY_NAME)) {
iconSet.setJsx(value);
} else if (key.equals(RENDER_WIKI_PROPERTY_NAME)) {
iconSet.setRenderWiki(value);
} else if (key.equals(RENDER_HTML_PROPERTY_NAME)) {
iconSet.setRenderHTML(value);
} else if (key.equals(ICON_TYPE_PROPERTY_NAME)) {
iconSet.setType(IconType.valueOf(value.toUpperCase()));
} else {
Icon icon = new Icon();
icon.setValue(properties.getProperty(key));
iconSet.addIcon(key, icon);
}
}
// return
return iconSet;
} catch (IOException e) {
throw new IconException(String.format(ERROR_MSG, name), e);
}
}
use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.
the class DefaultIconSetManager method getIconSet.
@Override
public IconSet getIconSet(String name) throws IconException {
// Special case: the default icon theme
if (DEFAULT_ICONSET_NAME.equals(name)) {
return getDefaultIconSet();
}
// Get the icon set from the cache
IconSet iconSet = iconSetCache.get(name, wikiDescriptorManager.getCurrentWikiId());
// Load it if it is not loaded yet
if (iconSet == null) {
try {
// Search by name
String xwql = "FROM doc.object(IconThemesCode.IconThemeClass) obj WHERE obj.name = :name";
Query query = queryManager.createQuery(xwql, Query.XWQL);
query.bindValue("name", name);
List<String> results = query.execute();
if (results.isEmpty()) {
return null;
}
// Get the first result
String docName = results.get(0);
DocumentReference docRef = documentReferenceResolver.resolve(docName);
// Load the icon theme
iconSet = iconSetLoader.loadIconSet(docRef);
// Put it in the cache
iconSetCache.put(docRef, iconSet);
iconSetCache.put(name, wikiDescriptorManager.getCurrentWikiId(), iconSet);
} catch (QueryException e) {
throw new IconException(String.format("Failed to load the icon set [%s].", name), e);
}
}
// Return the icon set
return iconSet;
}
use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.
the class DefaultIconSetManager method getCurrentIconSet.
@Override
public IconSet getCurrentIconSet() throws IconException {
// Get the current icon theme
String iconTheme = configurationSource.getProperty("iconTheme");
// Get the icon set
IconSet iconSet = null;
DocumentReference iconThemeDocRef = documentReferenceResolver.resolve(iconTheme);
if (!StringUtils.isBlank(iconTheme) && documentAccessBridge.exists(iconThemeDocRef)) {
iconSet = iconSetCache.get(iconThemeDocRef);
if (iconSet == null) {
// lazy loading
iconSet = iconSetLoader.loadIconSet(iconThemeDocRef);
iconSetCache.put(iconThemeDocRef, iconSet);
iconSetCache.put(iconSet.getName(), wikiDescriptorManager.getCurrentWikiId(), iconSet);
}
}
return iconSet;
}
use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.
the class DefaultIconManagerTest method renderHTML.
@Test
public void renderHTML() throws Exception {
IconSet iconSet = new IconSet("silk");
iconSet.addIcon("test", new Icon("hello"));
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet);
when(iconRenderer.renderHTML("test", iconSet)).thenReturn("rendered icon");
// Test
String result = mocker.getComponentUnderTest().renderHTML("test");
assertEquals("rendered icon", result);
}
use of org.xwiki.icon.IconSet in project xwiki-platform by xwiki.
the class DefaultIconManagerTest method renderWithFallBack.
@Test
public void renderWithFallBack() throws Exception {
IconSet iconSet = new IconSet("silk");
when(iconSetManager.getCurrentIconSet()).thenReturn(iconSet);
IconSet defaultIconSet = new IconSet("default");
when(iconSetManager.getDefaultIconSet()).thenReturn(defaultIconSet);
when(iconRenderer.render("test", defaultIconSet)).thenReturn("rendered icon");
// Test
String result = mocker.getComponentUnderTest().render("test");
assertEquals("rendered icon", result);
}
Aggregations