ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r1309360 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java
Date Wed, 04 Apr 2012 12:49:13 GMT
Author: adrianc
Date: Wed Apr  4 12:49:12 2012
New Revision: 1309360

URL: http://svn.apache.org/viewvc?rev=1309360&view=rev
Log:
Added some static methods to FlexibleStringExpander that enable querying an expression about
its component parts.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java?rev=1309360&r1=1309359&r2=1309360&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java
(original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java
Wed Apr  4 12:49:12 2012
@@ -51,6 +51,55 @@ public abstract class FlexibleStringExpa
     protected static final UtilCache<Key, FlexibleStringExpander> exprCache = UtilCache.createUtilCache("flexibleStringExpander.ExpressionCache");
     protected static final FlexibleStringExpander nullExpr = new ConstSimpleElem(new char[0]);
 
+    /**
+     * Returns <code>true</code> if <code>fse</code> contains a <code>String</code>
constant.
+     * @param fse The <code>FlexibleStringExpander</code> to test
+     * @return <code>true</code> if <code>fse</code> contains a <code>String</code>
constant
+     */
+    public static boolean containsConstant(FlexibleStringExpander fse) {
+        if (fse instanceof ConstSimpleElem || fse instanceof ConstOffsetElem) {
+            return true;
+        }
+        if (fse instanceof Elements) {
+            Elements fseElements = (Elements) fse;
+            for (FlexibleStringExpander childElement : fseElements.childElems) {
+                if (containsConstant(childElement)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns <code>true</code> if <code>fse</code> contains an
expression.
+     * @param fse The <code>FlexibleStringExpander</code> to test
+     * @return <code>true</code> if <code>fse</code> contains an
expression
+     */
+    public static boolean containsExpression(FlexibleStringExpander fse) {
+        return !(fse instanceof ConstSimpleElem);
+    }
+
+    /**
+     * Returns <code>true</code> if <code>fse</code> contains a script.
+     * @param fse The <code>FlexibleStringExpander</code> to test
+     * @return <code>true</code> if <code>fse</code> contains a script
+     */
+    public static boolean containsScript(FlexibleStringExpander fse) {
+        if (fse instanceof ScriptElem) {
+            return true;
+        }
+        if (fse instanceof Elements) {
+            Elements fseElements = (Elements) fse;
+            for (FlexibleStringExpander childElement : fseElements.childElems) {
+                if (containsScript(childElement)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     /** Evaluate an expression and return the result as a <code>String</code>.
      * Null expressions return <code>null</code>.
      * A null <code>context</code> argument will return the original expression.



Mime
View raw message