Package net.sf.lapg.templates.api

Examples of net.sf.lapg.templates.api.EvaluationContext


    if (options.isUseDefaultTemplates()) {
      loaders.add(new ClassTemplateLoader(getClass().getClassLoader(), "net/sf/lapg/gen/templates", "utf8"));
    }

    TemplatesFacade env = new TemplatesFacadeExt(new GrammarNavigationFactory(options.getTemplateName()), loaders.toArray(new IBundleLoader[loaders.size()]), notifier);
    EvaluationContext context = new EvaluationContext(map);
    context.setVariable("util", new TemplateStaticMethods());
    context.setVariable("$", "lapg_gg.sym");
    env.executeTemplate(options.getTemplateName() + ".main", context, null, null);
  }
View Full Code Here


  }

  @Override
  public String toString() {
    ITemplate templ = (ITemplate) evaluationStrategy.loadEntity(templatePackage+".symbol", IBundleEntity.KIND_TEMPLATE, null);
    return evaluationStrategy.evaluate(templ, new EvaluationContext(this), null, null);
  }
View Full Code Here

    return templateId != null && templateId.indexOf('.') == -1 && !templateId.equals("base") ? context.getCurrent().getPackage() + "." + templateId : templateId;
  }

  @Override
  public Object evaluate(EvaluationContext context, IEvaluationStrategy env) throws EvaluationException {
    EvaluationContext callContext = selectExpr != null ? new EvaluationContext(env.evaluate(selectExpr, context, false), context) : context;
    String tid = templateId != null ? getTemplateId(context) : (String/* TODO */) env.evaluate(templateIdExpr, context, false);

    Object[] args = null;
    if (arguments != null) {
      args = new Object[arguments.length];
      for (int i = 0; i < arguments.length; i++) {
        args[i] = env.evaluate(arguments[i], context, false);
      }
    }

    IBundleEntity t = null;
    boolean isBase = false;
    IBundleEntity current = callContext.getCurrent();
    if (tid.equals("base")) {
      if (current != null) {
        isBase = true;
        t = current.getBase();
        if (t == null) {
View Full Code Here

  public String evaluate(ITemplate t, EvaluationContext context, Object[] arguments, ILocatedEntity referer) {
    if (t == null) {
      return "";
    }
    try {
      return t.apply(new EvaluationContext(context != null ? context.getThisObject() : null, context, t), this, arguments);
    } catch (EvaluationException ex) {
      fireError(t, ex.getMessage());
      return "";
    }
  }
View Full Code Here

      return "";
    }
  }

  public Object evaluate(IQuery t, EvaluationContext context, Object[] arguments, ILocatedEntity referer) throws EvaluationException {
    return t.invoke(new EvaluationContext(context != null ? context.getThisObject() : null, context, t), this, arguments);
  }
View Full Code Here

    XmlNode n = XmlModel.load(" <r><user name='jone'/>go<user name='go'/></r> ");

    TestTemplatesFacade env = new TestTemplatesFacade(new XmlNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), "net/sf/lapg/templates/test/ltp", "utf8"));

    // test 1
    String q = env.executeTemplate("xmltest.xmldo", new EvaluationContext(n), null, null);
    Assert.assertEquals("jone\ngo\n", q);
    env.assertEmptyErrors();

    q = env.executeTemplate("xmltest.selectit", new EvaluationContext(n), null, null);
    Assert.assertEquals("name=\"jone\"\n", q);
    env.assertEmptyErrors();
  }
View Full Code Here

    h.put("list", new String[] { "a", "b" });

    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));

    // test 1
    String q = env.executeTemplate("loop.loop1", new EvaluationContext(h), null, null);
    Assert.assertEquals("Hmm: \n\n0: a\n1: b\n\n", q);

    // test 2
    q = env.executeTemplate("loop.loop2", new EvaluationContext(h), null, null);
    Assert.assertEquals("\nHmm: \n\n0: a\n1: b\n\n", q);

    // test 3
    h.put("list", new String[] {});
    q = env.executeTemplate("loop.loop2", new EvaluationContext(h), null, null);
    Assert.assertEquals("\nHmm: \n\n\n", q);
  }
View Full Code Here

  // query.ltp
  public void testQuery() {
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));

    // test 1
    String q = env.executeTemplate("query.a", new EvaluationContext(new Object()), null, null);
    Assert.assertEquals("\n123\n", q);
  }
View Full Code Here

    // test 1
    String q = env.executeTemplate("dollar.testdollar", null, null, null);
    Assert.assertEquals("$ is dollar\n", q);

    // test 2
    EvaluationContext context = new EvaluationContext(null);
    context.setVariable("$", "My");
    q = env.executeTemplate("dollar.testdollarvar", context, null, null);
    Assert.assertEquals("My is value, $ is dollar\n", q);

    // test 3
    q = env.executeTemplate("dollar.testdollarindex", null, null, null);
View Full Code Here

  }

  // filter.ltp
  public void testMap() {
    TemplatesFacade env = new TestTemplatesFacade(new DefaultNavigationFactory(), new ClassTemplateLoader(getClass().getClassLoader(), TEMPLATES_LOCATION, TEMPLATES_CHARSET));
    EvaluationContext context = new EvaluationContext(null);
    context.setVariable("util", new DefaultStaticMethods());

    // test 1
    String q = env.executeTemplate("filter.map1", context, null, null);
    Assert.assertEquals("[nbsss -> a3,a45 -> 943q,ano -> yes]\n", q);
  }
View Full Code Here

TOP

Related Classes of net.sf.lapg.templates.api.EvaluationContext

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.