@Override
 public String render(ModelAndView modelAndView) {
   String viewName = modelAndView.getViewName();
   try {
     Template template = handlebars.compile(viewName);
     return template.apply(modelAndView.getModel());
   } catch (IOException e) {
     throw new RuntimeIOException(e);
   }
 }
  @Override
  public String process(String templateId, Object data) {
    String renderedTemplate;
    try {
      Template template = handlebars.compile(templateId);
      renderedTemplate = template.apply(data);
    } catch (IOException e) {
      throw new MailException();
    }

    return renderedTemplate;
  }
Example #3
0
 static {
   try {
     handlebars.registerHelper(
         "compare",
         new Helper<Object>() {
           @Override
           public CharSequence apply(Object context, Options options) throws IOException {
             if (options.params[0].equals(context == "last")) {
               return options.fn();
             } else {
               return options.inverse();
             }
           }
         });
     template = handlebars.compile("/com/fantasy/system/job/dicts");
   } catch (IOException e) {
     LOGGER.error(e.getMessage(), e);
   }
 }
Example #4
0
  private Kml createRootNetworkLink(UriInfo uriInfo) throws UnknownHostException {
    Kml kml = KmlFactory.createKml();
    NetworkLink rootNetworkLink = kml.createAndSetNetworkLink();

    rootNetworkLink.setName(this.productName);
    rootNetworkLink.setSnippet(KmlFactory.createSnippet().withMaxLines(0));
    UriBuilder baseUrlBuidler = UriBuilder.fromUri(uriInfo.getBaseUri());
    baseUrlBuidler.replacePath("");
    this.baseUrl = baseUrlBuidler.build().toString();
    String descriptionHtml = description;
    Handlebars handlebars = new Handlebars(templateLoader);
    try {
      Template template = handlebars.compile("description");
      descriptionHtml = template.apply(this);
      LOGGER.debug(descriptionHtml);
    } catch (IOException e) {
      LOGGER.error("Failed to apply description Template", e);
    }
    rootNetworkLink.setDescription(descriptionHtml);
    rootNetworkLink.setOpen(true);
    rootNetworkLink.setVisibility(false);
    Link link = rootNetworkLink.createAndSetLink();
    UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
    builder =
        generateEndpointUrl(
            servicesContextRoot
                + FORWARD_SLASH
                + CATALOG_URL_PATH
                + FORWARD_SLASH
                + KML_TRANSFORM_PARAM
                + FORWARD_SLASH
                + "sources",
            builder);
    link.setHref(builder.build().toString());
    link.setViewRefreshMode(ViewRefreshMode.NEVER);
    link.setRefreshMode(RefreshMode.ON_INTERVAL);
    link.setRefreshInterval(REFRESH_INTERVAL);

    return kml;
  }