tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/4] incubator-tamaya git commit: TAMAYA-149: Fixed invalid return on URL resolver. Added possibility to replace unresolved values with just an empty String as return value.
Date Thu, 05 May 2016 17:04:53 GMT
TAMAYA-149: Fixed invalid return on URL resolver. Added possibility to replace unresolved values
with just an empty String as return value.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/dabb1b70
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/dabb1b70
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/dabb1b70

Branch: refs/heads/master
Commit: dabb1b70c84ac4bbf7ce4da535a1df17e98d1107
Parents: 0f7661e
Author: anatole <anatole@apache.org>
Authored: Thu May 5 18:47:15 2016 +0200
Committer: anatole <anatole@apache.org>
Committed: Thu May 5 18:47:15 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/tamaya/resolver/Resolver.java   | 15 +++++++++++++--
 .../internal/DefaultExpressionEvaluator.java        | 16 ++++++++++++----
 .../internal/ExpressionResolutionFilter.java        |  2 +-
 .../tamaya/resolver/internal/URLResolver.java       |  3 +--
 .../tamaya/resolver/spi/ExpressionEvaluator.java    |  4 +++-
 5 files changed, 30 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dabb1b70/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
index e6375f7..cdd93e0 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
@@ -39,7 +39,7 @@ public final class Resolver {
      */
     public static String evaluateExpression(String key, String value){
         return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class)
-                .evaluateExpression(key, value);
+                .evaluateExpression(key, value, true);
     }
 
     /**
@@ -48,7 +48,18 @@ public final class Resolver {
      * @return the filtered/evaluated value, including null.
      */
     public static String evaluateExpression(String value){
+        return evaluateExpression(value, true);
+    }
+
+    /**
+     * Evaluates the current expression.
+     * @param value the value to be filtered/evaluated.
+     * @param maskNotFound if true, not found expression parts will be replaced vy surrounding
with [].
+     *                     Setting to false will replace the value with an empty String.
+     * @return the filtered/evaluated value, including null.
+     */
+    public static String evaluateExpression(String value, boolean maskNotFound){
         return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class)
-                .evaluateExpression(null, value);
+                .evaluateExpression(null, value, maskNotFound);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dabb1b70/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
index d1fa07f..4f49d53 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
@@ -120,10 +120,11 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator
{
      *
      * @param key the key to be filtered
      * @param value value to be analyzed for expressions
+     * @param maskUnresolved
      * @return the resolved value, or the input in case where no expression was detected.
      */
     @Override
-    public String evaluateExpression(String key, String value){
+    public String evaluateExpression(String key, String value, boolean maskUnresolved){
         if(value ==null){
             return null;
         }
@@ -146,7 +147,10 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator
{
                             break;
                         }
                         String subExpression = parseSubExpression(tokenizer, value);
-                        current.append(evaluateInternal(subExpression));
+                        String res = evaluateInternal(subExpression, maskUnresolved);
+                        if(res!=null) {
+                            current.append(res);
+                        }
                         break;
                     default:
                         current.append(token);
@@ -215,9 +219,11 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator
{
      * Evalutes the expression parsed, hereby checking for prefixes and trying otherwise
all available resolvers,
      * based on priority.
      * @param unresolvedExpression the parsed, but unresolved expression
+     * @param maskUnresolved if true, not found expression parts will be replaced vy surrounding
with [].
+     *                     Setting to false will replace the value with an empty String.
      * @return the resolved expression, or null.
      */
-    private String evaluateInternal(String unresolvedExpression) {
+    private String evaluateInternal(String unresolvedExpression, boolean maskUnresolved)
{
         String value = null;
         // 1 check for explicit prefix
         for(ExpressionResolver resolver:resolvers){
@@ -240,7 +246,9 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator
{
         }
         if(value==null){
             LOG.log(Level.WARNING, "Unresolvable expression encountered " + unresolvedExpression);
-            value = "?{" + unresolvedExpression + '}';
+            if(maskUnresolved){
+                value = "?{" + unresolvedExpression + '}';
+            }
         }
         return value;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dabb1b70/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
index e8bad93..20e2c7a 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
@@ -79,7 +79,7 @@ public class ExpressionResolutionFilter implements PropertyFilter {
     @Override
     public String filterProperty(String valueToBeFiltered, FilterContext context){
         LOG.finest("Resolving " + valueToBeFiltered + "(key=" + context.getKey() + ")");
-        return evaluator.evaluateExpression(context.getKey(), valueToBeFiltered);
+        return evaluator.evaluateExpression(context.getKey(), valueToBeFiltered, true);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dabb1b70/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/URLResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/URLResolver.java
b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/URLResolver.java
index b0b6331..32195f8 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/URLResolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/URLResolver.java
@@ -55,12 +55,11 @@ public final class URLResolver implements ExpressionResolver {
                 while ((inputLine = bufferedReader.readLine()) != null) {
                     builder.append(inputLine).append("\n");
                 }
-
                 return builder.toString();
             }
         } catch (Exception e) {
             LOG.log(Level.FINEST, "Could not resolve URL: " + expression, e);
-            return '['+expression+']';
+            return null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dabb1b70/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java
b/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java
index 1f7c861..e9e8aa4 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java
@@ -49,7 +49,9 @@ public interface ExpressionEvaluator {
      * Evaluates the current expression.
      * @param key the key, not null.
      * @param value the value to be filtered/evaluated.
+     * @param maskNotFound if true, not found expression parts will be replaced vy surrounding
with [].
+     *                     Setting to false will replace the value with an empty String.
      * @return the filtered/evaluated value, including null.
      */
-    String evaluateExpression(String key, String value);
+    String evaluateExpression(String key, String value, boolean maskNotFound);
 }


Mime
View raw message