Tabnine Logo
GspParser
Code IndexAdd Tabnine to your IDE (free)

How to use
GspParser
in
com.wizzardo.tools.xml

Best Java code snippets using com.wizzardo.tools.xml.GspParser (Showing top 16 results out of 315)

origin: wizzardo/http

protected RenderableList prepareView(String view, String offset) {
  String template = resourceTools.getResourceAsString(view);
  if (template == null)
    throw new IllegalArgumentException("view '" + view + "' not found");
  String dir = view.substring(0, view.lastIndexOf("/") + 1);
  RenderableList l = new RenderableList();
  Node html = new GspParser().parse(template);
  Set<String> imports = new HashSet<>();
  readImports(html, imports);
  Node layoutTag = html.get("html/head/meta[@name=layout]");
  if (layoutTag != null) {
    layoutTag.parent().children().remove(layoutTag);
    String layoutContent = resourceTools.getResourceAsString("views/layouts/" + layoutTag.attr("content") + ".gsp");
    if (layoutContent == null)
      throw new IllegalArgumentException("Layout '" + layoutTag.attr("content") + "' not found");
    Node layout = new GspParser().parse(layoutContent);
    readImports(layout, imports);
    for (Decorator decorator : DependencyFactory.get(DecoratorLib.class).list()) {
      decorator.decorate(html, layout);
    }
    html = layout;
  }
  prepare(html.children(), l, dir, offset, imports);
  return l;
}
origin: wizzardo/http

default RenderableList prepare(String html) {
  Node n = new GspParser().parse(html);
  RenderableList l = new RenderableList();
  new ViewRenderingService().prepare(n.children(), l, "", "");
  return l;
}
origin: wizzardo/tools

@Test
public void gsp_comment_2() throws IOException {
  String s = "" +
      "<div %{--foo=\"${bar}\"--}%>\n" +
      "    \n" +
      "</div>\n";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(0, div.children().size());
  Assert.assertEquals(0, div.attributes().size());
}
origin: wizzardo/tools

@Test
public void gsp_4() throws IOException {
  String s = "<div><script>\n" +
      "   var a\n" +
      "   for(var i=0; i<10;i++) {\n" +
      "       a+=i;" +
      "   }\n" +
      "</script></div>";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals(1, div.children().size());
  Node script = div.children.get(0);
  Assert.assertEquals("var a\n" +
      "   for(var i=0; i<10;i++) {\n" +
      "       a+=i;" +
      "   }\n", script.text());
}
origin: wizzardo/http

  @Test
  public void test_exceptions() {
    Node n = new GspParser().parse("<div><g:if test=\"${flag}\">text</g:if>error<g:else>foo</g:else></div>");
    try {
      new ViewRenderingService().prepare(n.children(), new RenderableList(), "", "");
      assert false;
    } catch (IllegalStateException e) {
      Assert.assertEquals("If tag must be before Else tag", e.getMessage());
    }

    n = new GspParser().parse("<div><g:if test=\"${flag}\">text</g:if>error<g:elseif test=\"${flag}\">foo</g:elseif></div>");
    try {
      new ViewRenderingService().prepare(n.children(), new RenderableList(), "", "");
      assert false;
    } catch (IllegalStateException e) {
      Assert.assertEquals("If tag must be before Else tag", e.getMessage());
    }
  }
}
origin: wizzardo/tools

@Test
public void gsp_comment_1() throws IOException {
  String s = "" +
      "<div>\n" +
      "    %{--<p>$test</p>--}%\n" +
      "</div>\n";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(1, div.children().size());
  Assert.assertEquals(0, div.attributes().size());
  Assert.assertEquals("%{--<p>$test</p>--}%", div.children().get(0).textOwn());
}
origin: wizzardo/tools

@Test
public void gsp_comment_3() throws IOException {
  String s = "" +
      "<div foo=\"bar%{--_$id--}%_0\">\n" +
      "    \n" +
      "</div>\n";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(0, div.children().size());
  Assert.assertEquals(1, div.attributes().size());
  Assert.assertEquals("bar_0", div.attr("foo"));
}
origin: wizzardo/http

  @Test()
  public void test_ignore_comments() {
    String gsp = "<div>\n" +
        "    before\n" +
        "    %{--<p>text</p>--}%\n" +
        "    after\n" +
        "</div>";

    RenderableList renderable = new RenderableList();
    new ViewRenderingService().prepare(new GspParser().parse(gsp).children(), renderable, "", "");
    Assert.assertEquals("<div>\n" +
        "    before\n" +
        "    after\n" +
        "</div>\n", renderable.get(null).toString());
  }
}
origin: wizzardo/tools

@Test
public void gsp_1() throws IOException {
  String s = "<div><g:textField name=\"${it.key}\" placeholder=\"${[].collect({it})}\"/></div>";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(1, div.children().size());
  Node textField = div.children().get(0);
  Assert.assertEquals("g:textField", textField.name());
  Assert.assertEquals(0, textField.children().size());
  Assert.assertEquals(2, textField.attributes().size());
  Assert.assertEquals("${it.key}", textField.attr("name"));
  Assert.assertEquals("${[].collect({it})}", textField.attr("placeholder"));
}
origin: wizzardo/tools

