You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by vi...@apache.org on 2012/08/25 02:52:29 UTC
svn commit: r1377167 - in /incubator/oozie/trunk: ./
core/src/main/java/org/apache/oozie/util/ core/src/main/resources/
core/src/test/java/org/apache/oozie/util/ docs/src/site/twiki/
Author: virag
Date: Sat Aug 25 00:52:29 2012
New Revision: 1377167
URL: http://svn.apache.org/viewvc?rev=1377167&view=rev
Log:
OOZIE-963 Add new EL function to replace all instances of a sub-string with another one (kamrul via virag)
Modified:
incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
incubator/oozie/trunk/release-log.txt
Modified: incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java?rev=1377167&r1=1377166&r2=1377167&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java (original)
+++ incubator/oozie/trunk/core/src/main/java/org/apache/oozie/util/ELConstantsFunctions.java Sat Aug 25 00:52:29 2012
@@ -95,6 +95,30 @@ public class ELConstantsFunctions {
}
/**
+ * Replace each occurrence of regular expression match in the first string
+ * with the <code>replacement</code> string. This EL function utilizes the
+ * java String class replaceAll method. For more details please see
+ *
+ * <code>http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)</code>
+ *
+ * @param src source string.
+ * @param regex the regular expression to which this string is to be
+ * matched. null means no replacement.
+ * @param replacement - the string to be substituted for each match. If
+ * null, it will considered as ""
+ * @return the replaced string.
+ */
+ public static String replaceAll(String src, String regex, String replacement) {
+ if (src != null && regex != null) {
+ if (replacement == null) {
+ replacement = "";
+ }
+ return src.replaceAll(regex, replacement);
+ }
+ return src;
+ }
+
+ /**
* Return the trimmed version of the given string.
*
* @param input string to be trimmed
Modified: incubator/oozie/trunk/core/src/main/resources/oozie-default.xml
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/main/resources/oozie-default.xml?rev=1377167&r1=1377166&r2=1377167&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/main/resources/oozie-default.xml (original)
+++ incubator/oozie/trunk/core/src/main/resources/oozie-default.xml Sat Aug 25 00:52:29 2012
@@ -453,6 +453,7 @@
<value>
firstNotNull=org.apache.oozie.util.ELConstantsFunctions#firstNotNull,
concat=org.apache.oozie.util.ELConstantsFunctions#concat,
+ replaceAll=org.apache.oozie.util.ELConstantsFunctions#replaceAll,
trim=org.apache.oozie.util.ELConstantsFunctions#trim,
timestamp=org.apache.oozie.util.ELConstantsFunctions#timestamp,
urlEncode=org.apache.oozie.util.ELConstantsFunctions#urlEncode,
Modified: incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java?rev=1377167&r1=1377166&r2=1377167&view=diff
==============================================================================
--- incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java (original)
+++ incubator/oozie/trunk/core/src/test/java/org/apache/oozie/util/TestELConstantsFunctions.java Sat Aug 25 00:52:29 2012
@@ -43,6 +43,16 @@ public class TestELConstantsFunctions ex
assertEquals("", ELConstantsFunctions.concat(null, null));
}
+ public void testReplaceAll() {
+ assertEquals("aefefd", ELConstantsFunctions.replaceAll("abcbcd", "bc", "ef"));
+ assertEquals("d1 d2 d3", ELConstantsFunctions.replaceAll("d1,d2,d3", ",", " "));
+ assertEquals("ayyycd", ELConstantsFunctions.replaceAll("abcbcd", "bcb", "yyy"));
+ assertEquals("acd", ELConstantsFunctions.replaceAll("abcbcd", "bcb", ""));
+ assertEquals(null, ELConstantsFunctions.replaceAll(null, "bcb", "yyy"));
+ assertEquals("abcbcd", ELConstantsFunctions.replaceAll("abcbcd", null, "XYZ"));
+ assertEquals("acd", ELConstantsFunctions.replaceAll("abcbcd", "bcb", null));
+ }
+
public void testTimestamp() throws Exception {
String s = ELConstantsFunctions.timestamp();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
Modified: incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki?rev=1377167&r1=1377166&r2=1377167&view=diff
==============================================================================
--- incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki (original)
+++ incubator/oozie/trunk/docs/src/site/twiki/WorkflowFunctionalSpec.twiki Sat Aug 25 00:52:29 2012
@@ -1553,6 +1553,10 @@ string. This is the common behavior when
It returns the concatenation of 2 strings. A string with =null= value is considered as an empty string.
+*String replaceAll(String src, String regex, String replacement)*
+
+Replace each occurrence of regular expression match in the first string with the =replacement= string and return the replaced string. A 'regex' string with =null= value is considered as no change. A 'replacement' string with =null= value is consider as an empty string.
+
*String trim(String s)*
It returns the trimmed value of the given string. A string with =null= value is considered as an empty string.
Modified: incubator/oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/incubator/oozie/trunk/release-log.txt?rev=1377167&r1=1377166&r2=1377167&view=diff
==============================================================================
--- incubator/oozie/trunk/release-log.txt (original)
+++ incubator/oozie/trunk/release-log.txt Sat Aug 25 00:52:29 2012
@@ -1,5 +1,6 @@
-- Oozie 3.3.0 release (trunk - unreleased)
+OOZIE-963 Add new EL function to replace all instances of a sub-string with another one (kamrul via virag)
OOZIE-969 Unit tests in TestStatusTransitService failing due to change in CoordKillX (mona via virag)
OOZIE-965 Allow the timezone attribute in coordinator jobs to use a format like GMT-#### (rkanter via tucu)
OOZIE-848 Bulk Monitoring API - Consolidated view of jobs (mona via virag)