当前位置: 首页>>代码示例>>Java>>正文


Java TemplateError类代码示例

本文整理汇总了Java中org.mvel2.templates.TemplateError的典型用法代码示例。如果您正苦于以下问题:Java TemplateError类的具体用法?Java TemplateError怎么用?Java TemplateError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TemplateError类属于org.mvel2.templates包,在下文中一共展示了TemplateError类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eval

import org.mvel2.templates.TemplateError; //导入依赖的package包/类
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
        if (preExpression != null) {
            MVEL.executeExpression(cPreExpression, ctx, factory);
        }


        if (next != null) {
            String namedTemplate = MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class);
            CompiledTemplate ct = runtime.getNamedTemplateRegistry().getNamedTemplate(namedTemplate);

            if (ct == null)
                throw new TemplateError("named template does not exist: " + namedTemplate);

            return next.eval(runtime, appender.append(String.valueOf(TemplateRuntime.execute(ct, ctx, factory, runtime.getNamedTemplateRegistry()))), ctx, factory);

//            return next.eval(runtime,
//                    appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory))), ctx, factory);
        } else {
            return appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory, runtime.getNamedTemplateRegistry())));
        }
    }
 
开发者ID:codehaus,项目名称:mvel,代码行数:22,代码来源:CompiledNamedIncludeNode.java

示例2: eval

import org.mvel2.templates.TemplateError; //导入依赖的package包/类
public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) {
    factory = new StackDelimiterResolverFactory(factory);
    if (cPreExpression != null) {
      MVEL.executeExpression(cPreExpression, ctx, factory);
    }


    if (next != null) {
      String namedTemplate = MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class);
      CompiledTemplate ct = runtime.getNamedTemplateRegistry().getNamedTemplate(namedTemplate);

      if (ct == null)
        throw new TemplateError("named template does not exist: " + namedTemplate);

      return next.eval(runtime, appender.append(String.valueOf(TemplateRuntime.execute(ct, ctx, factory, runtime.getNamedTemplateRegistry()))), ctx, factory);

//            return next.eval(runtime,
//                    appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory))), ctx, factory);
    }
    else {
      return appender.append(String.valueOf(TemplateRuntime.execute(runtime.getNamedTemplateRegistry().getNamedTemplate(MVEL.executeExpression(cIncludeExpression, ctx, factory, String.class)), ctx, factory, runtime.getNamedTemplateRegistry())));
    }
  }
 
开发者ID:osswangxining,项目名称:mvel-jsr223,代码行数:24,代码来源:CompiledNamedIncludeNode.java

示例3: Template

import org.mvel2.templates.TemplateError; //导入依赖的package包/类
public Template(URL url) {
  String file = url.getFile();
  this.name = file.substring(file.lastIndexOf('/') + 1);
  try {
    this.baseURI = url.toURI().toString();
    this.compiled = loadCompiled(url);
  } catch (URISyntaxException e) {
    throw new TemplateError("Could not load template from template " + url, e);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-codegen,代码行数:11,代码来源:Template.java

示例4: loadCompiled

import org.mvel2.templates.TemplateError; //导入依赖的package包/类
/**
 * Load a template given its {@code templateURL}.
 *
 * @param templateURL the template url
 * @return the compiled template
 */
public static CompiledTemplate loadCompiled(URL templateURL) {
  CompiledTemplate template = templateCache.get(templateURL);
  if (template == null) {
    InputStream is = null;
    try {
      is = templateURL.openStream();
    } catch (IOException e) {
      throw new TemplateError("Could not load template from template " + templateURL, e);
    }
    template = loadCompiled(is);
    templateCache.put(templateURL, template);
  }
  return template;
}
 
开发者ID:vert-x3,项目名称:vertx-codegen,代码行数:21,代码来源:Template.java

示例5: testIncludeNamedNotFound

import org.mvel2.templates.TemplateError; //导入依赖的package包/类
@Test
public void testIncludeNamedNotFound() throws Exception {
  Template template = new Template(getClass().getResource("testtemplates/include_named_not_found.templ"));
  try {
    template.render(NULL_MODEL);
    fail("Was expecting to fail");
  } catch (TemplateError ignore) {
  }
}
 
开发者ID:vert-x3,项目名称:vertx-codegen,代码行数:10,代码来源:TemplateTest.java

示例6: render

import org.mvel2.templates.TemplateError; //导入依赖的package包/类
public String render(Model model, Map<String, Object> vars) {
  vars = new HashMap<>(vars);
  vars.put("options", options);
  vars.put("skipFile", false);
  vars.putAll(model.getVars());
  vars.putAll(ClassKind.vars());
  vars.putAll(MethodKind.vars());
  vars.putAll(Case.vars());

  TemplateRegistry registry = new SimpleTemplateRegistry() {
    @Override
    public CompiledTemplate getNamedTemplate(String name) {
      try {
        return super.getNamedTemplate(name);
      } catch (TemplateError err) {
        // Load error try to resolve from base uri
        try {
          URL url;
          if (name.startsWith("/")) {
            url = resolveURL(name.substring(1));
          } else {
            url = new URL(new URL(baseURI), name);
          }
          CompiledTemplate compiledTemplate = loadCompiled(url);
          addNamedTemplate(name, compiledTemplate);
          return compiledTemplate;
        } catch (Exception ex) {
          throw new TemplateError("Could not load template " + name + " from template " + baseURI, ex);
        }
      }
    }
  };

  ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
  try {
    // Be sure to have mvel classloader as parent during evaluation as it will need mvel classes
    // when generating code
    Thread.currentThread().setContextClassLoader(TemplateRuntime.class.getClassLoader());
    TemplateRuntime runtime = new TemplateRuntime(compiled.getTemplate(), registry, compiled.getRoot(), ".");
    String blah = (String) runtime.execute(new StringBuilder(), null, new MapVariableResolverFactory(vars));
    if (Boolean.TRUE.equals(vars.get("skipFile"))) {
      return null;
    }
    return blah;
  } finally {
    Thread.currentThread().setContextClassLoader(currentCL);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-codegen,代码行数:49,代码来源:Template.java


注:本文中的org.mvel2.templates.TemplateError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。