예제 #1
0
  private void renderPage(
      final HttpServletRequest req,
      String reqPagePath,
      HttpServletResponse res,
      Site site,
      Page page,
      String[] requestContext)
      throws PebbleException, IOException {

    TemplateContext global = new TemplateContext();
    global.setRequestContext(requestContext);
    for (String key : req.getParameterMap().keySet()) {
      global.put(key, req.getParameter(key));
    }

    global.put("page", makePageWrapper(page));
    populateSiteInfo(req, page, site, global);

    List<TemplateContext> components = new ArrayList<TemplateContext>();

    for (Component component : page.getComponentsSet()) {
      TemplateContext local = new TemplateContext();
      component.handle(page, local, global);
      components.add(local);
    }

    global.put("components", components);

    PebbleTemplate compiledTemplate =
        engine.getTemplate(site.getTheme().getType() + "/" + page.getTemplate().getFilePath());

    res.setStatus(200);
    res.setContentType("text/html");
    compiledTemplate.evaluate(res.getWriter(), global);
  }
예제 #2
0
  private void renderCMSPage(
      final HttpServletRequest req, HttpServletResponse res, Site sites, String pageSlug)
      throws ServletException, IOException, PebbleException {
    if (pageSlug.startsWith("/")) {
      pageSlug = pageSlug.substring(1);
    }
    String[] parts = pageSlug.split("/");

    String pageName = parts[0];

    Page page;
    if (Strings.isNullOrEmpty(pageName) && sites.getInitialPage() != null) {
      page = sites.getInitialPage();
    } else {
      page =
          sites
              .getPagesSet()
              .stream()
              .filter(p -> pageName.equals(p.getSlug()))
              .findAny()
              .orElse(null);
    }

    if (page == null || page.getTemplate() == null) {
      errorPage(req, res, sites, 404);
    } else if (!page.isPublished() || !page.getCanViewGroup().isMember(Authenticate.getUser())) {
      errorPage(req, res, sites, 404);
    } else {
      try {
        renderPage(req, pageSlug, res, sites, page, parts);
      } catch (ResourceNotFoundException e) {
        errorPage(req, res, sites, 404);
      }
    }
  }