Package net.pterodactylus.util.template

Examples of net.pterodactylus.util.template.TemplateContext


    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, String.format("Template was rendered in %.2fms.", ((finish - start) / 1000) / 1000.0));
View Full Code Here


    jsonPost.put("id", post.getId());
    jsonPost.put("sone", post.getSone().getId());
    jsonPost.put("recipient", post.getRecipientId().orNull());
    jsonPost.put("time", post.getTime());
    StringWriter stringWriter = new StringWriter();
    TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
    templateContext.set("core", webInterface.getCore());
    templateContext.set("request", request);
    templateContext.set("post", post);
    templateContext.set("currentSone", currentSone);
    templateContext.set("localSones", webInterface.getCore().getLocalSones());
    try {
      postTemplate.render(templateContext, stringWriter);
    } catch (TemplateException te1) {
      /* TODO - shouldn’t happen. */
    } finally {
View Full Code Here

    jsonReply.put("id", reply.getId());
    jsonReply.put("postId", reply.getPostId());
    jsonReply.put("soneId", reply.getSone().getId());
    jsonReply.put("time", reply.getTime());
    StringWriter stringWriter = new StringWriter();
    TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
    templateContext.set("core", webInterface.getCore());
    templateContext.set("request", request);
    templateContext.set("reply", reply);
    templateContext.set("currentSone", currentSone);
    try {
      replyTemplate.render(templateContext, stringWriter);
    } catch (TemplateException te1) {
      /* TODO - shouldn’t happen. */
    } finally {
View Full Code Here

    ObjectNode jsonNotification = new ObjectNode(instance);
    jsonNotification.put("id", notification.getId());
    StringWriter notificationWriter = new StringWriter();
    try {
      if (notification instanceof TemplateNotification) {
        TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext().mergeContext(((TemplateNotification) notification).getTemplateContext());
        templateContext.set("core", webInterface.getCore());
        templateContext.set("currentSone", webInterface.getCurrentSone(request.getToadletContext(), false));
        templateContext.set("localSones", webInterface.getCore().getLocalSones());
        templateContext.set("request", request);
        templateContext.set("currentVersion", SonePlugin.VERSION);
        templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
        templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
        templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
        templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
        templateContext.set("notification", notification);
        ((TemplateNotification) notification).render(templateContext, notificationWriter);
      } else {
        notification.render(notificationWriter);
      }
    } catch (IOException ioe1) {
View Full Code Here

        return null;
      } finally {
        Closer.close(templateInputStreamReader);
      }

      TemplateContext templateContext = templateContextFactory.createTemplateContext();
      templateContext.set("core", core);
      templateContext.set("currentSone", soneProperties);
      templateContext.set("currentEdition", core.getUpdateChecker().getLatestEdition());
      templateContext.set("version", SonePlugin.VERSION);
      StringWriter writer = new StringWriter();
      StringBucket bucket = null;
      try {
        template.render(templateContext, writer);
        bucket = new StringBucket(writer.toString(), utf8Charset);
View Full Code Here

    }
    String title = request.getHttpRequest().getParam("title").trim();
    String description = request.getHttpRequest().getParam("description").trim();
    image.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
    webInterface.getCore().touchConfiguration();
    return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()).put("parsedDescription", (String) parserFilter.format(new TemplateContext(), image.getDescription(), ImmutableMap.<String, Object>builder().put("sone", image.getSone()).build()));
  }
View Full Code Here

   *            The writer to render the part to
   * @param plainTextPart
   *            The part to render
   */
  private void render(Writer writer, PlainTextPart plainTextPart) {
    TemplateContext templateContext = templateContextFactory.createTemplateContext();
    templateContext.set("text", plainTextPart.getText());
    plainTextTemplate.render(templateContext, writer);
  }
View Full Code Here

   *            The title of the link
   * @param cssClass
   *            The CSS class of the link
   */
  private void renderLink(Writer writer, String link, String text, String title, String cssClass) {
    TemplateContext templateContext = templateContextFactory.createTemplateContext();
    templateContext.set("cssClass", cssClass);
    templateContext.set("link", link);
    templateContext.set("text", text);
    templateContext.set("title", title);
    linkTemplate.render(templateContext, writer);
  }
View Full Code Here

    int maxWidth = Numbers.safeParseInteger(parameters.get("max-width"), Integer.MAX_VALUE);
    int maxHeight = Numbers.safeParseInteger(parameters.get("max-height"), Integer.MAX_VALUE);
    String mode = String.valueOf(parameters.get("mode"));
    String title = String.valueOf(parameters.get("title"));

    TemplateContext linkTemplateContext = templateContextFactory.createTemplateContext();
    linkTemplateContext.set("class", imageClass);
    if (image.isInserted()) {
      linkTemplateContext.set("src", "/" + image.getKey());
      linkTemplateContext.set("forceDownload", true);
    } else {
      linkTemplateContext.set("src", "getImage.html?image=" + image.getId());
    }
    int imageWidth = image.getWidth();
    int imageHeight = image.getHeight();
    if ("enlarge".equals(mode)) {
      double scale = Math.max(maxWidth / (double) imageWidth, maxHeight / (double) imageHeight);
      linkTemplateContext.set("width", (int) (imageWidth * scale + 0.5));
      linkTemplateContext.set("height", (int) (imageHeight * scale + 0.5));
      linkTemplateContext.set("left", String.format("%dpx", (int) (maxWidth - (imageWidth * scale)) / 2));
      linkTemplateContext.set("top", String.format("%dpx", (int) (maxHeight - (imageHeight * scale)) / 2));
    } else {
      double scale = 1;
      if ((imageWidth > maxWidth) || (imageHeight > maxHeight)) {
        scale = Math.min(maxWidth / (double) imageWidth, maxHeight / (double) imageHeight);
      }
      linkTemplateContext.set("width", (int) (imageWidth * scale + 0.5));
      linkTemplateContext.set("height", (int) (imageHeight * scale + 0.5));
    }
    linkTemplateContext.set("alt", Optional.fromNullable(title).or(image.getDescription()));
    linkTemplateContext.set("title", Optional.fromNullable(title).or(image.getTitle()));

    StringWriter stringWriter = new StringWriter();
    linkTemplate.render(linkTemplateContext, stringWriter);
    return stringWriter.toString();
  }
View Full Code Here

TOP

Related Classes of net.pterodactylus.util.template.TemplateContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.