Exemplo n.º 1
1
 /** renders the template and wraps it to a full httpresponse */
 public void renderTemplate(IRequest req) {
   if (tpl == null) {
     if (this.ts == null) ts = Server.srv.templatemanager.getTemplateSet("default");
     tpl = ts.getTemplate(tName);
     if (tpl == null) tpl = ts.getTemplate("not_found");
   }
   if (tpl.isRedirect()) {
     this.setRedirectTo(tpl.getDestination(), req.getCookieDomain());
     return;
   }
   if (!nocache
       && !nostore
       && !tpl.hasToBeRendered(
           req.getProperty("if-none-match"),
           HttpDateParser.parseDate(req.getProperty("if-modified-since")))) {
     StringBuffer sb = new StringBuffer(isHTTP11 ? "HTTP/1.1" : "HTTP/1.0");
     sb.append(IResponseHeaders.NOT_MODIFIED);
     sb.trimToSize();
     prepareForSending(CharBuffer.wrap(sb.toString()));
     return;
   }
   String cntnt = tpl.render(req);
   if (cntnt == null || cntnt.length() < 1) {
     Server.log(
         this,
         "renderTemplate: rendered template has no content",
         Server.MSG_STATE,
         Server.LVL_MAJOR);
     resCode = NOCONTENT_CODE;
     StringBuffer sb = new StringBuffer();
     sb.append("<html><body><b>The requested page could not be displayed!<br><br>Reason:</b> ");
     if (tpl == null) {
       sb.append("No template given");
     } else {
       sb.append("Template '");
       sb.append(tpl.getName());
       sb.append("' has not been found on this server.");
     }
     sb.append("</body></html>");
     wrap(sb.toString(), req.getCookieDomain());
     return;
   }
   nocache = tpl.notCacheable();
   //      if (nocache)
   //          Server.log (this, "not cacheable", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
   wrap(cntnt, tpl.getEtag(), req.getCookieDomain());
 }