Package com.firefly.template

Examples of com.firefly.template.View


        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++) {
          out = new ByteArrayOutputStream();
            view.render(model, out);
        out.close();
        }
        end = System.currentTimeMillis();
        System.out.println("firefly-template: " + (end - start) + "ms\t" + (int)(times / (double)(end - start) * 1000) + "tps");
//        System.out.println(new String(out.toByteArray(), "UTF-8"));
View Full Code Here


   
    // #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 #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

        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++) {
          out = new ByteArrayOutputStream();
            view.render(model, out);
        out.close();
        }
        end = System.currentTimeMillis();
        System.out.println("firefly-template: " + (end - start) + "ms\t" + (int)(times / (double)(end - start) * 1000) + "tps");
//        System.out.println(new String(out.toByteArray(), "UTF-8"));
View Full Code Here

   */
  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.View

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.