Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroupDir


  @Test public void testSubdirWithSubtemplate() throws Exception {
    // /randomdir/a and /randomdir/subdir/b
    String dir = getRandomDir();
    writeFile(dir+"/subdir", "a.st", "a(x) ::= \"<x:{y|<y>}>\"");
    STGroup group = new STGroupDir(dir);
    ST st = group.getInstanceOf("/subdir/a");
    st.add("x", new String[] {"a", "b"});
    assertEquals("ab", st.render());
  }
View Full Code Here


    writeFile(dir, "a.st", "a(x) ::= <<foo>>");
        String groupFile =
            "b() ::= \"bar\"\n"+
            "c() ::= \"duh\"\n";
        writeFile(dir, "group.stg", groupFile);
        STGroup group = new STGroupDir(dir);
    assertEquals("foo", group.getInstanceOf("a").render());
    assertEquals("bar", group.getInstanceOf("/group/b").render());
    assertEquals("duh", group.getInstanceOf("/group/c").render());
    }
View Full Code Here

  @Test public void testSubSubdir() throws Exception {
        // /randomdir/a and /randomdir/subdir/b
        String dir = getRandomDir();
    writeFile(dir,              "a.st", "a(x) ::= <<foo>>");
    writeFile(dir+"/sub1/sub2", "b.st", "b() ::= \"bar\"");
        STGroup group = new STGroupDir(dir);
        ST st1 = group.getInstanceOf("a");
        ST st2 = group.getInstanceOf("/sub1/sub2/b");
        String expected = "foobar";
        String result = st1.render()+st2.render();
        assertEquals(expected, result);
    }
View Full Code Here

    writeFile(dir, "a.st", "a(x) ::= <<foo>>");
        String groupFile =
            "b() ::= \"bar\"\n"+
            "c() ::= \"duh\"\n";
        writeFile(dir, "subdir/group.stg", groupFile);
        STGroup group = new STGroupDir(dir);
        ST st1 = group.getInstanceOf("a");
        ST st2 = group.getInstanceOf("subdir/group/b");
        ST st3 = group.getInstanceOf("subdir/group/c");
        String expected = "foobarduh";
        String result = st1.render()+st2.render()+st3.render();
        assertEquals(expected, result);
    }
View Full Code Here

        String dir = getRandomDir();
        String a = "a() ::= << <b()> >>\n";
        String b = "b(x=\"foo\") ::= \"<x>\"\n";
        writeFile(dir, "a.st", a);
        writeFile(dir, "b.st", b);
        STGroup group = new STGroupDir(dir);
        ST st = group.getInstanceOf("a");
        String expected = " foo ";
        String result = st.render();
        assertEquals(expected, result);
    }
View Full Code Here

        String groupFile =
            "b() ::= \"group file b\"\n";
        writeFile(dir, "group.stg", groupFile);

        STGroup group1 = new STGroupDir(dir);
        ST st = group1.getInstanceOf("group/a"); // can't see
        assertEquals(null, st);
    }
View Full Code Here

      "a(x) ::= <<foo>>\n";
    String b =
      "b() ::= <<bar>>\n";
    writeFile(dir, "a.st", a);
    writeFile(dir, "b.st", b);
    STGroup group = new STGroupDir(dir);
    group.load(); // force load
    ST st = group.getInstanceOf("a");
    int originalHashCode = System.identityHashCode(st);
    group.unload(); // blast cache
    st = group.getInstanceOf("a");
    int newHashCode = System.identityHashCode(st);
    assertEquals(originalHashCode==newHashCode, false); // diff objects
    String expected = "foo";
    String result = st.render();
    assertEquals(expected, result);
    st = group.getInstanceOf("b");
    expected = "bar";
    result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

     * @param account the user account that has had its password reset
     * @param locale the locale of the user who reset the password
     * @return The message body as a string.
     */
    private String formatBody(URL resetUrl, ILocalAccountPerson account, Locale locale) {
        final STGroup group = new STGroupDir(templateDir, '$', '$');
        final ST template = group.getInstanceOf(templateName);

        String name = findDisplayNameFromLocalAccountPerson(account);
        template.add("displayName", name);
        template.add("url", resetUrl.toString());

View Full Code Here

  private STGroup group;
  private String path;

  public StringTemplateEngine(String templateFolder) {
    path = templateFolder;
    group = new STGroupDir(templateFolder);
  }
View Full Code Here

  public static void setLocale(Locale locale) {
    ErrorManager.locale = locale;
    String language = locale.getLanguage();
    String fileName = "org/antlr/tool/templates/messages/languages/"+language+".stg";
    try {
      messages = new STGroupFile(fileName);
    }
    catch (IllegalArgumentException iae) {
      if ( language.equals(Locale.US.getLanguage()) ) {
        rawError("ANTLR installation corrupted; cannot find English messages file "+fileName);
        panic();
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STGroupDir

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.