Return-Path: X-Original-To: apmail-ofbiz-commits-archive@www.apache.org Delivered-To: apmail-ofbiz-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D32CC99A6 for ; Wed, 4 Apr 2012 12:49:34 +0000 (UTC) Received: (qmail 18706 invoked by uid 500); 4 Apr 2012 12:49:34 -0000 Delivered-To: apmail-ofbiz-commits-archive@ofbiz.apache.org Received: (qmail 18679 invoked by uid 500); 4 Apr 2012 12:49:34 -0000 Mailing-List: contact commits-help@ofbiz.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ofbiz.apache.org Delivered-To: mailing list commits@ofbiz.apache.org Received: (qmail 18672 invoked by uid 99); 4 Apr 2012 12:49:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Apr 2012 12:49:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Apr 2012 12:49:33 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 46B1D2388847 for ; Wed, 4 Apr 2012 12:49:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1309360 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java Date: Wed, 04 Apr 2012 12:49:13 -0000 To: commits@ofbiz.apache.org From: adrianc@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120404124913.46B1D2388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 exprCache = UtilCache.createUtilCache("flexibleStringExpander.ExpressionCache"); protected static final FlexibleStringExpander nullExpr = new ConstSimpleElem(new char[0]); + /** + * Returns true if fse contains a String constant. + * @param fse The FlexibleStringExpander to test + * @return true if fse contains a String 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 true if fse contains an expression. + * @param fse The FlexibleStringExpander to test + * @return true if fse contains an expression + */ + public static boolean containsExpression(FlexibleStringExpander fse) { + return !(fse instanceof ConstSimpleElem); + } + + /** + * Returns true if fse contains a script. + * @param fse The FlexibleStringExpander to test + * @return true if fse 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 String. * Null expressions return null. * A null context argument will return the original expression.