abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1203401 - in /abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates: MultiContext.java Template.java
Date Thu, 17 Nov 2011 22:47:11 GMT
Author: jmsnell
Date: Thu Nov 17 22:47:10 2011
New Revision: 1203401

URL: http://svn.apache.org/viewvc?rev=1203401&view=rev
Log:
api improvements

Modified:
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Template.java

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java?rev=1203401&r1=1203400&r2=1203401&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/MultiContext.java
Thu Nov 17 22:47:10 2011
@@ -58,7 +58,9 @@ public final class MultiContext 
           (Context)object :
           object instanceof Map ?
             new MapContext((Map<String,Object>)object) :
-            new ObjectContext(object)
+            object instanceof Supplier ?
+              new ObjectContext(((Supplier<?>)object).get()) :
+              new ObjectContext(object)
       );
       return this;
     }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Template.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Template.java?rev=1203401&r1=1203400&r2=1203401&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Template.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/Template.java
Thu Nov 17 22:47:10 2011
@@ -142,12 +142,20 @@ public final class Template 
               exp.evaluate(context));
       return pattern;
     }
+    
+    public String expand(Supplier<Context> context) {
+      if (context == null) return null;
+      return expand(context.get());
+    }
 
     /**
      * Expand the URI Template using the non-private fields and methods of the specified
object to resolve the template
      * tokens
      */
     public String expand(Object object) {
+      if (object == null) return null;
+      if (object instanceof Supplier)
+        object = ((Supplier<?>)object).get();
         return expand(object, false);
     }
 
@@ -156,7 +164,10 @@ public final class Template 
      * tokens. If isiri is true, IRI escaping rules will be used.
      */
     public String expand(Object object, boolean isiri) {
-        return expand(asContext(object,isiri));
+      if (object == null) return null;
+      if (object instanceof Supplier)
+        object = ((Supplier<?>)object).get();
+      return expand(asContext(object,isiri));
     }
 
     private String replace(String pattern, Expression exp, String value) {
@@ -190,6 +201,12 @@ public final class Template 
         return pattern;
     }
 
+    public static String expand(String pattern, Supplier<Context> context) {
+      checkNotNull(pattern);
+      checkNotNull(context);
+      return expand(pattern,context.get());
+    }
+    
     public static String expand(String pattern, Context context) {
         checkNotNull(context);
         checkNotNull(pattern);



Mime
View raw message