use of org.eclipse.smarthome.ui.basic.render.RenderException in project smarthome by eclipse.
the class AbstractWidgetRenderer method getSnippet.
/**
* This method provides the html snippet for a given elementType of the sitemap model.
*
* @param elementType the name of the model type (e.g. "Group" or "Switch")
* @return the html snippet to be used in the UI (including placeholders for variables)
* @throws RenderException if snippet could not be read
*/
protected synchronized String getSnippet(String elementType) throws RenderException {
String lowerTypeElementType = elementType.toLowerCase();
String snippet = SNIPPET_CACHE.get(lowerTypeElementType);
if (snippet == null) {
String snippetLocation = SNIPPET_LOCATION + lowerTypeElementType + SNIPPET_EXT;
URL entry = WebAppActivator.getContext().getBundle().getEntry(snippetLocation);
if (entry != null) {
try {
snippet = IOUtils.toString(entry.openStream());
SNIPPET_CACHE.put(lowerTypeElementType, snippet);
} catch (IOException e) {
logger.warn("Cannot load snippet for element type '{}'", lowerTypeElementType, e);
}
} else {
throw new RenderException("Cannot find a snippet for element type '" + lowerTypeElementType + "'");
}
}
return snippet;
}
use of org.eclipse.smarthome.ui.basic.render.RenderException in project smarthome by eclipse.
the class WebAppServlet method service.
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
logger.debug("Servlet request received!");
// read request parameters
String sitemapName = req.getParameter("sitemap");
String widgetId = req.getParameter("w");
String subscriptionId = req.getParameter("subscriptionId");
boolean async = "true".equalsIgnoreCase(req.getParameter("__async"));
if (sitemapName == null) {
sitemapName = config.getDefaultSitemap();
}
StringBuilder result = new StringBuilder();
Sitemap sitemap = null;
for (SitemapProvider sitemapProvider : sitemapProviders) {
sitemap = sitemapProvider.getSitemap(sitemapName);
if (sitemap != null) {
break;
}
}
try {
if (sitemap == null) {
showSitemapList(res);
return;
}
logger.debug("reading sitemap {}", sitemap.getName());
if (widgetId == null || widgetId.isEmpty() || widgetId.equals(sitemapName)) {
// we are at the homepage, so we render the children of the sitemap root node
if (subscriptionId != null) {
if (subscriptions.exists(subscriptionId)) {
subscriptions.setPageId(subscriptionId, sitemap.getName(), sitemapName);
} else {
logger.debug("Basic UI requested a non-existing event subscription id ({})", subscriptionId);
}
}
String label = sitemap.getLabel() != null ? sitemap.getLabel() : sitemapName;
EList<Widget> children = renderer.getItemUIRegistry().getChildren(sitemap);
result.append(renderer.processPage(sitemapName, sitemapName, label, children, async));
} else if (!widgetId.equals("Colorpicker")) {
// we are on some subpage, so we have to render the children of the widget that has been selected
if (subscriptionId != null) {
if (subscriptions.exists(subscriptionId)) {
subscriptions.setPageId(subscriptionId, sitemap.getName(), widgetId);
} else {
logger.debug("Basic UI requested a non-existing event subscription id ({})", subscriptionId);
}
}
Widget w = renderer.getItemUIRegistry().getWidget(sitemap, widgetId);
if (w != null) {
String label = renderer.getItemUIRegistry().getLabel(w);
if (label == null) {
label = "undefined";
}
if (!(w instanceof LinkableWidget)) {
throw new RenderException("Widget '" + w + "' can not have any content");
}
EList<Widget> children = renderer.getItemUIRegistry().getChildren((LinkableWidget) w);
result.append(renderer.processPage(renderer.getItemUIRegistry().getWidgetId(w), sitemapName, label, children, async));
}
}
} catch (RenderException e) {
throw new ServletException(e.getMessage(), e);
}
if (async) {
res.setContentType(CONTENT_TYPE_ASYNC);
} else {
res.setContentType(CONTENT_TYPE);
}
res.getWriter().append(result);
res.getWriter().close();
}
Aggregations