Package com.firefly.template

Examples of com.firefly.template.Model


    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());
View Full Code Here


        }
        Map<String, Object> context = new HashMap<String, Object>();
        context.put("user", new User("liangfei", "admin"));
        context.put("books", books);
       
        Model model = new ModelMock();
        model.put("user", new User("liangfei", "admin"));
        model.put("books", books);
       
     // freemark
        StringWriter writer = new StringWriter();
        Configuration configuration = new Configuration();
        configuration.setTemplateLoader(new ClassTemplateLoader(PerformanceTest.class, "/"));
View Full Code Here

    }
   
    response.setCharacterEncoding(templateFactory.getConfig().getCharset());
    response.setHeader("Content-Type", "text/html; charset=" + templateFactory.getConfig().getCharset());
    ServletOutputStream out = response.getOutputStream();
    Model model = new Model() {

      @Override
      public void clear() {
        Enumeration<String> e = request.getAttributeNames();
        while (e.hasMoreElements()) {
View Full Code Here

    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

  public void testMap() {
    Map<Integer, Map<String, String>> map = new HashMap<Integer, Map<String, String>>();
    Map<String, String> m1 = new HashMap<String, String>();
    m1.put("key1", "key1");
    map.put(4, m1);
    Model model = new ModelMock();
    model.put("testMap", map);
    ObjectNavigator o = ObjectNavigator.getInstance();
    Assert.assertThat(o.find(model, "testMap[4]['key1']").toString(), equalTo("key1"));
  }
View Full Code Here

    List<String> list = new ArrayList<String>();
    list.add("list111");
    list.add("list222");
    list.add("list333");
   
    Model model = new ModelMock();
    model.put("a", "fffff");
    model.put("b", map2);
    model.put("arr", arr);
    model.put("list", list);
   
    ObjectNavigator o = ObjectNavigator.getInstance();
    Assert.assertThat(o.find(model, "a").toString(), equalTo("fffff"));
    Assert.assertThat(o.find(model, "b['ccc']").toString(), equalTo("ddd"));
    Assert.assertThat(o.find(model, "b['eee']").toString(), equalTo("fff"));
View Full Code Here

   
    map2.put("map3", map3);
    map2.put("map4", map4);
    foo.setMap2(map2);
   
    Model model = new ModelMock();
    model.put("foo", foo);
   
    ObjectNavigator o = ObjectNavigator.getInstance();
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.info")), equalTo("bar1"));
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.serialNumber")), equalTo("33"));
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.price")), equalTo("3.3"));
View Full Code Here

   
    map2.put("map3", map3);
    map2.put("map4", map4);
    foo.setMap2(map2);
   
    Model model = new ModelMock();
    model.put("foo", foo);
   
    System.out.println(o.find(model, "foo.bar.info"));
    System.out.println(o.find(model, "foo.bar.info"));
    System.out.println(o.find(model, "foo.bar.serialNumber"));
    System.out.println(o.find(model, "foo.bar.price"));
View Full Code Here

TOP

Related Classes of com.firefly.template.Model

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.