Search in sources :

Example 1 with IconException

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

the class DefaultIconSetManager method getIconSetNames.

@Override
public List<String> getIconSetNames() throws IconException {
    try {
        String xwql = "SELECT obj.name FROM Document doc, doc.object(IconThemesCode.IconThemeClass) obj " + "ORDER BY obj.name";
        Query query = queryManager.createQuery(xwql, Query.XWQL);
        return query.execute();
    } catch (QueryException e) {
        throw new IconException("Failed to get the name of all icon sets.", e);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) IconException(org.xwiki.icon.IconException)

Example 2 with IconException

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

the class DefaultIconSetManager method getDefaultIconSet.

@Override
public IconSet getDefaultIconSet() throws IconException {
    XWikiContext xcontext = xcontextProvider.get();
    XWiki xwiki = xcontext.getWiki();
    IconSet iconSet = iconSetCache.get(DEFAULT_ICONSET_NAME);
    if (iconSet == null) {
        try {
            // lazy loading
            iconSet = iconSetLoader.loadIconSet(new InputStreamReader(xwiki.getResourceAsStream("/resources/icons/default.iconset")), DEFAULT_ICONSET_NAME);
            iconSetCache.put(DEFAULT_ICONSET_NAME, iconSet);
        } catch (IconException | MalformedURLException e) {
            throw new IconException("Failed to get the current default icon set.", e);
        }
    }
    return iconSet;
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) IconSet(org.xwiki.icon.IconSet) IconException(org.xwiki.icon.IconException)

Example 3 with IconException

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

the class DefaultIconSetLoaderTest method loadIconSetFromWikiDocumentWithException.

@Test
public void loadIconSetFromWikiDocumentWithException() throws Exception {
    Exception exception = new Exception("test");
    when(documentAccessBridge.getDocumentInstance(any(DocumentReference.class))).thenThrow(exception);
    // Test
    Exception caughException = null;
    try {
        mocker.getComponentUnderTest().loadIconSet(new DocumentReference("a", "b", "c"));
    } catch (IconException e) {
        caughException = e;
    }
    assertNotNull(caughException);
    assert (caughException instanceof IconException);
    assertEquals(exception, caughException.getCause());
    assertEquals("Failed to load the IconSet [a:b.c].", caughException.getMessage());
}
Also used : IOException(java.io.IOException) IconException(org.xwiki.icon.IconException) DocumentReference(org.xwiki.model.reference.DocumentReference) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Example 4 with IconException

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

the class DefaultIconSetManagerTest method getIconSetWhenException.

@Test
public void getIconSetWhenException() throws Exception {
    // Mocks
    Exception exception = new QueryException("exception in the query", null, null);
    when(queryManager.createQuery(any(), any())).thenThrow(exception);
    // Test
    Exception caughtException = null;
    try {
        mocker.getComponentUnderTest().getIconSet("silk");
    } catch (IconException e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    assertEquals(exception, caughtException.getCause());
    assertEquals("Failed to load the icon set [silk].", caughtException.getMessage());
}
Also used : QueryException(org.xwiki.query.QueryException) QueryException(org.xwiki.query.QueryException) IconException(org.xwiki.icon.IconException) MalformedURLException(java.net.MalformedURLException) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Example 5 with IconException

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

the class VelocityRendererTest method renderWithException.

@Test
public void renderWithException() throws Exception {
    // Mocks
    Exception exception = new XWikiVelocityException("exception");
    when(velocityManager.getVelocityEngine()).thenThrow(exception);
    // Test
    IconException caughtException = null;
    try {
        mocker.getComponentUnderTest().render("myCode");
    } catch (IconException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to render the icon.", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
}
Also used : XWikiVelocityException(org.xwiki.velocity.XWikiVelocityException) XWikiVelocityException(org.xwiki.velocity.XWikiVelocityException) IconException(org.xwiki.icon.IconException) IconException(org.xwiki.icon.IconException) Test(org.junit.Test)

Aggregations

IconException (org.xwiki.icon.IconException)14 Test (org.junit.Test)8 QueryException (org.xwiki.query.QueryException)5 IOException (java.io.IOException)4 IconSet (org.xwiki.icon.IconSet)4 MalformedURLException (java.net.MalformedURLException)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 InputStreamReader (java.io.InputStreamReader)2 VelocityContext (org.apache.velocity.VelocityContext)2 Icon (org.xwiki.icon.Icon)2 Query (org.xwiki.query.Query)2 VelocityEngine (org.xwiki.velocity.VelocityEngine)2 XWikiVelocityException (org.xwiki.velocity.XWikiVelocityException)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Properties (java.util.Properties)1