Esempio n. 1
0
            @Override
            public Reader getReader(String templateName) throws LoaderException {
              String[] parts = templateName.split("/", 2);

              if (parts.length != 2) {
                throw new IllegalArgumentException("Not a valid name: " + templateName);
              }
              CMSTheme theme = CMSTheme.forType(parts[0]);
              if (theme == null) {
                throw new IllegalArgumentException("Theme " + parts[0] + " not found!");
              }

              byte[] bytes = theme.contentForPath(parts[1]);
              if (bytes == null) {
                throw new IllegalArgumentException(
                    "Theme " + parts[0] + " does not contain resource '" + parts[1] + '"');
              }
              return new InputStreamReader(new ByteArrayInputStream(bytes), StandardCharsets.UTF_8);
            }
Esempio n. 2
0
 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());
   }
 }