Package com.firefly.template

Examples of com.firefly.template.TemplateFactory


        long end = System.currentTimeMillis();
        System.out.println("freemark: " + (end - start) + "ms\t" + (int)(times / (double)(end - start) * 1000) + "tps");
//        System.out.println(new String(ret, "UTF-8"));
       
        // firefly
        final TemplateFactory t = new TemplateFactory(new File(TestConfig.class.getResource("/").toURI())).init();
        FunctionRegistry.add("book_count", new Function() {

      @Override
      public void render(Model model, OutputStream out, Object... obj) throws Throwable {
        Book book = (Book)obj[0];
        out.write(String.valueOf(book.getPrice() * book.getDiscount() / 100).getBytes(t.getConfig().getCharset()));
      }
     
    });
        View view = t.getView("/books.html");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        view.render(model, out);
    out.close();
    start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
View Full Code Here


        }
      }};
    FunctionRegistry.add("testFunction2", function2);
   
    // #if #elseif #else
    TemplateFactory t = new TemplateFactory(new File(TestConfig.class.getResource("/page").toURI())).init();
//    System.out.println(t.getConfig().getViewPath());
//    System.out.println(t.getConfig().getCompiledPath());
    View view = t.getView("/testIf.html");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Model model = new ModelMock();
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
   
    out = new ByteArrayOutputStream();
    model.put("user", user);
    model.put("login", true);
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
   
    // #for
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testFor.html");
   
    List<User> list = new ArrayList<User>();
    user = new User();
    user.setName("Tom");
    user.setAge(20);
    list.add(user);
   
    user = new User();
    user.setName("小明");
    user.setAge(13);
    list.add(user);
   
    user = new User();
    user.setName("小红");
    user.setAge(20);
    list.add(user);
   
    model.put("users", list);
    model.put("intArr", new int[]{1,2,3,4,5});
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
   
    // #switch #case #default
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testSwitch.html");
    model.put("stage", 2);
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
   
    // #set
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testSet.html");
    model.put("name", "迈克");
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
   
    // #include
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testInclude.html");
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
   
//    FunctionRegistry.MAP.get("").render(model, out, obj)
View Full Code Here

    if (!init) {
      log.info("template path {}", viewPath);
      com.firefly.template.Config config = new com.firefly.template.Config();
      config.setViewPath(viewPath);
      config.setCharset(encoding);
      t = new TemplateFactory(config).init();
      init = true;
    }
    return this;
  }
View Full Code Here

   
    String page = errorPage.get(status);
    if(VerifyUtils.isEmpty(page))
      return getDefaultErrorPage(status, content);
   
    TemplateFactory templateFactory = TemplateView.getTemplateFactory();
    if(templateFactory == null)
      return getDefaultErrorPage(status, content);
   
    com.firefly.template.View v = templateFactory.getView(page);
    if(v == null)
      return getDefaultErrorPage(status, content);
   
    ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
    Model model = new Model() {
View Full Code Here

        }
      }};
    FunctionRegistry.add("testFunction2", function2);
   
    // #if #elseif #else
    TemplateFactory t = new TemplateFactory(new File(TestConfig.class.getResource("/page").toURI())).init();
//    System.out.println(t.getConfig().getViewPath());
//    System.out.println(t.getConfig().getCompiledPath());
    View view = t.getView("/testIf.html");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Model model = new ModelMock();
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
    System.out.println("=======================================");
   
    out = new ByteArrayOutputStream();
    model.put("otherAge", 33);
    model.put("user", user);
    model.put("login", true);
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
    System.out.println("=======================================for");
   
    // #for
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testFor.html");
   
    List<User> list = new ArrayList<User>();
    user = new User();
    user.setName("Tom");
    user.setAge(20);
    list.add(user);
   
    user = new User();
    user.setName("小明");
    user.setAge(13);
    list.add(user);
   
    user = new User();
    user.setName("小红");
    user.setAge(20);
    list.add(user);
   
    model.put("users", list);
    model.put("intArr", new int[]{1,2,3,4,5});
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
    System.out.println("=======================================");
   
    // #switch #case #default
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testSwitch.html");
    model.put("stage", 2);
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
    System.out.println("=======================================");
   
    // #set
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testSet.html");
    model.put("name", "迈克");
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
    System.out.println("=======================================");
   
    // #include
    model = new ModelMock();
    out = new ByteArrayOutputStream();
    view = t.getView("/testInclude.html");
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
    System.out.println("=======================================");
   
    // #function
    model = new ModelMock();
    model.put("teststr", "好长好长,好大好大,的一个东东!");
    model.put("testXmlEscape", "<input type=\"text\">测试</input>");
    out = new ByteArrayOutputStream();
    view = t.getView("/testFunction.html");
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
//    FunctionRegistry.MAP.get("").render(model, out, obj)
  }
View Full Code Here

        long end = System.currentTimeMillis();
        System.out.println("freemark: " + (end - start) + "ms\t" + (int)(times / (double)(end - start) * 1000) + "tps");
//        System.out.println(new String(ret, "UTF-8"));
       
        // firefly
        final TemplateFactory t = new TemplateFactory(new File(TestConfig.class.getResource("/").toURI())).init();
        FunctionRegistry.add("book_count", new Function() {

      @Override
      public void render(Model model, OutputStream out, Object... obj) throws Throwable {
        Book book = (Book)obj[0];
        out.write(String.valueOf(book.getPrice() * book.getDiscount() / 100).getBytes(t.getConfig().getCharset()));
      }
     
    });
        View view = t.getView("/books.html");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        view.render(model, out);
    out.close();
    start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
View Full Code Here

      _viewPath = viewPath;
      com.firefly.template.Config config = new com.firefly.template.Config();
      config.setViewPath(viewPath);
      config.setCharset(encoding);
      charset = encoding;
      templateFactory = new TemplateFactory(config).init();
      init = true;
    }
  }
View Full Code Here

   * @param args
   */
  public static void main(String[] args) throws Throwable {
    String str = "测试一下页面";
    System.out.println(Arrays.toString(str.getBytes("UTF-8")));
    TemplateFactory t = new TemplateFactory(new File(CharsetDemo.class.getResource("/page").toURI())).init();
    View view = t.getView("/index2.html");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Model model = new ModelMock();
    view.render(model, out);
    out.close();
    System.out.println(out.toString());
View Full Code Here

TOP

Related Classes of com.firefly.template.TemplateFactory

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.