Package org.apache.abdera.i18n.templates

Examples of org.apache.abdera.i18n.templates.HashMapContext


        System.out.println(template.expand(map));
    }

    // Using a HashMap based context
    private static void exampleWithHashMapContext() {
        HashMapContext context = new HashMapContext();
        context.put("user", "james");
        context.put("categories", new String[] {"a", "b", "c"});
        context.put("foo", "abc");
        context.put("bar", "xyz");
        System.out.println(template.expand(context));
    }
View Full Code Here


public class RouteTest extends Assert {
  @Test
  public void testSimpleRoute() throws Exception {
    Route route = new Route("feed", "/:collection");
   
    HashMapContext ctx = new HashMapContext();
    ctx.put("collection", "test");
    assertEquals("/test", route.expand(ctx));
   
    assertTrue(route.match("/foo"));
    assertFalse(route.match("/foo/test"));
    assertFalse(route.match("foo"));
View Full Code Here

  }
  @Test
  public void testStaticRoute() throws Exception {
    Route route = new Route("feed", "/feed");
   
    HashMapContext ctx = new HashMapContext();
    assertEquals("/feed", route.expand(ctx));
   
    assertTrue(route.match("/feed"));
    assertFalse(route.match("/feed/test"));
    assertFalse(route.match("feed"));
View Full Code Here

 
  @Test
  public void testTwoPathRoute() throws Exception {
    Route route = new Route("entry", "/:collection/:entry");
   
    HashMapContext ctx = new HashMapContext();
    ctx.put("collection", "c");
    ctx.put("entry", "e");
    assertEquals("/c/e", route.expand(ctx));
   
    assertFalse(route.match("/foo"));
    assertTrue(route.match("/foo/test"));
    assertFalse(route.match("foo"));
View Full Code Here

  public void testTwoPathRouteWithSubstitution() throws Exception {
    Map<String, String> defaults = new HashMap<String,String>();
    defaults.put("collection", "c");
    Route route = new Route("entry", "/:collection/:entry", defaults, null);
   
    HashMapContext ctx = new HashMapContext();
    ctx.put("entry", "e");
    assertEquals("/c/e", route.expand(ctx));
  }
View Full Code Here

  @Test
  public void testDashedRoute() throws Exception {
    Route route = new Route("entry", ":collection/:entry-:foo");
   
    HashMapContext ctx = new HashMapContext();
    ctx.put("collection", "c");
    ctx.put("entry", "e");
    ctx.put("foo", "f");
    assertEquals("c/e-f", route.expand(ctx));
   
    assertTrue(route.match("1/2-3"));
    assertFalse(route.match("1/2-"));
    assertFalse(route.match("1/-"));
View Full Code Here

  public void testDashedRouteWithSubstitution() throws Exception {
    Map<String, String> defaults = new HashMap<String,String>();
    defaults.put("foo", "f");
    Route route = new Route("entry", ":collection/:entry-:foo", defaults, null);
   
    HashMapContext ctx = new HashMapContext();
    ctx.put("collection", "c");
    ctx.put("entry", "e");
    assertEquals("c/e-f", route.expand(ctx));
   
    assertTrue(route.match("1/2-3"));
    assertFalse(route.match("1/2-"));
    assertFalse(route.match("1/-"));
View Full Code Here

  @SuppressWarnings("unchecked")
  private Context getContext(Object param) {
    Context context = null;
    if (param != null) {
      if (param instanceof Map) {
        context = new HashMapContext((Map<String,Object>)param, true);
      } else if (param instanceof Context) {
        context = (Context)param;
      } else {
        context = new ObjectContext(param,true);
      }
View Full Code Here

  @Test
  public void test1() throws Exception {
    String t = "http://bitworking.org/news/{entry}";
    String e = "http://bitworking.org/news/RESTLog_Specification";
    HashMapContext c = new HashMapContext();
    c.put("entry", "RESTLog_Specification");
    eval(t,e,c);
  }
View Full Code Here

 
  @Test
  public void test2() throws Exception {
    String t = "http://example.org/wiki/{entry=FrontPage}";
    String e = "http://example.org/wiki/FrontPage";
    HashMapContext c = new HashMapContext();
    eval(t,e,c);
  }
View Full Code Here

TOP

Related Classes of org.apache.abdera.i18n.templates.HashMapContext

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.