public CMSURLHandler() {
   engine.addExtension(new CMSExtensions());
   if (CMSConfigurationManager.isInThemeDevelopmentMode()) {
     engine.setTemplateCache(null);
     logger.info("CMS Theme Development Mode enabled!");
   } else {
     engine.setTemplateCache(
         CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build());
   }
 }
  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);
  }
 private void handleLeadingSlash(final HttpServletRequest req, HttpServletResponse res, Site sites)
     throws PebbleException, IOException, ServletException {
   if (req.getMethod().equals("GET")) {
     res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
     res.setHeader("Location", rewritePageUrl(req));
     return;
   } else if (req.getMethod().equals("POST")) {
     if (CoreConfiguration.getConfiguration().developmentMode()) {
       PebbleEngine engine = new PebbleEngine(new StringLoader());
       engine.addExtension(new CMSExtensions());
       PebbleTemplate compiledTemplate =
           engine.getTemplate(
               "<html><head></head><body><h1>POST action with backslash</h1><b>You posting data with a URL with a backslash. Alter the form to post with the same URL without the backslash</body></html>");
       res.setStatus(500);
       res.setContentType("text/html");
       compiledTemplate.evaluate(res.getWriter());
     } else {
       errorPage(req, res, sites, 500);
     }
   }
 }
 private void errorPage(
     final HttpServletRequest req, HttpServletResponse res, Site site, int errorCode)
     throws ServletException, IOException {
   CMSTheme cmsTheme = site.getTheme();
   if (cmsTheme != null && cmsTheme.definesPath(errorCode + ".html")) {
     try {
       PebbleTemplate compiledTemplate =
           engine.getTemplate(cmsTheme.getType() + "/" + errorCode + ".html");
       TemplateContext global = new TemplateContext();
       populateSiteInfo(req, null, site, global);
       res.setStatus(errorCode);
       res.setContentType("text/html");
       compiledTemplate.evaluate(res.getWriter(), global);
     } catch (PebbleException e) {
       throw new ServletException("Could not render error page for " + errorCode);
     }
   } else {
     res.sendError(errorCode, req.getRequestURI());
   }
 }
 public void invalidateEntry(String key) {
   engine.getTemplateCache().invalidate(key);
 }