1 package org.kuali.ole.util;
2
3 import org.kuali.ole.OLEConstants;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8
9
10
11
12
13
14
15 public class StringUtil {
16
17 public static String trimEmptyNullValues(String value){
18 if(value!=null){
19 value = value.trim();
20 if(value.equals("null")){
21 value = "";
22 }
23 }
24 return value;
25 }
26 public static String trimHashNullValues(String value){
27 if(value!=null){
28 value = value.trim();
29 if(value.equals("null")|| value.isEmpty()){
30 value = OLEConstants.DELIMITER_HASH;
31 }
32 }
33 return value;
34 }
35
36 public static String makeUrlClickable(List<String> protocolList, String content) {
37 content = content.replace(" ", " ");
38 StringBuffer result = new StringBuffer();
39 String clickableUrl = "";
40 int count = 0;
41 int lenth = content.length();
42 while (count < lenth) {
43 String textToScan = content.substring(count);
44 boolean urlFound = false;
45 int spaceIndex = -1;
46 String url = "";
47 for (String protocol : protocolList) {
48 if (textToScan.startsWith(protocol)) {
49 urlFound = true;
50 spaceIndex = textToScan.indexOf(" ");
51 if (spaceIndex > 0)
52 url = textToScan.substring(0, (spaceIndex));
53 else
54 url = textToScan.substring(0);
55 break;
56 }
57 }
58 if (urlFound) {
59 clickableUrl = "<a href='" + url + "' target='_blank'>" + url + "</a>";
60 count = count + url.length();
61 result.append(clickableUrl);
62 } else {
63 result.append(content.charAt(count));
64 count = count + 1;
65 }
66 }
67 return result.toString();
68
69 }
70 }