use of org.eclipse.smarthome.core.items.ItemNotFoundException in project smarthome by eclipse.
the class ChartRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Chart chart = (Chart) w;
try {
String itemParam = null;
Item item = itemUIRegistry.getItem(chart.getItem());
if (item instanceof GroupItem) {
itemParam = "groups=" + chart.getItem();
} else {
itemParam = "items=" + chart.getItem();
}
String chartUrl = "/chart?" + itemParam + "&period=" + chart.getPeriod();
if (chart.getService() != null) {
chartUrl += "&service=" + chart.getService();
}
// if legend parameter is given, add corresponding GET parameter
if (chart.getLegend() != null) {
if (chart.getLegend()) {
chartUrl += "&legend=true";
} else {
chartUrl += "&legend=false";
}
}
// add theme GET parameter
String chartTheme = null;
switch(config.getTheme()) {
case WebAppConfig.THEME_NAME_DEFAULT:
chartTheme = "bright";
break;
case WebAppConfig.THEME_NAME_DARK:
chartTheme = "dark";
break;
}
if (chartTheme != null) {
chartUrl += "&theme=" + chartTheme;
}
String url;
boolean ignoreRefresh;
if (!itemUIRegistry.getVisiblity(w)) {
url = URL_NONE_ICON;
ignoreRefresh = true;
} else {
// add timestamp to circumvent browser cache
url = chartUrl + "&t=" + (new Date()).getTime();
ignoreRefresh = false;
}
String snippet = getSnippet("chart");
snippet = preprocessSnippet(snippet, w);
if (chart.getRefresh() > 0) {
snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(chart.getRefresh()));
} else {
snippet = StringUtils.replace(snippet, "%update_interval%", "0");
}
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%proxied_url%", chartUrl);
snippet = StringUtils.replace(snippet, "%valid_url%", "true");
snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false");
snippet = StringUtils.replace(snippet, "%url%", url);
sb.append(snippet);
} catch (ItemNotFoundException e) {
logger.warn("Chart cannot be rendered as item '{}' does not exist.", chart.getItem());
}
return null;
}
Aggregations