Search in sources :

Example 1 with AllowAllMatcher

use of org.beetl.core.resource.AllowAllMatcher in project beetl2.0 by javamonkey.

the class CompositeResourceLoaderTest method testSimple.

@Test
public void testSimple() throws Exception {
    Configuration conf = Configuration.defaultConfiguration();
    CompositeResourceLoader loader = new CompositeResourceLoader();
    String home = System.getProperty("user.dir");
    String path1 = home + "/src/test/resources/template/resourceloader/var1";
    String path2 = home + "/src/test/resources/template/resourceloader/var2";
    FileResourceLoader fileLoader1 = new FileResourceLoader(path1);
    FileResourceLoader fileLoader2 = new FileResourceLoader(path2);
    Map data = getData();
    // 根据id加载
    MapResourceLoader mapLoader = new MapResourceLoader(data);
    loader.addResourceLoader(new StartsWithMatcher("http:").withoutPrefix(), fileLoader2);
    loader.addResourceLoader(new StartsWithMatcher("db:").withoutPrefix(), mapLoader);
    loader.addResourceLoader(new AllowAllMatcher(), fileLoader1);
    GroupTemplate gt = new GroupTemplate(loader, conf);
    Template t = gt.getTemplate("/xxx.html");
    t.binding("a", "hello");
    String result = t.render();
    ;
    AssertJUnit.assertEquals("hellohello--file2:hello--db=hello", result);
}
Also used : StartsWithMatcher(org.beetl.core.resource.StartsWithMatcher) Configuration(org.beetl.core.Configuration) AllowAllMatcher(org.beetl.core.resource.AllowAllMatcher) FileResourceLoader(org.beetl.core.resource.FileResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) CompositeResourceLoader(org.beetl.core.resource.CompositeResourceLoader) Map(java.util.Map) HashMap(java.util.HashMap) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Configuration (org.beetl.core.Configuration)1 GroupTemplate (org.beetl.core.GroupTemplate)1 Template (org.beetl.core.Template)1 AllowAllMatcher (org.beetl.core.resource.AllowAllMatcher)1 CompositeResourceLoader (org.beetl.core.resource.CompositeResourceLoader)1 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)1 StartsWithMatcher (org.beetl.core.resource.StartsWithMatcher)1 Test (org.testng.annotations.Test)1