Exemple #1
0
  private SitemapBean createSitemapBean(String sitemapName, Sitemap sitemap, URI uri) {
    SitemapBean bean = new SitemapBean();

    bean.name = sitemapName;
    bean.icon = sitemap.getIcon();
    bean.label = sitemap.getLabel();

    bean.link =
        UriBuilder.fromUri(uri)
            .path(SitemapResource.PATH_SITEMAPS)
            .path(bean.name)
            .build()
            .toASCIIString();
    bean.homepage =
        createPageBean(
            sitemap.getName(),
            sitemap.getLabel(),
            sitemap.getIcon(),
            sitemap.getName(),
            sitemap.getChildren(),
            true,
            false,
            uri);
    return bean;
  }
 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.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;
 }
Exemple #3
0
 public static 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()) {
           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);
   }
 }