public class ProfileUtils extends Object
| Constructor and Description |
|---|
ProfileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
calculateMD5(String s)
Calculate an MD5 hash of a string
|
static boolean |
checkContentTypeForProfileImage(String contentType)
Check content type against allowed types. only JPEG,GIF and PNG are support at the moment
|
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, or, if format
is set to null, do a current locale based conversion.
|
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 String |
getUserPreferredOrientation()
Gets the users preferred orientation, 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 <T> void |
removeDuplicates(List<T> list)
Remove duplicates from a list, order is not retained.
|
static <T> void |
removeDuplicatesWithOrder(List<T> list)
Remove duplicates from a list, order is retained.
|
static byte[] |
scaleImage(byte[] imageData,
int maxSize,
String mimeType) |
static byte[] |
scaleImage(InputStream in,
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 String |
stripHtmlFromText(String text,
boolean smartSpacing,
boolean stripEscapeSequences)
Strips html/xml tags from a string and returns the cleaned version.
|
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. ie This Is Proper Text
|
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).
|
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/jpegpublic static byte[] scaleImage(byte[] imageData,
int maxSize,
String mimeType)
public static byte[] scaleImage(InputStream in, int maxSize, String mimeType)
imageData - bytes of the original imagemaxSize - maximum dimension in pxpublic static String convertDateToString(Date date, String format)
date - date to convertformat - format in SimpleDateFormat syntax. Set to null to force as locale based conversion.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 datepublic static String getDayName(int day, Locale locale)
day - int according to Calendar.DAY_OF_WEEKlocale - locale to render dayname inpublic static String toProperCase(String input)
input - string to be formattedpublic static String convertDateForStatus(Date date)
date - date to convertpublic static Locale getUserPreferredLocale()
public static String getUserPreferredOrientation()
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 characterpublic 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 processpublic static String stripHtmlFromText(String text, boolean smartSpacing, boolean stripEscapeSequences)
text - any text (if this is null or empty then the input text is returned unchanged)smartSpacing - if true then try to make the text represent the intent of the html,
trims out duplicate spaces, converts block type html into a space, etc.,
else just removes html tags and leaves all other parts of the string intact,
NOTE: false is also slightly fasterstripEscapeSequences - if true, strips out any escape sequences such as ' 'for alternative mechanismpublic 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 hashpublic static byte[] createAvatar(byte[] imageData,
String mimeType)
imageData - original bytes of the imagemimeType - mimetype of imageCopyright © 2008–2019 The Sakai Foundation. All rights reserved.