Exemplo n.º 1
0
 private void blockUnlessChangeOccurs(String sitemapname, String pageId) {
   Sitemap sitemap = getSitemap(sitemapname);
   if (sitemap != null) {
     if (pageId.equals(sitemap.getName())) {
       waitForChanges(sitemap.getChildren());
     } else {
       Widget pageWidget = itemUIRegistry.getWidget(sitemap, pageId);
       if (pageWidget instanceof LinkableWidget) {
         EList<Widget> children = itemUIRegistry.getChildren((LinkableWidget) pageWidget);
         waitForChanges(children);
       }
     }
   }
 }
Exemplo n.º 2
0
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String sitemapName = request.getParameter("sitemap");
    String widgetId = request.getParameter("widgetId");

    if (sitemapName == null) {
      throw new ServletException("Parameter 'sitemap' must be provided!");
    }
    if (widgetId == null) {
      throw new ServletException("Parameter 'widget' must be provided!");
    }

    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 = image.getUrl();
      } else if (widget instanceof Video) {
        Video video = (Video) widget;
        uriString = video.getUrl();
      } else {
        if (widget == null) {
          throw new ServletException("Widget '" + widgetId + "' could not be found!");
        } else {
          throw new ServletException(
              "Widget type '" + widget.getClass().getName() + "' is not supported!");
        }
      }
    } else {
      throw new ServletException("Sitemap '" + sitemapName + "' could not be found!");
    }

    HttpClient httpClient = new HttpClient();

    try {
      // check if the uri uses credentials and configure the http client accordingly
      URI uri = URI.create(uriString);

      if (uri.getUserInfo() != null) {
        String[] userInfo = uri.getUserInfo().split(":");
        httpClient.getParams().setAuthenticationPreemptive(true);
        Credentials creds = new UsernamePasswordCredentials(userInfo[0], userInfo[1]);
        httpClient
            .getState()
            .setCredentials(
                new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM), creds);
      }
    } catch (IllegalArgumentException e) {
      throw new ServletException("URI '" + uriString + "' is not valid: " + e.getMessage());
    }

    // do the client request
    GetMethod method = new GetMethod(uriString);
    httpClient.executeMethod(method);

    // copy all headers
    for (Header header : method.getResponseHeaders()) {
      response.setHeader(header.getName(), header.getValue());
    }

    // now copy/stream the body content
    IOUtils.copy(method.getResponseBodyAsStream(), response.getOutputStream());
    method.releaseConnection();
  }
Exemplo n.º 3
0
 private PageDTO getPageBean(String sitemapName, String pageId, URI uri, Locale locale) {
   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,
           locale);
     } 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);
         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);
           pageBean.parent.widgets = null;
           pageBean.parent.parent = null;
         } else if (parentPage instanceof Sitemap) {
           pageBean.parent = getPageBean(sitemapName, sitemap.getName(), uri, locale);
           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);
   }
 }