Ejemplo n.º 1
0
  private void addMessageButtons(ToadletContext ctx, HTMLNode parent, String folderName, int uid) {
    HTMLNode buttonBox = parent.addChild("div", "class", "message-buttons");

    // Add reply button
    HTMLNode replyForm = ctx.addFormChild(buttonBox, NewMessageToadlet.getPath(), "reply");
    replyForm.addChild(
        "input",
        new String[] {"type", "name", "value"},
        new String[] {"hidden", "folder", folderName});
    replyForm.addChild(
        "input",
        new String[] {"type", "name", "value"},
        new String[] {"hidden", "message", "" + uid});

    String replyText = FreemailL10n.getString("Freemail.MessageToadlet.reply");
    replyForm.addChild(
        "input",
        new String[] {"type", "name", "value"},
        new String[] {"submit", "reply", replyText});
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public Response handleRequest(FreenetRequest request, Response response) throws IOException {
    String redirectTarget = getRedirectTarget(request);
    if (redirectTarget != null) {
      return new RedirectResponse(redirectTarget);
    }

    if (isFullAccessOnly() && !request.getToadletContext().isAllowedFullAccess()) {
      return response
          .setStatusCode(401)
          .setStatusText("Not authorized")
          .setContentType("text/html");
    }
    ToadletContext toadletContext = request.getToadletContext();
    if (request.getMethod() == Method.POST) {
      /* require form password. */
      String formPassword = request.getHttpRequest().getPartAsStringFailsafe("formPassword", 32);
      if (!formPassword.equals(toadletContext.getContainer().getFormPassword())) {
        return new RedirectResponse(invalidFormPasswordRedirectTarget);
      }
    }
    PageMaker pageMaker = toadletContext.getPageMaker();
    PageNode pageNode = pageMaker.getPageNode(getPageTitle(request), toadletContext);
    for (String styleSheet : getStyleSheets()) {
      pageNode.addCustomStyleSheet(styleSheet);
    }
    for (Map<String, String> linkNodeParameters : getAdditionalLinkNodes(request)) {
      HTMLNode linkNode = pageNode.headNode.addChild("link");
      for (Entry<String, String> parameter : linkNodeParameters.entrySet()) {
        linkNode.addAttribute(parameter.getKey(), parameter.getValue());
      }
    }
    String shortcutIcon = getShortcutIcon();
    if (shortcutIcon != null) {
      pageNode.addForwardLink("icon", shortcutIcon);
    }

    TemplateContext templateContext = templateContextFactory.createTemplateContext();
    templateContext.mergeContext(template.getInitialContext());
    try {
      long start = System.nanoTime();
      processTemplate(request, templateContext);
      long finish = System.nanoTime();
      logger.log(
          Level.FINEST, "Template was rendered in " + ((finish - start) / 1000) / 1000.0 + "ms.");
    } catch (RedirectException re1) {
      return new RedirectResponse(re1.getTarget());
    }

    StringWriter stringWriter = new StringWriter();
    template.render(templateContext, stringWriter);
    pageNode.content.addChild("%", stringWriter.toString());

    postProcess(request, templateContext);

    return response
        .setStatusCode(200)
        .setStatusText("OK")
        .setContentType("text/html")
        .write(pageNode.outer.generate());
  }