コード例 #1
1
ファイル: ContentContainer.java プロジェクト: ronry/ronrytest
 /** 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());
 }
コード例 #2
0
ファイル: ContentContainer.java プロジェクト: ronry/ronrytest
 public boolean canUseTemplateset(TemplateSet t) {
   if (Server.srv.DEFAULT_TEMPLATESET == null || t == null) return true;
   StringBuffer defaultTs = new StringBuffer(Server.srv.DEFAULT_TEMPLATESET);
   if (defaultTs != null) {
     StringTokenizer st = new StringTokenizer(defaultTs.toString(), ",");
     while (st.hasMoreTokens()) {
       StringBuilder templateName = new StringBuilder(st.nextToken());
       if (templateName.toString().equals(t.getName())) return true;
     }
   }
   if (Server.DEBUG) {
     StringBuffer scn = new StringBuffer();
     scn.append(" can not use Template ");
     scn.append(t.getName());
     Server.log(this, scn.toString(), Server.MSG_TRAFFIC, Server.LVL_MINOR);
   }
   return false;
 }
コード例 #3
0
ファイル: ContentContainer.java プロジェクト: ronry/ronrytest
  public String checkTName(User u, String name) {
    if (Server.srv.getProperty("costum.userAgent") == null) return name;

    String browseragent = name;
    if (u != null && u.getUserAgent() != null) {
      browseragent = u.getUserAgent();
    } else return name;

    boolean defaultFile = true;
    String ta[] = Server.srv.getProperty("costum.userAgent").split(",");
    Vector<String> tempAgent = new Vector<String>();
    for (int i = 0; i < ta.length; i++) {
      tempAgent.add(ta[i].trim().toLowerCase());
    }
    int fn = 0;
    int found = 0;
    for (Enumeration<String> e = tempAgent.elements(); e.hasMoreElements(); ) {
      StringBuilder customAgent = new StringBuilder((String) e.nextElement());
      fn++;
      if (browseragent.toLowerCase().indexOf(customAgent.toString().toLowerCase()) >= 0) {
        defaultFile = false;
        Server.log(
            this,
            "Found Browser '" + customAgent + "'(" + u.getUserAgent() + ")",
            Server.MSG_STATE,
            Server.LVL_VERBOSE);
        found = fn;
        continue;
      } else {
        if (u != null && u.getUserAgent() != null)
          Server.log(
              this,
              "Browser '" + customAgent + "' not found(" + u.getUserAgent() + ")",
              Server.MSG_STATE,
              Server.LVL_VERBOSE);
      }
      customAgent = null;
    }
    StringBuilder fName = null;
    if (defaultFile) {
      return name;
    } else {
      fName = new StringBuilder(name).append("_custom").append(found);
      if (ts == null || u == null | u.getName() == null) return name;
      tpl = ts.getTemplate(fName.toString());
      if (tpl == null) {
        Server.log(
            this,
            u.getTemplateSet() + " File " + fName + " not found",
            Server.MSG_STATE,
            Server.LVL_VERBOSE);
        fName = new StringBuilder(name).append("_custom");
        tpl = ts.getTemplate(fName.toString());
      }
      if (tpl == null) {
        Server.log(
            this,
            u.getTemplateSet() + " File " + fName + " not found- loading default input File",
            Server.MSG_ERROR,
            Server.LVL_MAJOR);
        return name;
      }
    }
    return fName.toString();
  }