Jive API (3.0.13) Core Javadocs

com.jivesoftware.community.util
Class SkinUtils

java.lang.Object
  extended by com.jivesoftware.community.util.SkinUtils

public class SkinUtils
extends Object

A collection of convenience methods.


Nested Class Summary
static class SkinUtils.FileType
           
 
Field Summary
static String DEFAULT_COMPRESSED_TYPES
           
static String DEFAULT_DOC_TYPES
           
static String DEFAULT_PRESENTATION_TYPES
           
static String DEFAULT_SPREADSHEET_TYPES
           
static String SKIN_ATTACHMENTFILENAMEMAPPINGS
           
static String SKIN_DISPLAYFULLNAME
           
static boolean SKIN_DISPLAYFULLNAME_DEFAULT
           
 
Method Summary
static void addCommonFileExtensionName(String extension, String type)
          Add a mapping for a file extension to a particular type of file.
static void addIconGenerator(int objectType, IconGenerator generator)
          Add a new or override an existing icon generator for the given object type.
static String dateToText(HttpServletRequest request, User user, Date date)
          Deprecated. Replaced to com.jivesoftware.util.DateUtils#displayFriendly(long)
static boolean emailResetPasswordInstructions(String username, HttpServletRequest request)
          This method will send the user specified an email with instructions on how to reset their password.
