Package org.openhab.model.sitemap

Examples of org.openhab.model.sitemap.Sitemap


    assertEquals("Label [5]", label);
  }
 
  @Test
  public void getWidget_UnknownPageId() throws ItemNotFoundException {
    Sitemap sitemap = SitemapFactory.eINSTANCE.createSitemap();
    when(registry.getItem("unknown")).thenThrow(new ItemNotFoundException("unknown"));
    Widget w = uiRegistry.getWidget(sitemap, "unknown");
    assertNull(w);
  }
View Full Code Here


    // if there are no parameters, display the "default" sitemap
    if(sitemapName==null) sitemapName = "default";
   
    StringBuilder result = new StringBuilder();
   
    Sitemap sitemap = sitemapProvider.getSitemap(sitemapName);
    try {
      if(sitemap==null) {
        throw new RenderException("Sitemap '" + sitemapName + "' could not be found");
      }
      logger.debug("reading sitemap {}", sitemap.getName());
      if(widgetId==null || widgetId.isEmpty() || widgetId.equals("Home")) {
        // we are at the homepage, so we render the children of the sitemap root node
        String label = sitemap.getLabel()!=null ? sitemap.getLabel() : sitemapName;
        EList<Widget> children = sitemap.getChildren();
        if(poll && waitForChanges(children)==false) {
          // we have reached the timeout, so we do not return any content as nothing has changed
          res.getWriter().append(getTimeoutResponse()).close();
          return;
        }
        result.append(renderer.processPage("Home", sitemapName, label, sitemap.getChildren(), 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
        Widget w = renderer.getItemUIRegistry().getWidget(sitemap, widgetId);
        if(w!=null) {
          if(!(w instanceof LinkableWidget)) {
View Full Code Here

            if(pathSegments.length>=3) {
              String sitemapName = pathSegments[1];
              String pageName = pathSegments[2];

              Sitemap sitemap = (Sitemap) RESTApplication.getModelRepository().getModel(sitemapName + ".sitemap");
              if(sitemap!=null) {
                List<Widget> children = null;
                if(pageName.equals(sitemapName)) {
                  children = sitemap.getChildren();
                } else {               
                  Widget widget = RESTApplication.getItemUIRegistry().getWidget(sitemap, pageName);
                  if(widget instanceof LinkableWidget) {
                    LinkableWidget page = (LinkableWidget) widget;
                    children = RESTApplication.getItemUIRegistry().getChildren(page);
View Full Code Here

      if (pathInfo.startsWith("/" + SitemapResource.PATH_SITEMAPS)) {
            String[] pathSegments = pathInfo.substring(1).split("/");
              if(pathSegments.length>=3) {
                String sitemapName = pathSegments[1];
                String pageId = pathSegments[2];
                Sitemap sitemap = (Sitemap) RESTApplication.getModelRepository().getModel(sitemapName + ".sitemap");
                if(sitemap!=null) {
            return SitemapResource.getPageBean(sitemapName, pageId, basePath);
                }
              }
          }
View Full Code Here

      .outputComments(true).build();
    }
 
    static public PageBean getPageBean(String sitemapName, String pageId, URI uri) {
    ItemUIRegistry itemUIRegistry = RESTApplication.getItemUIRegistry();
    Sitemap sitemap = getSitemap(sitemapName);
    if(sitemap!=null) {
      if(pageId.equals(sitemap.getName())) {
        return createPageBean(sitemapName, sitemap.getLabel(), sitemap.getIcon(), sitemap.getName(), sitemap.getChildren(), false, isLeaf(sitemap.getChildren()), uri);
      } else {
        Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
        if(pageWidget instanceof LinkableWidget) {
          EList<Widget> children = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
          PageBean pageBean = createPageBean(sitemapName, itemUIRegistry.getLabel(pageWidget), itemUIRegistry.getIcon(pageWidget),
              pageId, children, false, isLeaf(children), uri);
          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);
            pageBean.parent.widgets = null;
            pageBean.parent.parent = null;
          } else if(parentPage instanceof Sitemap) {
            pageBean.parent = getPageBean(sitemapName, sitemap.getName(), uri);
            pageBean.parent.widgets = null;
          }
          return pageBean;
        } else {
          if(logger.isDebugEnabled()) {
View Full Code Here

  public Collection<SitemapBean> getSitemapBeans(URI uri) {
    Collection<SitemapBean> beans = new LinkedList<SitemapBean>();
    logger.debug("Received HTTP GET request at '{}'.", UriBuilder.fromUri(uri).build().toASCIIString());
    ModelRepository modelRepository = RESTApplication.getModelRepository();
    for(String modelName : modelRepository.getAllModelNamesOfType("sitemap")) {
      Sitemap sitemap = (Sitemap) modelRepository.getModel(modelName);
      if(sitemap!=null) {
        SitemapBean bean = new SitemapBean();
        bean.name = StringUtils.removeEnd(modelName, SITEMAP_FILEEXT);
        bean.icon = sitemap.getIcon();
        bean.label = sitemap.getLabel();
        bean.link = UriBuilder.fromUri(uri).path(bean.name).build().toASCIIString();
        bean.homepage = new PageBean();
        bean.homepage.link = bean.link + "/" + sitemap.getName();
        beans.add(bean);
      }
    }
    return beans;
  }
View Full Code Here

    }
    return beans;
  }

  public SitemapBean getSitemapBean(String sitemapname, URI uri) {
    Sitemap sitemap = getSitemap(sitemapname);
    if(sitemap!=null) {
      return createSitemapBean(sitemapname, sitemap, uri);
    } else {
      logger.info("Received HTTP GET request at '{}' for the unknown sitemap '{}'.", uriInfo.getPath(), sitemapname);
      throw new WebApplicationException(404);
View Full Code Here

  }

  static public Sitemap getSitemap(String sitemapname) {
        ModelRepository repo = RESTApplication.getModelRepository();
        if(repo!=null) {
      Sitemap sitemap = (Sitemap) repo.getModel(sitemapname + SITEMAP_FILEEXT);
      return sitemap;
        }
        return null;
    }
View Full Code Here

    if(baseUrl == null) {
      baseUrl = "";
    }
    String uriString = null;
   
    Sitemap sitemap = (Sitemap) modelRepository.getModel(sitemapName);
    if(sitemap!=null) {
      Widget widget = itemUIRegistry.getWidget(sitemap, widgetId);
      if(widget instanceof Image) {
        Image image = (Image) widget;
        uriString = baseUrl + image.getUrl();
View Full Code Here

  /* (non-Javadoc)
   * @see org.openhab.model.sitemap.internal.SitemapProvider#getSitemap(java.lang.String)
   */
  public Sitemap getSitemap(String sitemapName) {
    if(modelRepo!=null) {
      Sitemap sitemap = (Sitemap) modelRepo.getModel(sitemapName + ".sitemap");
      if(sitemap!=null) {
        return sitemap;
      } else {
        logger.debug("Sitemap {} can not be found", sitemapName);
        return null;
View Full Code Here

TOP

Related Classes of org.openhab.model.sitemap.Sitemap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.