← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8985: Fixed links with htmlLinks method, taking into account links ending with a line break

 

------------------------------------------------------------
revno: 8985
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-11-13 09:00:12 +0100
message:
  Fixed links with htmlLinks method, taking into account links ending with a line break
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-10-03 16:07:42 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-11-13 08:00:12 +0000
@@ -1,9 +1,5 @@
 package org.hisp.dhis.system.util;
 
-import java.util.Collection;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 /*
  * Copyright (c) 2004-2012, University of Oslo
  * All rights reserved.
@@ -31,6 +27,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * @author Lars Helge Overland
  */
@@ -38,7 +38,7 @@
 {
     public static final TextUtils INSTANCE = new TextUtils();
     
-    private static final Pattern LINK_PATTERN = Pattern.compile( "((http://|https://|www\\.).+?)($| )" );
+    private static final Pattern LINK_PATTERN = Pattern.compile( "((http://|https://|www\\.).+?)($|\\n|\\r|\\r\\n| )" );
     
     /**
      * Performs the htmlNewline(String) and htmlLinks(String) methods against
@@ -49,28 +49,11 @@
      */
     public static String htmlify( String text )
     {
+        text = htmlLinks( text );
         text = htmlNewline( text );
-        text = htmlLinks( text );
         return text;
     }
-    
-    /**
-     * Replaces common newline characters like \n, \r, \r\n to the HTML line
-     * break tag <br>.
-     * 
-     * @param text the text to substitute.
-     * @return the substituted text.
-     */
-    public static String htmlNewline( String text )
-    {
-        if ( text == null || text.trim().isEmpty() )
-        {
-            return null;
-        }
         
-        return text.replaceAll( "(\n|\r|\r\n)", "<br>" );
-    }
-    
     /**
      * Substitutes links in the given text with valid HTML mark-up. For instance, 
      * http://dhis2.org is replaced with <a href="http://dhis2.org";>http://dhis2.org</a>,
@@ -104,6 +87,23 @@
         
         return matcher.appendTail( buffer ).toString();
     }
+
+    /**
+     * Replaces common newline characters like \n, \r, \r\n to the HTML line
+     * break tag <br>.
+     * 
+     * @param text the text to substitute.
+     * @return the substituted text.
+     */
+    public static String htmlNewline( String text )
+    {
+        if ( text == null || text.trim().isEmpty() )
+        {
+            return null;
+        }
+        
+        return text.replaceAll( "(\n|\r|\r\n)", "<br>" );
+    }
     
     /**
      * Gets the sub string of the given string. If the beginIndex is larger than