Package org.apache.hadoop.yarn.webapp.hamlet

Examples of org.apache.hadoop.yarn.webapp.hamlet.Hamlet$SCRIPT


   
    this.modifiedQuery = q.toString();
   
    Boolean result = null;
    if (rewritten) {
      Script script = engine.createScript(this.modifiedQuery);
      try {
        result = (Boolean) script.execute(ctx);
      } catch (Exception e) {
        log.error("Error evaluating script: " + this.modifiedQuery + " against event" + eventFields.toString(), e);
      }
    } else {
      Expression expr = engine.createExpression(this.modifiedQuery);
View Full Code Here


            throw new NullPointerException("script and context must be non-null");
        }
        // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
        context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
        try {
            Script jexlScript = jexlEngine.createScript(script);
            JexlContext ctxt = new JexlContextWrapper(context);
            return jexlScript.execute(ctxt);
        } catch (Exception e) {
            throw new ScriptException(e.toString());
        }
    }
View Full Code Here

        // This is mandated by JSR-223
        if (script == null) {
            throw new NullPointerException("script must be non-null");
        }
        try {
            Script jexlScript = jexlEngine.createScript(script);
            return new JexlCompiledScript(jexlScript);
        } catch (Exception e) {
            throw new ScriptException(e.toString());
        }
    }
View Full Code Here

        if (ctx instanceof JexlContext) {
            jexlCtx = (JexlContext) ctx;
        } else {
            throw new SCXMLExpressionException(ERR_CTX_TYPE);
        }
        Script jexlScript = null;
        try {
            final JexlContext effective = getEffectiveContext(jexlCtx);
            effective.setEvaluatingLocation(true);
            jexlScript = getJexlEngine().createScript(script);
            return jexlScript.execute(effective);
        } catch (Exception e) {
            String exMessage = e.getMessage() != null ? e.getMessage() : e.getClass().getCanonicalName();
            throw new SCXMLExpressionException("evalScript('" + script + "'): " + exMessage, e);
        }
    }
View Full Code Here

  public boolean filterMatchesEntry(String filter, FeedEntry entry) throws FeedEntryFilterException {
    if (StringUtils.isBlank(filter)) {
      return true;
    }

    Script script = null;
    try {
      script = ENGINE.createScript(filter);
    } catch (JexlException e) {
      throw new FeedEntryFilterException("Exception while parsing expression " + filter, e);
    }

    JexlContext context = new MapContext();
    context.set("title", Jsoup.parse(entry.getContent().getTitle()).text().toLowerCase());
    context.set("author", entry.getContent().getAuthor().toLowerCase());
    context.set("content", Jsoup.parse(entry.getContent().getContent()).text().toLowerCase());
    context.set("url", entry.getUrl().toLowerCase());

    Callable<Object> callable = script.callable(context);
    Future<Object> future = executor.submit(callable);
    Object result = null;
    try {
      result = future.get(500, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
View Full Code Here

import static org.apache.hadoop.yarn.webapp.hamlet.HamletSpec.*;

public class TestHamlet {

  @Test public void testHamlet() {
    Hamlet h = newHamlet().
        title("test").
        h1("heading 1").
        p("#id.class").
          b("hello").
          em("world!")._().
        div("#footer").
          _("Brought to you by").
          a("http://hostname/", "Somebody")._();

    PrintWriter out = h.getWriter();
    out.flush();
    assertEquals(0, h.nestLevel);
    verify(out).print("<title");
    verify(out).print("test");
    verify(out).print("</title>");
View Full Code Here

    verify(out).print("</div>");
    verify(out, never()).print("</p>");
  }

  @Test public void testTable() {
    Hamlet h = newHamlet().
        title("test table").
        link("style.css");

    TABLE t = h.table("#id");

    for (int i = 0; i < 3; ++i) {
      t.tr().td("1").td("2")._();
    }
    t._();

    PrintWriter out = h.getWriter();
    out.flush();
    assertEquals(0, h.nestLevel);
    verify(out).print("<table");
    verify(out).print("</table>");
    verify(out, never()).print("</td>");
View Full Code Here

    verify(out, never()).print("</td>");
    verify(out, never()).print("</tr>");
  }

  @Test public void testEnumAttrs() {
    Hamlet h = newHamlet().
        meta_http("Content-type", "text/html; charset=utf-8").
        title("test enum attrs").
        link().$rel("stylesheet").
          $media(EnumSet.of(Media.screen, Media.print)).
          $type("text/css").$href("style.css")._().
        link().$rel(EnumSet.of(LinkType.index, LinkType.start)).
          $href("index.html")._();

    h.div("#content")._("content")._();

    PrintWriter out = h.getWriter();
    out.flush();
    assertEquals(0, h.nestLevel);
    verify(out).print(" media=\"screen, print\"");
    verify(out).print(" rel=\"start index\"");
  }
View Full Code Here

    verify(out).print(" media=\"screen, print\"");
    verify(out).print(" rel=\"start index\"");
  }

  @Test public void testScriptStyle() {
    Hamlet h = newHamlet().
        script("a.js").script("b.js").
        style("h1 { font-size: 1.2em }");

    PrintWriter out = h.getWriter();
    out.flush();
    assertEquals(0, h.nestLevel);
    verify(out, times(2)).print(" type=\"text/javascript\"");
    verify(out).print(" type=\"text/css\"");
  }
View Full Code Here

    verify(out, times(2)).print(" type=\"text/javascript\"");
    verify(out).print(" type=\"text/css\"");
  }

  @Test public void testPreformatted() {
    Hamlet h = newHamlet().
        div().
          i("inline before pre").
          pre().
            _("pre text1\npre text2").
            i("inline in pre").
            _("pre text after inline")._().
          i("inline after pre")._();

    PrintWriter out = h.getWriter();
    out.flush();
    assertEquals(5, h.indents);
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.yarn.webapp.hamlet.Hamlet$SCRIPT

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.