Package httl

Examples of httl.Engine


  }

  @SuppressWarnings("unchecked")
  @Test
  public void testTemplate() throws Exception {
    Engine engine = Engine.getEngine(config);
    Loader loader = engine.getProperty("loader", Loader.class);
    assertEquals(MultiLoader.class, loader.getClass());
    Loader[] loaders = engine.getProperty("loaders", Loader[].class);
    assertEquals(ClasspathLoader.class, loaders[0].getClass());
    loader = engine.getProperty("loaders", ClasspathLoader.class);
    assertEquals(ClasspathLoader.class, loader.getClass());
    String[] suffixes = engine.getProperty("template.suffix", new String[] { ".httl" });
    List<String> list = loader.list(suffixes[0]);
    assertTrue(list.size() > 0);
    String dir = engine.getProperty("template.directory", "");
    if (dir.length() > 0 && dir.startsWith("/")) {
      dir = dir.substring(1);
    }
    if (dir.length() > 0 && ! dir.endsWith("/")) {
      dir += "/";
    }
    System.out.println(config + ": " + (data == null ? "null" : data.getClass().getSimpleName()) + " => " + templateName);
    String encoding = "UTF-8";
    if ("gbk.httl".equals(templateName)) {
      encoding = "GBK";
    }
    Engine _engine = engine;
    if ("extends_default.httl".equals(templateName)) {
      _engine = Engine.getEngine("httl-comment-extends.properties");
    }
    Template template = _engine.getTemplate("/templates/" + templateName, Locale.CHINA, encoding, data);
    UnsafeByteArrayOutputStream actualStream = new UnsafeByteArrayOutputStream();
    StringWriter actualWriter = new StringWriter();
    if ("extends_var.httl".equals(templateName)) {
      if (data instanceof Map) {
        ((Map<String, Object>) data).put("extends", "default.httl");
View Full Code Here


  @Parameterized.Parameters
  public static Collection<Object[]> prepareData() throws Exception {
    if (!profile)
      System.out.println("========httl-exception.properties========");
    Engine engine = Engine.getEngine("httl-exception.properties");

    String dir = engine.getProperty("template.directory", "");
    if (dir.length() > 0 && dir.startsWith("/")) {
      dir = dir.substring(1);
    }
    if (dir.length() > 0 && ! dir.endsWith("/")) {
      dir += "/";
View Full Code Here

  private String templateName;

  @Test
  public void testException() throws Exception {
    boolean profile = "true".equals(System.getProperty("profile"));
    Engine engine = Engine.getEngine("httl-exception.properties");
    String dir = engine.getProperty("template.directory", "");
    if (dir.length() > 0 && dir.startsWith("/")) {
      dir = dir.substring(1);
    }
    if (dir.length() > 0 && ! dir.endsWith("/")) {
      dir += "/";
    }
    URL url = this.getClass().getClassLoader().getResource(dir + "results/" + templateName + ".txt");
    if (url == null) {
      throw new FileNotFoundException("Not found file: " + dir + "results/" + templateName + ".txt");
    }
    File result = new File(url.getFile());
    if (! result.exists()) {
      throw new FileNotFoundException("Not found file: " + result.getAbsolutePath());
    }
    try {
      engine.getTemplate("/templates/" + templateName);
      fail(templateName);
    } catch (ParseException e) {
      e.printStackTrace();
      if (! profile) {
        String message = e.getMessage();
View Full Code Here

    String[] configs = new String[] { "httl.properties", "httl-comment.properties", "httl-comment-text.properties", "httl-comment-javassist.properties", "httl-comment-compile.properties", "httl-comment-interpret.properties", "httl-attribute.properties", "httl-velocity.properties" };
    for (String config : configs) {
     
      if (! "httl-comment.properties".equals(config)) continue; // 指定配置测试
     
      Engine engine = Engine.getEngine(config);
     
      Codec[] codecs = engine.getProperty("codecs", Codec[].class);
      String json = codecs[0].toString("context", model);

      Object[] maps = new Object[] {context, model, json, null};
      for (Object map : maps) {
       
        if (! (map instanceof Map)) continue; // 指定模型测试
       
        if ("httl-velocity.properties".equals(config)
            && (map == null || map instanceof String)) continue;
       
        String dir = engine.getProperty("template.directory", "");
        if (dir.length() > 0 && dir.startsWith("/")) {
          dir = dir.substring(1);
        }
        if (dir.length() > 0 && ! dir.endsWith("/")) {
          dir += "/";
View Full Code Here

TOP

Related Classes of httl.Engine

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.