Search in sources :

Example 6 with Icon

use of org.xwiki.icon.Icon in project xwiki-platform by xwiki.

the class DefaultIconRendererTest method renderHTMLWithJSX.

@Test
public void renderHTMLWithJSX() throws Exception {
    IconSet iconSet = new IconSet("default");
    iconSet.setJsx("jsx");
    iconSet.addIcon("test", new Icon("blabla"));
    // Test
    mocker.getComponentUnderTest().renderHTML("test", iconSet);
    // Verify
    verify(jsExtension).use("jsx");
    verify(linkExtension, never()).use(any());
    verify(skinExtension, never()).use(any());
}
Also used : Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 7 with Icon

use of org.xwiki.icon.Icon 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);
    }
}
Also used : Icon(org.xwiki.icon.Icon) IOException(java.io.IOException) Properties(java.util.Properties) IconSet(org.xwiki.icon.IconSet) IconException(org.xwiki.icon.IconException)

Example 8 with Icon

use of org.xwiki.icon.Icon in project xwiki-platform by xwiki.

the class DefaultIconRenderer method renderIcon.

private String renderIcon(IconSet iconSet, String iconName, String renderer) throws IconException {
    // Get the icon
    Icon icon = iconSet.getIcon(iconName);
    // The icon may not exist
    if (icon == null) {
        // return an empty string. Idea: fallback on a different icon instead?
        return "";
    }
    // Interpret the velocity command
    StringWriter contentToParse = new StringWriter();
    contentToParse.write("#set($icon = \"");
    contentToParse.write(icon.getValue());
    contentToParse.write("\")\n");
    contentToParse.write(renderer);
    return velocityRenderer.render(contentToParse.toString());
}
Also used : StringWriter(java.io.StringWriter) Icon(org.xwiki.icon.Icon)

Example 9 with Icon

use of org.xwiki.icon.Icon 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);
}
Also used : Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Example 10 with Icon

use of org.xwiki.icon.Icon in project xwiki-platform by xwiki.

the class DefaultIconRendererTest method renderWithSSX.

@Test
public void renderWithSSX() throws Exception {
    IconSet iconSet = new IconSet("default");
    iconSet.setSsx("ssx");
    iconSet.addIcon("test", new Icon("blabla"));
    // Test
    mocker.getComponentUnderTest().render("test", iconSet);
    // Verify
    verify(skinExtension).use("ssx");
    verify(linkExtension, never()).use(any());
    verify(jsExtension, never()).use(any());
}
Also used : Icon(org.xwiki.icon.Icon) IconSet(org.xwiki.icon.IconSet) Test(org.junit.Test)

Aggregations

Icon (org.xwiki.icon.Icon)15 IconSet (org.xwiki.icon.IconSet)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)2 IconException (org.xwiki.icon.IconException)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Properties (java.util.Properties)1