Package httl

Examples of httl.Template


  public void setLogger(Logger logger) {
    this.logger = logger;
  }

  private Locale getLocale() {
    Template template = Context.getContext().getTemplate();
    if (template != null && template.getLocale() != null) {
      return template.getLocale();
    }
    Object locale = resolver.get("locale");
    if (locale instanceof Locale) {
      return (Locale) locale;
    }
View Full Code Here


    int i = name.indexOf('#');
    if (i > 0) {
      macro = name.substring(i + 1);
      name = name.substring(0, i);
    }
    Template template = Context.getContext().getTemplate();
    if (template != null) {
      if (StringUtils.isEmpty(encoding)) {
        encoding = template.getEncoding();
      }
      name = UrlUtils.relativeUrl(name, template.getName());
      if (locale == null) {
        locale = template.getLocale();
      }
    }
    if (StringUtils.isNotEmpty(extendsDirectory)) {
      name = extendsDirectory + name;
    }
    Template extend = engine.getTemplate(name, locale, encoding);
    if (StringUtils.isNotEmpty(macro)) {
      extend = extend.getMacros().get(macro);
    }
    if (template != null) {
      if (template == extend) {
        throw new IllegalStateException("The template " + template.getName() + " can not be recursive extending the self template.");
      }
View Full Code Here

  public Template render(Resource resource) throws IOException, ParseException {
    return render(IOUtils.readToString(resource.openReader()));
  }

  public Template render(byte[] source) throws IOException, ParseException {
    Template template = Context.getContext().getTemplate();
    if (template == null) {
      throw new IllegalArgumentException("display context template == null");
    }
    String encoding = template.getEncoding();
    return render(encoding == null ? new String(source) : new String(source, encoding));
  }
View Full Code Here

  public Template render(char[] source) throws IOException, ParseException {
    return render(new String(source));
  }

  public Template render(String source) throws IOException, ParseException {
    Template template = Context.getContext().getTemplate();
    if (template == null) {
      throw new IllegalArgumentException("display context template == null");
    }
    return engine.parseTemplate(source);
  }
View Full Code Here

    int i = name.indexOf('#');
    if (i > 0) {
      macro = name.substring(i + 1);
      name = name.substring(0, i);
    }
    Template template = Context.getContext().getTemplate();
    if (template != null) {
      if (StringUtils.isEmpty(encoding)) {
        encoding = template.getEncoding();
      }
      name = UrlUtils.relativeUrl(name, template.getName());
      if (locale == null) {
        locale = template.getLocale();
      }
    }
    Template include = engine.getTemplate(name, locale, encoding);
    if (StringUtils.isNotEmpty(macro)) {
      include = include.getMacros().get(macro);
    }
    if (template != null && template == include) {
      throw new IllegalStateException("The template " + template.getName() + " can not be recursive including the self template.");
    }
    return include;
View Full Code Here

  public Resource read(String name, Locale locale, String encoding) throws IOException {
    if (StringUtils.isEmpty(name)) {
      throw new IllegalArgumentException("display template name == null");
    }
    Template template = Context.getContext().getTemplate();
    if (template != null) {
      if (StringUtils.isEmpty(encoding)) {
        encoding = template.getEncoding();
      }
      name = UrlUtils.relativeUrl(name, template.getName());
      if (locale == null) {
        locale = template.getLocale();
      }
    }
    return engine.getResource(name, locale, encoding);
  }
View Full Code Here

    }
    return null;
  }

  public static Template getMacro(Template template, String name) {
    Template macro = template.getMacros().get(name);
    if (macro == null) {
      throw new IllegalStateException("No such macro " + name + "in template " + template.getName());
    }
    return macro;
  }
View Full Code Here

          }
        }
      }
    }
    assert(reference != null);
    Template template = (Template) reference.get();
    if (template == null || template.getLastModified() < lastModified) {
      synchronized (reference) { // reference lock
        template = (Template) reference.get();
        if (template == null || template.getLastModified() < lastModified) { // double check
          template = parseTemplate(resource, name, locale, encoding, args); // slowly
          reference.set(template);
        }
      }
    }
View Full Code Here

      if (templateFilter != null) {
        source = templateFilter.filter(resource.getName(), source);
      }
      Node root = templateParser.parse(source, 0);
      Map<String, Class<?>> parameterTypes = useRenderVariableType && args != null ? new DelegateMap<String, Class<?>>(new TypeMap(convertMap(args))) : null;
      Template template = translator.translate(resource, root, parameterTypes);
      if (logger != null && logger.isDebugEnabled()) {
        logger.debug("Parsed the template " + name + ", eslapsed: " + (System.currentTimeMillis() - start) + "ms.");
      }
      return template;
    } catch (ParseException e) {
View Full Code Here

   */
  public void inited() {
    if (importMacros != null && importMacros.length > 0) {
      for (String importMacro : importMacros) {
        try {
          Template importMacroTemplate = engine.getTemplate(importMacro);
          importMacroTemplates.putAll(importMacroTemplate.getMacros());
        } catch (Exception e) {
          throw new IllegalStateException(e.getMessage(), e);
        }
      }
    }
View Full Code Here

TOP

Related Classes of httl.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.