dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19315
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8367: Impl subsitutions of newlines to HTML linebreaks in messages and interpretations
------------------------------------------------------------
revno: 8367
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-10-03 18:07:42 +0200
message:
Impl subsitutions of newlines to HTML linebreaks in messages and interpretations
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/readMessage.vm
--
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-06-06 14:10:19 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java 2012-10-03 16:07:42 +0000
@@ -33,7 +33,6 @@
/**
* @author Lars Helge Overland
- * @version $Id$
*/
public class TextUtils
{
@@ -42,6 +41,37 @@
private static final Pattern LINK_PATTERN = Pattern.compile( "((http://|https://|www\\.).+?)($| )" );
/**
+ * Performs the htmlNewline(String) and htmlLinks(String) methods against
+ * the given text.
+ *
+ * @param text the text to substitute.
+ * @return the substituted text.
+ */
+ public static String htmlify( String 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>,
* and www.dhis2.org is replaced with <a href="http://dhis2.org">www.dhis2.org</a>.
@@ -74,7 +104,7 @@
return matcher.appendTail( buffer ).toString();
}
-
+
/**
* Gets the sub string of the given string. If the beginIndex is larger than
* the length of the string, the empty string is returned. If the beginIndex +
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm 2012-09-30 17:45:22 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/interpretationFeed.vm 2012-10-03 16:07:42 +0000
@@ -6,7 +6,7 @@
<span class="grey">${format.formatDate( $ip.created )}</span>
</div>
<div class="interpretationText">
- ${ip.text}
+ $!dhisTextUtils.htmlify( ${ip.text} )
</div>
<div class="interpretationChart">
#if( $ip.chartInterpretation )
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/readMessage.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/readMessage.vm 2012-05-29 19:30:37 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/readMessage.vm 2012-10-03 16:07:42 +0000
@@ -60,7 +60,7 @@
<span class="bold" style="cursor:pointer" onclick="showSenderInfo( ${message.id}, ${message.sender.id} )">$encoder.htmlEncode( $message.sender.name )</span>
<span class="grey">$format.formatDate( $message.lastUpdated )</span>
-<p>$!dhisTextUtils.htmlLinks( $encoder.htmlEncode( $message.text ) )</p>
+<p>$!dhisTextUtils.htmlify( $encoder.htmlEncode( $message.text ) )</p>
<span id="metaData${message.id}" style="display:none">$!encoder.htmlEncode( $message.metaData )</span>
</div>
#end