|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.sakaiproject.profile2.util.ProfileUtils
public class ProfileUtils
| Constructor Summary | |
|---|---|
ProfileUtils()
|
|
| Method Summary | ||
|---|---|---|
static String |
calculateMD5(String s)
Calculate an MD5 hash of a string |
|
static boolean |
checkContentTypeForProfileImage(String contentType)
Check content type against allowed types. |
|
static String |
convertDateForStatus(Date date)
Convert a date into a field like "just then, 2 minutes ago, 4 hours ago, yesterday, on sunday, etc" |
|
static String |
convertDateToString(Date date,
String format)
Convert a Date into a String according to format |
|
static Date |
convertStringToDate(String dateStr,
String format)
Convert a string into a Date object (reverse of above |
|
static byte[] |
createAvatar(byte[] imageData,
String mimeType)
Creates a square avatar image by taking a segment out of the centre of the original image and resizing to the appropriate dimensions |
|
static String |
createEventRef(String ref)
Creates a full profile event reference for a given reference |
|
static String |
generateUuid()
Generate a UUID |
|
static String |
getDayName(int day,
Locale locale)
Get the localised name of the day (ie Monday for en, Maandag for nl) |
|
static String |
getInformalFormatForMimeType(String mimeType)
Helper to get the informal format name that is used by ImageIO. |
|
static List<String> |
getListFromString(String str,
char separator)
Method to chop a String into it's parts based on the separator and return as a List. |
|
static String |
getSkypeMeURL(String skypeUsername)
Returns the SkypeMe URL for the specified Skype username. |
|
static Locale |
getUserPreferredLocale()
Gets the users preferred locale, either from the user's session or Sakai preferences and returns it This depends on Sakai's ResourceLoader. |
|
static Object |
getValueFromMapOrDefault(Map<?,?> map,
Object key,
Object defaultValue)
Method for getting a value from a map based on the given key, but if it does not exist, use the given default |
|
static String |
processHtml(String s)
Processes HTML and escapes evils tags like <script>, also converts newlines to proper HTML breaks. |
|
static
|
removeDuplicates(List<T> list)
Remove duplicates from a list, order is not retained. |
|
static
|
removeDuplicatesWithOrder(List<T> list)
Remove duplicates from a list, order is retained. |
|
static byte[] |
scaleImage(byte[] imageData,
int maxSize,
String mimeType)
Scale an image so it is fit within a give width and height, whilst maintaining its original proportions |
|
static String |
stripAndCleanHtml(String s)
Strips string of HTML, escaping anything that is left to return plain text. |
|
static String |
stripHtml(String s)
Strips string of HTML and returns plain text. |
|
static Date |
stripYear(Date date)
Strip the year from a given date (actually just sets it to 1) |
|
static String |
toProperCase(String input)
Convert a string to propercase. |
|
static String |
truncate(String s,
int maxNumOfChars,
boolean isHtml)
Trims text to the given maximum number of displayed characters. |
|
static String |
truncateAndAbbreviate(String s,
int maxNumOfChars,
boolean isHtml)
Trims and abbreviates text to the given maximum number of displayed characters (less 3 characters, in case "..." must be appended). |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ProfileUtils()
| Method Detail |
|---|
public static boolean checkContentTypeForProfileImage(String contentType)
contentType - string of the content type determined by some image parserpublic static String getInformalFormatForMimeType(String mimeType)
If no valid mapping is found, it will default to "jpg".
mimeType - the mimetype of the original image, eg image/jpeg
public static byte[] scaleImage(byte[] imageData,
int maxSize,
String mimeType)
imageData - bytes of the original imagemaxSize - maximum dimension in px
public static String convertDateToString(Date date,
String format)
date - date to convertformat - format in SimpleDateFormat syntax
public static Date convertStringToDate(String dateStr,
String format)
dateStr - date string to convertformat - format of the input date in SimpleDateFormat syntaxpublic static Date stripYear(Date date)
date - original date
public static String getDayName(int day,
Locale locale)
day - int according to Calendar.DAY_OF_WEEKlocale - locale to render dayname in
public static String toProperCase(String input)
input - string to be formatted
public static String convertDateForStatus(Date date)
date - date to convertpublic static Locale getUserPreferredLocale()
public static String createEventRef(String ref)
ref -
public static Object getValueFromMapOrDefault(Map<?,?> map,
Object key,
Object defaultValue)
map - key - defaultValue -
public static List<String> getListFromString(String str,
char separator)
str - the String to splitseparator - separator character
public static String processHtml(String s)
s -
public static String stripHtml(String s)
s -
public static String stripAndCleanHtml(String s)
Deals better with poorly formed HTML than just stripHtml and is best for XSS protection, not for storing actual data.
s - The string to process
public static String truncate(String s,
int maxNumOfChars,
boolean isHtml)
s - the stringmaxNumOfChars - num chars to keep. If HTML, it's the number of content chars, ignoring tags.isHtml - is the string HTML?
public static String truncateAndAbbreviate(String s,
int maxNumOfChars,
boolean isHtml)
s - the stringmaxNumOfChars - num chars to keep. If HTML, it's the number of content chars, ignoring tags.isHtml - is the string HTML?
public static String generateUuid()
public static String getSkypeMeURL(String skypeUsername)
skypeUsername -
public static <T> void removeDuplicates(List<T> list)
list - list of objects to cleanpublic static <T> void removeDuplicatesWithOrder(List<T> list)
list - list of objects to cleanpublic static String calculateMD5(String s)
s - String to hash
public static byte[] createAvatar(byte[] imageData,
String mimeType)
imageData - original bytes of the imagemimeType - mimetype of image
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||