Isn't it possible to use the REST API to get the icon? See https://extensions.xwiki.org/xwiki/bin/view/Extension/Icon%20Theme%20Application#HRESTAPI.