Beispiel #1
0
  public static void main(String[] args) throws Exception {
    List<Book> books = new ArrayList<Book>();
    books.add(new Book("The Hitchhiker's Guide to the Galaxy", 5.70, true, "0"));
    books.add(new Book("Life, the Universe and Everything", 5.60, false, "N"));
    books.add(new Book("The > Restaurant at the < End of the Universe & all", 5.40, true, "Yes"));

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("books", books);
    model.put("pageName", "My Bookshelf");

    JadeConfiguration jadeConfiguration = new JadeConfiguration();
    jadeConfiguration.setPrettyPrint(true);
    jadeConfiguration.setMode(Jade4J.Mode.XML);

    JadeTemplate template = jadeConfiguration.getTemplate("src/main/java/jade2j/index.jade");

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();
    String result = jadeConfiguration.renderTemplate(template, model);
    stopWatch.stop();

    System.out.println(result);
    System.out.println(stopWatch.toString());
  }
Beispiel #2
0
  @Override
  public int doStartTag() throws JspException {
    WebApplicationContext context =
        WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());

    JadeConfiguration jadeConfiguration = context.getBean(JadeConfiguration.class);
    JadeTemplate jadeTemplate = context.getBean("TemplateSign", JadeTemplate.class);

    Map<String, Object> data = Maps.newHashMap();

    data.put("user", user);
    data.put("shortMode", shortMode);
    data.put("author", author);
    data.put("postdate", postdate);

    // TODO: move to globals
    data.put("dateFormat", new DateFormatHandler());

    if (timeprop != null) {
      data.put("timeprop", timeprop);
    }

    jadeConfiguration.renderTemplate(jadeTemplate, data, pageContext.getOut());

    /*
        ObjectMapper mapper = new ObjectMapper();
        try {
          pageContext.getOut().append(mapper.writer().writeValueAsString(data.get("user")));
        } catch (Exception e) {
          e.printStackTrace();
         // throw new RuntimeException(e);
        }
    */

    return SKIP_BODY;
  }