Package com.xfltr.hapax

Examples of com.xfltr.hapax.Template


import com.xfltr.hapax.TemplateDictionary;
import com.xfltr.hapax.TemplateException;

class HelloWorldExample {
  public static void main(String[] args) throws TemplateException {
    Template tmpl = Template.parse("Hello, {{WORLD:h}}");
    TemplateDictionary dict = TemplateDictionary.create();
    dict.put("WORLD", "Iapetus");
    System.out.println(tmpl.renderToString(dict));
  }
View Full Code Here


    // as paths originating at the root of the
    // template directory rather than relative to the current template's path.
    //
    // In both of these cases, we ignore the path of the current template.
    //
    final Template template;
    String search_filename;
    if (PathUtil.isAbsolute(include_filename)) {
      // TODO: "/html" is an exceptional case.
      include_filename =
          PathUtil.join("/", PathUtil.makeRelative("/html", include_filename));
      template = context.getLoader().getTemplate(include_filename);
      search_filename = include_filename;
    } else {
      // TODO: design-pattern-needed hack.  Context should know how to get this
      // template.
      template = context.getLoader().getTemplate(include_filename,
                                                 context.getTemplateDirectory());
      if (context.getTemplateDirectory() != null) {
        search_filename =
            PathUtil.join(context.getTemplateDirectory(), include_filename);
      } else {
        search_filename =
            PathUtil.join("", include_filename);
      }
    }

    // Create an entry in the data dictionary for every template we've processed
    // already.  This allows us to detect infinite loops.
    String warning_flag = "__already__included__" + search_filename;
    if (dict.contains(warning_flag)) {
      throw new CyclicIncludeException(
          "Cyclic include loop detected: " + search_filename
          + " has been included multiple times.");
    } else {
      dict.put(warning_flag, "");
    }

    template.render(dict, collector);
  }
View Full Code Here

TOP

Related Classes of com.xfltr.hapax.Template

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.