@Test
public void gsp_2() throws IOException {
  String s = "<div><g:textField name=\"${it.key}\" placeholder=\"${String.valueOf(it.getValue()).replace(\"\\\"\", \"\")}\"/></div>";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(1, div.children().size());
  Node textField = div.children().get(0);
  Assert.assertEquals("g:textField", textField.name());
  Assert.assertEquals(0, textField.children().size());
  Assert.assertEquals(2, textField.attributes().size());
  Assert.assertEquals("${it.key}", textField.attr("name"));
  Assert.assertEquals("${String.valueOf(it.getValue()).replace(\"\\\"\", \"\")}", textField.attr("placeholder"));
}
origin: wizzardo/tools

@Test
public void gsp_3() throws IOException {
  String s = "<div id=\"${id}\"><span>foo:</span>${foo}</div>";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(2, div.children().size());
  Assert.assertEquals(1, div.attributes().size());
  Assert.assertEquals("${id}", div.attr("id"));
  Node span = div.children().get(0);
  Assert.assertEquals("span", span.name());
  Assert.assertEquals(1, span.children().size());
  Assert.assertEquals("foo:", span.text());
  Node foo = div.children().get(1);
  Assert.assertEquals("${foo}", foo.text());
}
origin: wizzardo/tools

@Test
public void gsp_page() throws IOException {
  String s = "<%@ page contentType=\"text/html;charset=UTF-8\" %>\n" +
      "<!DOCTYPE html>\n" +
      "<html>\n" +
      "<head>\n" +
      "    <title>title</title>\n" +
      "    %{-- comment! --}%\n" +
      "</head>" +
      "</html>";
  Node doc = new GspParser().parse(s);
  Assert.assertEquals(3, doc.children().size());
  Assert.assertEquals("%@", doc.get(0).name());
  Assert.assertEquals("!DOCTYPE", doc.get(1).name());
  Assert.assertEquals("html", doc.get(2).name());
}
origin: wizzardo/tools

  @Test
  public void gsp_page2() throws IOException {
    String s = "<%@ page contentType=\"text/html;charset=UTF-8\" %>\n" +
        "<!DOCTYPE html>\n" +
        "<html>\n" +
        "<head>\n" +
        "    <title>title</title>\n" +
        "</head>" +
        "</html>";
    Node doc = new GspParser().parse(s);
    Assert.assertEquals(3, doc.children().size());
    Assert.assertEquals("%@", doc.get(0).name());
    Assert.assertEquals("!DOCTYPE", doc.get(1).name());
    Assert.assertEquals("html", doc.get(2).name());
  }
}
origin: wizzardo/tools

@Test
public void gsp_comment_4() throws IOException {
  String s = "<div>\n" +
      "    before\n" +
      "    %{--<p>text</p>--}%\n" +
      "    after\n" +
      "</div>";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(3, div.children().size());
  Assert.assertEquals("before", div.get(0).text());
  Assert.assertEquals("%{--<p>text</p>--}%", div.get(1).text());
  Assert.assertEquals("after", div.get(2).text());
}
origin: wizzardo/tools

@Test
public void gsp_html_comment() throws IOException {
  String s = "<div>\n" +
      "    before\n" +
      "    <!--<p>text</p>-->\n" +
      "    after\n" +
      "</div>";
  Node root = new GspParser().parse(s);
  Node div = root.children().get(0);
  Assert.assertEquals("div", div.name());
  Assert.assertEquals(3, div.children().size());
  Assert.assertEquals("before", div.get(0).text());
  Assert.assertEquals("<!--<p>text</p>-->", div.get(1).text());
  Assert.assertEquals("after", div.get(2).text());
}
origin: wizzardo/http

  @Test
  public void render() {
    Node n = new GspParser().parse("<div style=\"width: 100px\"><a href=\"http://${host.toLowerCase()}\">yandex</a><br></div>");

    RenderableList l = new RenderableList();
    new ViewRenderingService().prepare(n.children(), l, "", "");


    Model model = new Model();
    model.put("host", "YA.ru");
    RenderResult result = l.get(model);

//        System.out.println(result.toString());
    Assert.assertEquals(3, l.size());
    Assert.assertEquals("<div style=\"width: 100px\">\n" +
        "    <a href=\"http://ya.ru\">\n" +
        "        yandex\n" +
        "    </a>\n" +
        "    <br/>\n" +
        "</div>\n", result.toString());
  }

com.wizzardo.tools.xmlGspParser

Javadoc

Created by wizzardo on 21.07.15.

Most used methods

  • <init>
  • parse

Popular in Java

  • Reading from database using SQL prepared statement
  • putExtra (Intent)
  • findViewById (Activity)
  • getContentResolver (Context)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now