use of org.eclipse.smarthome.model.sitemap.Sitemap in project smarthome by eclipse.
the class SitemapResource method getPageBean.
private PageDTO getPageBean(String sitemapName, String pageId, URI uri, Locale locale, boolean timeout) {
Sitemap sitemap = getSitemap(sitemapName);
if (sitemap != null) {
if (pageId.equals(sitemap.getName())) {
EList<Widget> children = itemUIRegistry.getChildren(sitemap);
return createPageBean(sitemapName, sitemap.getLabel(), sitemap.getIcon(), sitemap.getName(), children, false, isLeaf(children), uri, locale, timeout);
} else {
Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
if (pageWidget instanceof LinkableWidget) {
EList<Widget> children = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
PageDTO pageBean = createPageBean(sitemapName, itemUIRegistry.getLabel(pageWidget), itemUIRegistry.getCategory(pageWidget), pageId, children, false, isLeaf(children), uri, locale, timeout);
EObject parentPage = pageWidget.eContainer();
while (parentPage instanceof Frame) {
parentPage = parentPage.eContainer();
}
if (parentPage instanceof Widget) {
String parentId = itemUIRegistry.getWidgetId((Widget) parentPage);
pageBean.parent = getPageBean(sitemapName, parentId, uri, locale, timeout);
pageBean.parent.widgets = null;
pageBean.parent.parent = null;
} else if (parentPage instanceof Sitemap) {
pageBean.parent = getPageBean(sitemapName, sitemap.getName(), uri, locale, timeout);
pageBean.parent.widgets = null;
}
return pageBean;
} else {
if (logger.isDebugEnabled()) {
if (pageWidget == null) {
logger.debug("Received HTTP GET request at '{}' for the unknown page id '{}'.", uri, pageId);
} else {
logger.debug("Received HTTP GET request at '{}' for the page id '{}'. " + "This id refers to a non-linkable widget and is therefore no valid page id.", uri, pageId);
}
}
throw new WebApplicationException(404);
}
}
} else {
logger.info("Received HTTP GET request at '{}' for the unknown sitemap '{}'.", uri, sitemapName);
throw new WebApplicationException(404);
}
}
use of org.eclipse.smarthome.model.sitemap.Sitemap in project smarthome by eclipse.
the class SitemapResource method getSitemapBeans.
public Collection<SitemapDTO> getSitemapBeans(URI uri) {
Collection<SitemapDTO> beans = new LinkedList<SitemapDTO>();
logger.debug("Received HTTP GET request at '{}'.", UriBuilder.fromUri(uri).build().toASCIIString());
for (SitemapProvider provider : sitemapProviders) {
for (String modelName : provider.getSitemapNames()) {
Sitemap sitemap = provider.getSitemap(modelName);
if (sitemap != null) {
SitemapDTO bean = new SitemapDTO();
bean.name = modelName;
bean.icon = sitemap.getIcon();
bean.label = sitemap.getLabel();
bean.link = UriBuilder.fromUri(uri).path(bean.name).build().toASCIIString();
bean.homepage = new PageDTO();
bean.homepage.link = bean.link + "/" + sitemap.getName();
beans.add(bean);
}
}
}
return beans;
}
use of org.eclipse.smarthome.model.sitemap.Sitemap in project smarthome by eclipse.
the class SitemapSubscriptionService method collectWidgets.
private EList<Widget> collectWidgets(String sitemapName, String pageId) {
EList<Widget> widgets = new BasicEList<Widget>();
Sitemap sitemap = getSitemap(sitemapName);
if (sitemap != null) {
if (pageId.equals(sitemap.getName())) {
widgets = itemUIRegistry.getChildren(sitemap);
} else {
Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
if (pageWidget instanceof LinkableWidget) {
widgets = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
// We add the page widget. It will help any UI to update the page title.
widgets.add(pageWidget);
}
}
}
return widgets;
}
use of org.eclipse.smarthome.model.sitemap.Sitemap in project smarthome by eclipse.
the class ItemUIRegistryImpl method getWidgetId.
@Override
public String getWidgetId(Widget widget) {
Widget w2 = defaultWidgets.get(widget);
if (w2 != null) {
return getWidgetId(w2);
}
String id = "";
Widget w = widget;
while (w.eContainer() instanceof Widget) {
Widget parent = (Widget) w.eContainer();
String index = String.valueOf(((LinkableWidget) parent).getChildren().indexOf(w));
if (index.length() == 1) {
// make it two digits
index = "0" + index;
}
id = index + id;
w = parent;
}
if (w.eContainer() instanceof Sitemap) {
Sitemap sitemap = (Sitemap) w.eContainer();
String index = String.valueOf(sitemap.getChildren().indexOf(w));
if (index.length() == 1) {
// make it two digits
index = "0" + index;
}
id = index + id;
}
// use the item name as the id
if (w.eContainer() == null) {
String itemName = w.getItem();
id = itemName;
}
return id;
}
use of org.eclipse.smarthome.model.sitemap.Sitemap in project smarthome by eclipse.
the class ProxyServletService method uriFromRequest.
/**
* Determine which URI to address based on the request contents.
*
* @param request the servlet request. New attributes may be added to the request in order to cache the result for
* future calls.
* @return the URI indicated by the request, or <code>null</code> if not possible
*/
URI uriFromRequest(HttpServletRequest request) {
try {
// Return any URI we've already saved for this request
URI uri = (URI) request.getAttribute(ATTR_URI);
if (uri != null) {
return uri;
} else {
ProxyServletException pse = (ProxyServletException) request.getAttribute(ATTR_SERVLET_EXCEPTION);
if (pse != null) {
// If we errored on this request before, there is no point continuing
return null;
}
}
String sitemapName = request.getParameter("sitemap");
if (sitemapName == null) {
throw new ProxyServletException(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'sitemap' must be provided!");
}
String widgetId = request.getParameter("widgetId");
if (widgetId == null) {
throw new ProxyServletException(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'widgetId' must be provided!");
}
Sitemap sitemap = (Sitemap) modelRepository.getModel(sitemapName);
if (sitemap == null) {
throw new ProxyServletException(HttpServletResponse.SC_NOT_FOUND, String.format("Sitemap '%s' could not be found!", sitemapName));
}
Widget widget = itemUIRegistry.getWidget(sitemap, widgetId);
if (widget == null) {
throw new ProxyServletException(HttpServletResponse.SC_NOT_FOUND, String.format("Widget '%s' could not be found!", widgetId));
}
String uriString = null;
if (widget instanceof Image) {
uriString = ((Image) widget).getUrl();
} else if (widget instanceof Video) {
uriString = ((Video) widget).getUrl();
} else {
throw new ProxyServletException(HttpServletResponse.SC_FORBIDDEN, String.format("Widget type '%s' is not supported!", widget.getClass().getName()));
}
String itemName = widget.getItem();
if (itemName != null) {
State state = itemUIRegistry.getItemState(itemName);
if (state != null && state instanceof StringType) {
try {
uri = URI.create(state.toString());
request.setAttribute(ATTR_URI, uri);
return uri;
} catch (IllegalArgumentException ex) {
// fall thru
}
}
}
try {
uri = URI.create(uriString);
request.setAttribute(ATTR_URI, uri);
return uri;
} catch (IllegalArgumentException iae) {
throw new ProxyServletException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, String.format("URI '%s' is not a valid URI.", uriString));
}
} catch (ProxyServletException pse) {
request.setAttribute(ATTR_SERVLET_EXCEPTION, pse);
return null;
}
}
Aggregations