Package com.firefly.template

Examples of com.firefly.template.Model


    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(), is("fffff"));
    Assert.assertThat(o.find(model, "b['ccc']").toString(), is("ddd"));
    Assert.assertThat(o.find(model, "b['eee']").toString(), is("fff"));
View Full Code Here


    bar.setSerialNumber(23L);
    bar.setPrice(2.30);
    fooMap.put("bar2", bar);
    foo.setMap(fooMap);
   
    Model model = new ModelMock();
    model.put("foo", foo);
   
    ObjectNavigator o = ObjectNavigator.getInstance();
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.info")), is("bar1"));
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.serialNumber")), is("33"));
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.price")), is("3.3"));
View Full Code Here

    bar.setSerialNumber(23L);
    bar.setPrice(2.30);
    fooMap.put("bar2", bar);
    foo.setMap(fooMap);
   
    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

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

    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);
   
    Assert.assertThat(ObjectNavigator.getInstance().find(model, "a").toString(), is("fffff"));
    Assert.assertThat(ObjectNavigator.getInstance().find(model, "b['ccc']").toString(), is("ddd"));
    Assert.assertThat(ObjectNavigator.getInstance().find(model, "b['eee']").toString(), is("fff"));
    Assert.assertThat(ObjectNavigator.getInstance().find(model, "b[\"ccc\"]").toString(), is("ddd"));
View Full Code Here

    bar.setSerialNumber(23L);
    bar.setPrice(2.30);
    fooMap.put("bar2", bar);
    foo.setMap(fooMap);
   
    Model model = new ModelMock();
    model.put("foo", foo);
   
    ObjectNavigator o = ObjectNavigator.getInstance();
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.info")), is("bar1"));
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.serialNumber")), is("33"));
    Assert.assertThat(String.valueOf(o.find(model, "foo.bar.price")), is("3.3"));
View Full Code Here

    bar.setSerialNumber(23L);
    bar.setPrice(2.30);
    fooMap.put("bar2", bar);
    foo.setMap(fooMap);
   
    Model model = new ModelMock();
    model.put("foo", foo);
   
    System.out.println(ObjectNavigator.getInstance().find(model, "foo.bar.info"));
    System.out.println(ObjectNavigator.getInstance().find(model, "foo.bar.info"));
    System.out.println(ObjectNavigator.getInstance().find(model, "foo.bar.serialNumber"));
    System.out.println(ObjectNavigator.getInstance().find(model, "foo.bar.price"));
View Full Code Here

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

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

    com.firefly.template.View v = templateFactory.getView(page);
    if(v == null)
      return getDefaultErrorPage(status, content);
   
    ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
    Model model = new Model() {
      private Map<String, Object> map = new HashMap<String, Object>();

      @Override
      public void put(String key, Object object) {
        map.put(key, object);
      }

      @Override
      public Object get(String key) {
        return map.get(key);
      }

      @Override
      public void remove(String key) {
        map.remove(key);
      }

      @Override
      public void clear() {
        map.clear();
      }
    };
   
    try {
      model.put("#systemErrorMessage", URLDecoder.decode(content, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      log.error("url decode error", e);
    }
   
    try {
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.