static Iterator<ForumMessage> filterPendingMessages(Iterator<ForumMessage> messages)
          Assumes index of iterator is at front of iterator (ie, iterator hasn't been used).
static String formatDate(HttpServletRequest request, User user, Date date)
          Formats a date for a user, according to their locale and time zone preferences.
static String getCommonFileExtensionName(String filename)
          Get the file type of a given file name.
static String getDecoratedDocumentElementName()
           
static String getDisplayName(User user)
          A simple method to check whether to display a user's full name or their username.
static String getDocumentAdditionClassname()
           
static String getDocumentDeletionClassname()
           
static String getFavoritedObjectCss(JiveObject favoritedObject, int size)
          Given a bookmark, produce the appropriate CSS class.
static String getIcon(String name, boolean returnAsCssClass, int type)
          Returns an icon string in the standard Jive format.
static String getImageClassname()
           
static String getImageDeletionClassname()
           
static String getImageThumbNailClassname()
           
static String getJiveObjectCss(JiveObject object, int size)
          Returns a string of css class(es) for the given object and type.
static String getJiveObjectIcon(JiveObject object, boolean returnAsCssClass, int type)
          Returns an icon path or a css class name for the icon to associate with the given jive object.
static String getJiveObjectIconForType(int objectType, boolean returnAsCssClass, int type)
          Returns an icon path or a css class name for the icon to associate with the given jive object type constant.
static String getJiveObjectTypeCss(com.jivesoftware.community.objecttype.JiveObjectType jiveObjectType, int size)
           
static String getJiveObjectTypeCssByTypeID(int objectType, int size)
           
static Date getLastLoggedIn(User user)
          Returns the time the given user last logged in.
static long getLastVisited(HttpServletRequest request, HttpServletResponse response)
          Returns the Date the user last visited.
static Locale getLocale()
          Returns the locale from the struts context if one exists, otherwise we return JiveGlobals.getLocale().
static List<Community> getParentCommunities(Community community)
          Returns a list of parent communities for the given forum in top-down order.
static String getSkinProperty(Community community, String name)
          Searches for the property name in the given community.
static String getText(String locale, String key)
          This method is primarily for accessing the internationalized text bundles when no action context is available (i.e. inside a standalone freemarker context such as the email templating system).
static String getTheme()
          Returns the current skin theme or the string "default" to denote the default theme.
static String getUnDecoratedDocumentElementName()
           
static String getXMPPPresenceClassname(org.xmpp.packet.Presence presence)
          Return the proper css classname for the supplied Presence.
static String getXMPPPresenceMessage(org.xmpp.packet.Presence presence)
          Return the show and status message for the supplied Presence.
static boolean isAvatarsEnabled()
          Used to tell whether or not avatars are enabled.
static boolean isExternal()
          Utility method to determine if the current license is a Jive SBS Community (external) or Jive SBS (internal) license.
static boolean isNew(Community community, Date time)
          Returns true if the community has been modified since the specified time.
static boolean isNew(ForumMessage message, Date time)
          Returns true if the forum message has been modified since the specified time.
static boolean isNew(ForumThread thread, Date time)
          Returns true if the forum thread has been modified since the specified time.
static boolean isSlimLayout()
          Used to tell if we should user a slimmer layout
static boolean isValidPasswordToken(long userId, String token)
          Returns true is the supplied token is valid for the userId given.
static String millisecondsToString(long time, boolean stripEmpty)
          Converts time in milliseconds to a String in the format HH:mm:ss.SSS.
static String quoteOriginal(String body, String delimiter, int lineLength)
          Formats the unfiltered body of a message to make it appear in the "quote original" format.
static void removeCommonFileExtensionName(String extension)
          Remove a mapping for a file extension to a particular type of file.
static void removeIconGenerator(int objectType)
          Remove an existing custom generator if one exists.
static boolean resetUserPassword(long userId, String token, String newPassword)
          This method is used in conjunction with the emailResetPasswordInstructions method to reset a user's password.
static String secondsToString(long time, boolean stripEmpty)
          Converts time in seconds to a String in the format HH:mm:ss.
static String test_getBinaryObjectCss(String prefix, String contentType, String name)
          Exposed for test cases
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DOC_TYPES

public static final String DEFAULT_DOC_TYPES
See Also:
Constant Field Values

DEFAULT_SPREADSHEET_TYPES

public static String DEFAULT_SPREADSHEET_TYPES

DEFAULT_PRESENTATION_TYPES

public static final String DEFAULT_PRESENTATION_TYPES
See Also:
Constant Field Values

DEFAULT_COMPRESSED_TYPES

public static final String DEFAULT_COMPRESSED_TYPES
See Also:
Constant Field Values

SKIN_DISPLAYFULLNAME

public static final String SKIN_DISPLAYFULLNAME
See Also:
Constant Field Values

SKIN_DISPLAYFULLNAME_DEFAULT

public static final boolean SKIN_DISPLAYFULLNAME_DEFAULT
See Also:
Constant Field Values

SKIN_ATTACHMENTFILENAMEMAPPINGS

public static final String SKIN_ATTACHMENTFILENAMEMAPPINGS
See Also:
Constant Field Values
Method Detail

formatDate

public static String formatDate(HttpServletRequest request,
                                User user,
                                Date date)
Formats a date for a user, according to their locale and time zone preferences.

Parameters:
request - the servlet request object.
user - the User that the date is being formatted for.
date - the Date object we're comparing the current time with.
Returns:
the date formatted for the correct locale and time zone.

getLocale

public static Locale getLocale()
Returns the locale from the struts context if one exists, otherwise we return JiveGlobals.getLocale().

Returns:
the locale from the struts context if one exists, otherwise we return JiveGlobals.getLocale().

quoteOriginal

public static String quoteOriginal(String body,
                                   String delimiter,
                                   int lineLength)
Formats the unfiltered body of a message to make it appear in the "quote original" format. This is simply the body of the message with the delimiter appended to the beginning of each line. The delimiter is most often "> " by convention. A desired length for each line in the returned String can be specified to aid in formatting.

This method uses message.getBody() in order to get the body of the message. This usually yields better results for the formatting required by this method. However, it also has the potential of being a security risk if malicious HTML code is embedded in the body. Therefore, you should always filter HTML from the result of this method before showing it in an environment where HTML is interpreted. If you are showing the results of this method in an HTML <textarea>, there is no need to worry about malicious HTML.

Parameters:
body - the message body to quote.
delimiter - a String that will start each line of the quoted message. For example, "> ";
lineLength - the desired length of each line in the quoted message.
Returns:
the unfiltered body of the message in the "quote original" format.

isNew

public static boolean isNew(Community community,
                            Date time)
Returns true if the community has been modified since the specified time.

Parameters:
community - the community to check.
time - the time to reference the community against.
Returns:
true if the community has been modified since the specified time.

isNew

public static boolean isNew(ForumThread thread,
                            Date time)
Returns true if the forum thread has been modified since the specified time.

Parameters:
thread - the thread to check.
time - the time to reference the thread against.
Returns:
true if the thread has been modified since the specified time.

isNew

public static boolean isNew(ForumMessage message,
                            Date time)
Returns true if the forum message has been modified since the specified time.

Parameters:
message - the message to check.
time - the time to reference the message against.
Returns:
true if the message has been modified since the specified time.

getParentCommunities

public static List<Community> getParentCommunities(Community community)
Returns a list of parent communities for the given forum in top-down order. This will not include the "root" community. Also, if a forum is in the root community an empty list will be returned.

Parameters:
community - the community to return parent communities.
Returns:
a list of parent communities in top-down order or an empty iterator if no parent communities exist.

getSkinProperty

public static String getSkinProperty(Community community,
                                     String name)
Searches for the property name in the given community. If the property is not found there, the property is checked for in the forum's community. Finally, if the property is not found there, the global property list is searched.

This is a useful method for skin writers if they want to apply per-forum or per-community level UI changes. For example, the property for the forum page background color is stored as the global property "skin.default.bgColor". To apply a forum-level background color, simply create an extended property of the forum named "skin.default.bgColor" and call this method when retrieving the property from the skin.

Parameters:
community - the community to check
name - the name of the property we're looking for.
Returns:
the value of the given property or null if was not found.

getLastVisited

public static long getLastVisited(HttpServletRequest request,
                                  HttpServletResponse response)
Returns the Date the user last visited. If no date was found (stored in a cookie) the current time is used.

Parameters:
request - the HttpServletRequest object, known as "request" on a JSP page.
response - the HttpServletRequest object, known as "response" on a JSP page.
Returns:
the time of the last visit in milliseconds since Jan 1st, 1970.

filterPendingMessages

public static Iterator<ForumMessage> filterPendingMessages(Iterator<ForumMessage> messages)
Assumes index of iterator is at front of iterator (ie, iterator hasn't been used).

Parameters:
messages - the message (and its replies) to examine
Returns:
an Iterator of non-pending messages from the given iterator.

emailResetPasswordInstructions

public static boolean emailResetPasswordInstructions(String username,
                                                     HttpServletRequest request)
                                              throws IllegalArgumentException
This method will send the user specified an email with instructions on how to reset their password. Included in the instructions is a 'token' string which is good for 72 hours. By following the instructions given in the email the user will be able to reset their password.

If the user has already been sent a password reset email in the last 72 hours, the token will not be regenerated but will instead be reused in the instructional email. Conversely, if the user has been sent an email prior to the last 72 hours, the token will be regenerated and saved. In either case, no more than 1 email every 24 hours will be sent. Attempts to send more than 1 email per 24 hours will result in this method returning false.

You can insert the following tokens into the subject or body of the email message and they'll be dynamically replaced with the appropriate values when the email is sent: {userID}, {username}, {name}, {email}, {token}, {requestIP}, {host}, {port} and {webAppDir}.

The details of the email can be changed using the Jive admin skin, the default email is below:

{host} - Jive SBS reset password request.

We have received a request from {requestIP} to reset your password. If you have requested to reset your password, please follow the instructions below. If you do not wish to reset your password, please simply disregard this message.

To reset your Jive password at {host} you can either:

- Click the following url:

http://{host}:{port}{webAppDir}/resetPassword.jsp?userid={userID}&token={token}

- Goto http://{host}:{port}{webAppDir}/resetPassword.jsp and enter the following information into the fields provided:

UserID: {userID}

Token: {token}

Parameters:
username - the usename of the user for whom we wish to send an email with instructions on how to reset their password
request - the servlet request object
Returns:
True if the email was send successfully, false otherwise
Throws:
IllegalArgumentException - if either username or request is null

isValidPasswordToken

public static boolean isValidPasswordToken(long userId,
                                           String token)
Returns true is the supplied token is valid for the userId given. This method checks the consistency of the token (case sensitive) as well as whether the token is valid timewise (The token is only good for 72 hours). If the token is not valid timewise, the user property storing the token will be deleted.

Parameters:
userId - the id of the user for whom we are validating the password reset token.
token - the password reset token associated with the above user.
Returns:
true is the token is valid, false otherwise.

resetUserPassword

public static boolean resetUserPassword(long userId,
                                        String token,
                                        String newPassword)
This method is used in conjunction with the emailResetPasswordInstructions method to reset a user's password. The system generated token will be provided in the instructional email. Returns true if the password was reset, false otherwise. Possible reasons for failure:

Parameters:
userId - the id of the user for whom the password should be changed.
token - the password reset token associated with the above user.
newPassword - the password to use for the specified user.
Returns:
true is the password was changed, false otherwise.

dateToText

public static String dateToText(HttpServletRequest request,
                                User user,
                                Date date)
Deprecated. Replaced to com.jivesoftware.util.DateUtils#displayFriendly(long)

Returns an English sentence which describes the Date parameter relative to the current time. For instance, if the passed in date was 39 seconds ago, this method returns:

"Less than 1 min ago"

Similiarly, a date 1 ago would be:

"Yesterday at 3:53 PM"

The method obeys user preferences for time zone if they exist.

Parameters:
request - the servlet request object.
user - the User that the date is being formatted for, or null if an anonymmous user.
date - the Date object we're comparing the current time with.
Returns:
a String representing an English version of the date difference

addCommonFileExtensionName

public static void addCommonFileExtensionName(String extension,
                                              String type)
Add a mapping for a file extension to a particular type of file. The standard file types are defined as: but you can define your own if the file extension you want to add is one of the existing file types. If you do add your own, you'll need to define a CSS class:

jive-icon-doctype-${yourFileType}

You can override any of the existing mappings by adding the extension with a different file type grouping.

Parameters:
extension - the file extension you want add (example: doc, xls, ppt)
type - the file type you want the extension grouped with

removeCommonFileExtensionName

public static void removeCommonFileExtensionName(String extension)
Remove a mapping for a file extension to a particular type of file.

Parameters:
extension - the file extension to remove the mapping for

addIconGenerator

public static void addIconGenerator(int objectType,
                                    IconGenerator generator)
Add a new or override an existing icon generator for the given object type.

Parameters:
objectType - the object type of the generator you want to add
generator - the generator

removeIconGenerator

public static void removeIconGenerator(int objectType)
Remove an existing custom generator if one exists.

Parameters:
objectType - the object type of the generator you want to remove.

getCommonFileExtensionName

public static String getCommonFileExtensionName(String filename)
Get the file type of a given file name. You can either use the API to add a common file extension name via addCommonFileExtensionName(...) or you can set a system property:

skin.attachments.filemapping

which can contain a comma delimited list of extension=type pairs.

If you set a system property, you may need to restart your application server to reset the render cache.

Parameters:
filename - the file name to attempt to find a file type for.
Returns:
the common file extension name (text, image, compressed, excel document, acrobat) or generic if the file extension isn't mapped to a file type.

getJiveObjectCss

public static String getJiveObjectCss(JiveObject object,
                                      int size)
Returns a string of css class(es) for the given object and type. Currently this is of the form : "jive-icon-sml jive-icon-document" where sml is for the size and document is the object 'type'

Parameters:
object - the object to return the css class for
size - 0 for small, 1 for medium, 2 for big. Default is medium for any other provided side.
Returns:
a string of css class(es) for the given object and size

getFavoritedObjectCss

public static String getFavoritedObjectCss(JiveObject favoritedObject,
                                           int size)
Given a bookmark, produce the appropriate CSS class. The trick here is that if you bookmark a document, we don't show the bookmark icon, we show the document icon with the bookmark icon on top.

Parameters:
favoritedObject - the favorite to produce an icon for
size - the prefix (example: jive-icon-...)
Returns:
the name of the CSS class that describes the favorite

test_getBinaryObjectCss

public static String test_getBinaryObjectCss(String prefix,
                                             String contentType,
                                             String name)
Exposed for test cases


getJiveObjectTypeCss

public static String getJiveObjectTypeCss(com.jivesoftware.community.objecttype.JiveObjectType jiveObjectType,
                                          int size)

getJiveObjectTypeCssByTypeID

public static String getJiveObjectTypeCssByTypeID(int objectType,
                                                  int size)

getJiveObjectIconForType

public static String getJiveObjectIconForType(int objectType,
                                              boolean returnAsCssClass,
                                              int type)
Returns an icon path or a css class name for the icon to associate with the given jive object type constant. If you can access the actual JiveObject, calling getJiveObjectIcon(JiveObject, boolean, int) is preferable since it will return more specific icons for things like binary documents and comments.

Parameters:
objectType - the objectType to return the icon image for
returnAsCssClass - true to return a css class (may be partial), false to return the path to the image (not including the context root i.e. /clearspace/)
type - 0 for small, 1 for medium, 2 for large, 3 for xlarge, 4 for a label icon, 5 for no type
Returns:
a css class (may be partial) or the path to the image (not including the context root) depending on the value of the returnAsCssClass parameter

getJiveObjectIcon

public static String getJiveObjectIcon(JiveObject object,
                                       boolean returnAsCssClass,
                                       int type)
Returns an icon path or a css class name for the icon to associate with the given jive object. The icon for a given jive object type can be overriden by creating an implementation of IconGenerator and registering the implementation with addIconGenerator(int, IconGenerator).

Parameters:
object - the content object to return the icon image for
returnAsCssClass - true to return a css class (may be partial), false to return the path to the image (not including the context root i.e. /clearspace/)
type - 0 for small, 1 for medium, 2 for large, 3 for xlarge, 4 for a label icon, 5 for no type
Returns:
a css class (may be partial) or the path to the image (not including the context root) depending on the value of the returnAsCssClass parameter

getIcon

public static String getIcon(String name,
                             boolean returnAsCssClass,
                             int type)

Returns an icon string in the standard Jive format. The format can be configured through Jive Properties, the default returned format is:

images/jive-icon-community-16x16.gif

Parameters:
name - controls the name portion of the String returned.
returnAsCssClass - true to return a CSS class or false to return a file name.
type - 0 for small, 1 for medium, 2 for large, 3 for xlarge, 4 for a label icon, 5 for no type.
Returns:
the String compiled from the very settings.
See Also:
JiveGlobals.setJiveProperty(String, String)

getDisplayName

public static String getDisplayName(User user)
A simple method to check whether to display a user's full name or their username. This is controlled by the jive property ("skin.default.displayFullNames"

Parameters:
user - the user to return the display name for
Returns:
the display name for the user.

getTheme

public static String getTheme()
Returns the current skin theme or the string "default" to denote the default theme. Set the theme name by the admin console or by setting a Jive property of 'skin.theme'.

Returns:
the current skin theme or "default" to denote the default theme.

isSlimLayout

public static boolean isSlimLayout()
Used to tell if we should user a slimmer layout

Returns:
true if we should use a slimmer version of the layout

isAvatarsEnabled

public static boolean isAvatarsEnabled()
Used to tell whether or not avatars are enabled.

Returns:
true if avatars are enabled, false otherwise. True by default.

getXMPPPresenceClassname

public static String getXMPPPresenceClassname(org.xmpp.packet.Presence presence)
Return the proper css classname for the supplied Presence.

Parameters:
presence - the presence to return a classname for.
Returns:
the proper css classname for the supplied Presence.

getXMPPPresenceMessage

public static String getXMPPPresenceMessage(org.xmpp.packet.Presence presence)
Return the show and status message for the supplied Presence. Or "Offline" if the presence is null.

Parameters:
presence - the presence to return a status message for.
Returns:
the status message for the supplied Presence.

getLastLoggedIn

public static Date getLastLoggedIn(User user)
Returns the time the given user last logged in. The last login time is stored as the millisecond date value. Parse this value by calling new Date(Long.parseLong(value)).

Parameters:
user - the user to check
Returns:
the date the user last logged in or null if it can not be determined.

getDocumentAdditionClassname

public static String getDocumentAdditionClassname()

getDocumentDeletionClassname

public static String getDocumentDeletionClassname()

getImageDeletionClassname

public static String getImageDeletionClassname()

getImageThumbNailClassname

public static String getImageThumbNailClassname()

getImageClassname

public static String getImageClassname()

getDecoratedDocumentElementName

public static String getDecoratedDocumentElementName()

getUnDecoratedDocumentElementName

public static String getUnDecoratedDocumentElementName()

isExternal

public static boolean isExternal()
Utility method to determine if the current license is a Jive SBS Community (external) or Jive SBS (internal) license. Returns true if the current license is a Jive SBS Community license, false otherwise.

Returns:
true if the current license is a Jive SBS Community license, false otherwise.

getText

public static String getText(String locale,
                             String key)
This method is primarily for accessing the internationalized text bundles when no action context is available (i.e. inside a standalone freemarker context such as the email templating system). It should *not* be used to render this text when an alternate method is available, such as the <@s.text/> tags on web views or the "getText" methods inside actions.

Parameters:
locale -
key -
Returns:

secondsToString

public static String secondsToString(long time,
                                     boolean stripEmpty)
Converts time in seconds to a String in the format HH:mm:ss.

Parameters:
time - the time in seconds.
stripEmpty - - remove for times formatted 00:01:00 strip the leading 00: so it's 01:00. For 00:00 return 0
Returns:
a String representing the time in the format HH:mm:ss. lazily adapted (jacked) from here: http://www.uk-dave.com/bytes/java/time_long_to_string.html (public domain)

millisecondsToString

public static String millisecondsToString(long time,
                                          boolean stripEmpty)
Converts time in milliseconds to a String in the format HH:mm:ss.SSS.

Parameters:
time - the time in milliseconds.
stripEmpty - - remove for times formatted 00:01:00 strip the leading 00: so it's 01:00. For 00:00 return 0
Returns:
a String representing the time in the format HH:mm:ss.SSS. lazily adapted (jacked) from here: http://www.uk-dave.com/bytes/java/time_long_to_string.html (public domain)

Jive Product Page

Copyright © 1999-2007 Jive Software.