Author: carlos
Date: Wed Apr  5 13:22:33 2006
New Revision: 391781

URL: http://svn.apache.org/viewcvs?rev=391781&view=rev
Log:
[MSUREFIRE-86] Make surefire compile under Java 1.3

Modified:
    
maven/surefire/trunk/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
    
maven/surefire/trunk/surefire/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java

Modified: 
maven/surefire/trunk/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java?rev=391781&r1=391780&r2=391781&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
 (original)
+++ 
maven/surefire/trunk/surefire/src/main/java/org/apache/maven/surefire/report/XMLReporter.java
 Wed Apr  5 13:22:33 2006
@@ -267,6 +267,42 @@
     private static String escapeAttribute( String attribute )
     {
         // Shouldn't Xpp3Dom do this itself?
-        return attribute.replaceAll( "<", "&lt;" ).replaceAll( ">", "&gt;" );
+        String s = replaceAll( attribute, "<", "&lt;" );
+        s = replaceAll( s, ">", "&gt;" );
+        return s;
+        
     }
+
+    /**
+     * Replace all ocurrences of a value in a string. Same as Java 1.4 
String.replaceAll( String, String )
+     * 
+     * @param s the string to search into
+     * @param from original String to look for
+     * @param to String to change for
+     * @return the modified String
+     */
+    public static String replaceAll( String source, String pattern, String 
replace )
+    {
+        if ( ( source != null ) && ( pattern.length() > 0 ) )
+        {
+            final int len = pattern.length();
+            StringBuffer sb = new StringBuffer();
+            int found = -1;
+            int start = 0;
+
+            while ( ( found = source.indexOf( pattern, start ) ) != -1 )
+            {
+                sb.append( source.substring( start, found ) );
+                sb.append( replace );
+                start = found + len;
+            }
+
+            sb.append( source.substring( start ) );
+
+            return sb.toString();
+        }
+        else
+            return "";
+    }
+
 }

Modified: 
maven/surefire/trunk/surefire/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java
URL: 
http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java?rev=391781&r1=391780&r2=391781&view=diff
==============================================================================
--- 
maven/surefire/trunk/surefire/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java
 (original)
+++ 
maven/surefire/trunk/surefire/src/test/java/org/apache/maven/surefire/report/XMLReporterTest.java
 Wed Apr  5 13:22:33 2006
@@ -58,6 +58,22 @@
         reporter.testError( reportEntry, "", "" );
         assertResult( reporter, message );
     }
+    
+    public void testReplaceAll()
+    {
+        String s, from, to;
+        s = "";
+        from = "";
+        to = "";
+        String result = XMLReporter.replaceAll( s, from, to );
+        assertEquals( s.replaceAll( from, to ), result );
+
+        s = "xxfromyytozz";
+        from = "from";
+        to = "to";
+        result = XMLReporter.replaceAll( s, from, to );
+        assertEquals( s.replaceAll( from, to ), result );
+    }
 
     private void assertResult( XMLReporter reporter, String message )
     {


Reply via email to