com.atlassian.confluence.util
Class GeneralUtil

java.lang.Object
  extended by com.atlassian.confluence.util.GeneralUtil

public final class GeneralUtil
extends java.lang.Object


Constructor Summary
GeneralUtil()
           
 
Method Summary
static java.lang.String alwaysMaskEmail(java.lang.String emailAddress)
          Masks an email address by replacing '@' with 'at' and '.' with 'dot'.
static java.lang.String appendAmpsandOrQuestionMark(java.lang.String str)
           
static int arraySize(int[] array)
          convenience method to allow us to determine the size of an int array a velocity file
static java.lang.String base64Decode(java.lang.String s)
           
static java.lang.String base64Encode(java.lang.String s)
           
static java.lang.String completeUrlEncode(java.lang.String url)
          A utility method to encode the given url for protocols which the CompleteURLEncoder supports.
static java.lang.String constrainLength(java.lang.String s, int length)
          Truncate a string after n characters
static java.util.Map<java.lang.String,java.lang.String> convertBeanToMap(java.lang.Object bean)
           
static java.util.Date convertMailFormatDate(java.lang.String date)
           
static java.lang.Boolean convertToBoolean(java.lang.Object obj)
           
static boolean convertToBoolean(java.lang.Object bool, boolean defaultValue)
           
static java.lang.Character convertToCharacter(java.lang.Object obj)
           
static java.lang.Integer convertToInteger(java.lang.Object obj)
           
static java.lang.String convertToString(java.lang.Object obj)
           
static void copyDate(java.util.Calendar original, java.util.Calendar copy)
          Takes two calendar objects and sets the Date of the second to the Date of the first.
static java.io.File createTempDirectoryInConfluenceTemp(java.lang.String prefix)
           
static java.io.File createTempFile(java.lang.String directory)
           
static java.lang.String customGetPageUrl(AbstractPage page)
          Need a special case of generalutils getpageurl that appends ? or ampersand smartly this is used to prefix url parameters that are appended after this path like: showcomments=true#addcomment
static java.lang.String displayShortUrl(java.lang.String url)
           
static java.lang.String displayShortUrl(java.lang.String url, int length)
           
static java.lang.String doubleUrlEncode(java.lang.String s)
           
static java.lang.String escapeCDATA(java.lang.String s)
           
static java.util.List<java.lang.String> escapeCommas(java.util.List<java.lang.String> toEscape)
          Escape commas on each entry in the given list of strings.
static java.lang.String escapeCommas(java.lang.String toEscape)
          Escapes commas and backslashes with leading backslashes.
static java.lang.String escapeForHtmlAttribute(java.lang.String s)
          Escapes " and \ with a leading \ so that strings can't break out of double-quoted HTML attributes.
static java.lang.String escapeForJavascript(java.lang.String s)
          Escapes ', " and \ with a leading \.
static java.lang.String[] escapeXml(java.lang.Object[] args)
          Produces an array of XML escaped Strings from a list of Objects.
static java.lang.String escapeXml(java.lang.String stringToEscape)
           
static java.lang.String escapeXMLCharacters(java.lang.String input)
          Take a String which may contain <, > or & and return an XML string containing entities
static
<T> java.util.List<T>
filterNulls(java.util.Collection<T> in)
          Return a List with no null entries
static java.lang.String findAndMaskEmail(java.lang.String text, com.atlassian.user.User currentUser)
           
static java.lang.String format(java.lang.Number number)
          TODO: Replace with a NumberFormatter, similar to DateFormatter
static java.lang.String format(java.lang.Object obj)
           
static java.lang.String format(java.lang.String str)
           
static java.lang.String formatDateFull(java.util.Date date)
           
static java.lang.String formatLongTime(long time)
           
static java.util.Date getBuildDate()
           
static java.lang.String getBuildDateString()
           
static java.lang.String getBuildNumber()
           
static java.lang.String getCharacterEncoding()
           
static java.lang.String getCompactDuration(long time)
          Returns the duration in a compact HH:mm:ss format.
static java.io.File getConfluenceTempDirectory()
          Deprecated. since 5.5. Use getLocalTempDirectory() instead.
static java.lang.String getConfluenceTempDirectoryPath()
          Deprecated. since 5.5. Use getLocalTempDirectory() instead.
static java.lang.String getCookieValue(java.lang.String key)
           
static java.util.ResourceBundle getDefaultResourceBundle()
           
static java.lang.String getFormatDateSimple(java.util.Date date)
           
static Settings getGlobalSettings()
           
static I18NBean getI18n()
           
static java.lang.String getIdBasedPageUrl(AbstractPage page)
          Get page URL that is id based (i.e.
static com.atlassian.core.util.ImageInfo getImageInfo(java.io.File pathToImage)
           
static java.io.File getLocalTempDirectory()
          Checks if local temp directory exists before returning the path.
static java.lang.String getNiceDuration(int minutes, int seconds)
           
static java.lang.String getPageUrl(AbstractPage page)
           
static java.lang.String getPageUrl(VersionHistorySummary summary)
           
static long getPercentage(long numerator, long denom)
          converts a fraction into a percentage
static long getPercentage(java.lang.String numeratorAsString, java.lang.String denomAsString)
           
static
<T> java.util.List<T>
getRandomSubSet(java.util.List<T> list, int sizeOfSubset, java.util.Random random)
          Returns a randomised subset of the list provided.
static java.lang.String getRelativeTime(java.util.Date date)
          Deprecated. since 2.7 use FriendlyDateFormatter
static java.io.File getSharedTempDirectory()
          Checks if shared temp directory exists before returning the path.
static java.lang.String getStackTrace(java.lang.Throwable t)
           
static java.lang.Long getSystemStartupTime()
           
static java.lang.String getUploadFileTooLargeMessage(java.lang.String errorMessage)
          if this error message is of the type: "java.io.IOException: Content Length Error" convert it to something nicer
static UserAccessor getUserAccessor()
           
static java.lang.String getVersionNumber()
           
static java.lang.String hackSingleQuotes(java.lang.String s)
          hack to make strings that contain singles compatible with javascript (which also uses single quotes denote strings)
static boolean hasTooManyUsers()
          Check if the current installation has more active users than is allowed by the license
static java.lang.String highlight(java.lang.String content, java.lang.String searchwords)
           
static java.lang.String htmlEncode(java.lang.String text)
          TODO introduce deprecation: deprecated since 5.3.2.
static java.lang.String htmlEncodeAndReplaceSpaces(java.lang.String text)
          TODO introduce deprecation: deprecated since 5.3.2.
static java.lang.String htmlEscapeQuotes(java.lang.String input)
          Take a string and escape the quotes in it with \" and HTML escape them afterwards.
static boolean isAllAscii(java.lang.String s)
           
static boolean isAllLettersOrNumbers(java.lang.String s)
           
static boolean isDateWithin24Hours(java.util.Date date)
          Determines if given date is within 24 hours
static boolean isDefaultUserProfilePicture(java.lang.String username)
          Deprecated. since 2.7. Use UserAccessor.getUserProfilePicture(com.atlassian.user.User).
static boolean isInLastDays(java.util.Date date, int maxDays)
           
static boolean isLicenseExpired()
           
static boolean isOutgoingMailConfigured()
          Deprecated. since v5.0. Use MailServerManager.isDefaultSMTPMailServerDefined() instead.
static boolean isSafeTitleForFilesystem(java.lang.String title)
          Ensure the title is safe to be written to the file system.
static boolean isSafeTitleForUrl(java.lang.String title)
          Is "title" something we can safely put in a /foo/bar/title URL? Or should we reference this thing by ID just to be safe?
static boolean isSetupComplete()
           
static boolean isSuperUser(com.atlassian.user.User user)
          Deprecated. since 3.5 calls to the PermissionManager will ensure super-user checks are performed
static void loadDefaultProperties()
          Deprecated. since 3.0 because it doesn't do anything
static java.lang.String lookupDomainName(javax.servlet.http.HttpServletRequest request)
          Get the default domain name.
static java.lang.String makeFlatSummary(java.lang.String content)
          Create a summary of this content fragment.
static java.lang.String makeFlatSummary(java.lang.String content, java.lang.String query)
          Create a summary of this content fragment given a query
static com.atlassian.bonnie.search.summary.Summary makeSummary(java.lang.String content)
          Create a proper summary of this content fragment.
static com.atlassian.bonnie.search.summary.Summary makeSummary(java.lang.String content, java.lang.String query)
          Create a proper summary of this content fragment given a query
static java.lang.String maskEmail(java.lang.String emailAddress)
          If configured, masks an email address to defeat the most simplistic spam bots.
static java.lang.String maskEmail(java.lang.String emailAddress, Settings globalSettings, I18NBean i18NBean)
           
static ConfluenceActionSupport newWiredConfluenceActionSupport()
           
static java.lang.String personalSpaceUrl(java.lang.String contextPath, java.lang.String username)
          Deprecated. since 5.0 You should instead retrieve the space using SpaceManager and call getUrlPath on the Space object. Also note that if a user has been renamed (which is possible from Confluence 5.3 onwards) then this method is likely to return the wrong key.
static java.lang.String plain2html(java.lang.String text)
           
static java.lang.String populateSimpleMessage(java.lang.String template, java.util.List<java.lang.String> values)
           Populate the template String supplied using the given values.
static
<K,V> java.util.Map<K,V>
prefixAllMapKeys(java.lang.String prefix, java.util.Map<K,V> map)
          Convert the supplied Map so that all of the keys in the Map are prefixed by the supplied String followed by a full stop.
static void profilePop(java.lang.String s)
           
static void profilePush(java.lang.String s)
           
static java.lang.String rdfEncode(java.lang.String s)
          A fairly evil hack to work around CONF-10364.
static java.lang.String refineOsDestination(java.lang.String osDestination)
          Escape XML and replace all space with %20
static java.lang.String removeEmailsFromString(java.lang.String text)
          Remove all emails from text
static java.lang.String replaceConfluenceConstants(java.lang.String in, java.io.File home, java.io.File localHome)
          Replaces ConfluenceBootstrapConstants.CONFLUENCE_HOME_CONSTANT and ConfluenceBootstrapConstants.CONFLUENCE_LOCAL_HOME_CONSTANT in the given text with the correct paths.
static java.lang.String replaceConfluenceHomeConstant(java.lang.String in, java.lang.String confHome)
          Deprecated. since 5.5. Use replaceConfluenceConstants(String, java.io.File, java.io.File) instead.
static java.lang.String replaceInvalidXmlCharacters(java.lang.String text)
          Take a String which may contain characters outside of the XML character range (http://www.w3.org/TR/REC-xml/#charsets) and return a String with those characters converted to Unicode "Replacement Character"s (0xFFFD).
static
<T> java.util.List<T>
safeSubList(java.util.List<T> list, int max)
           
static javax.servlet.http.Cookie setCookie(java.lang.String key, java.lang.String value)
          Sets a cookie.
static void setSystemStartupTime(java.lang.Long systemStartupTime)
           
static void setUserAccessor(UserAccessor userAcc)
           
static java.lang.String shortenString(java.lang.String str, int max)
          Returns a substring of the specified string if it is longer than max.
static boolean shouldUrlDecode(java.lang.String str)
          TODO introduce deprecation: deprecated since 5.3.3.
static java.util.Collection<java.lang.String> specialLowerCaseCollection(java.util.Collection<java.lang.String> collection)
          Takes a collection of Strings and lowercases the entries.
static java.lang.String specialToLowerCase(java.lang.String str)
          

the database lower() function in PostgreSQL only works for ASCII strings.

static java.lang.String[] splitCommaDelimitedString(java.lang.String escapedNames)
          Method will turn a String of comma separated entities into a String Array.
static boolean stringSet(java.lang.String str)
           
 long subtract(long a, long b)
          Deprecated. since 5.0. Just use a minus sign.
 long subtract(java.lang.String firstOperandAsString, java.lang.String secondOperandAsString)
          Deprecated. since 5.0. Just say no.
static java.lang.String summarise(java.lang.String content)
           
static java.util.Date toEndOfMonth(java.util.Calendar postDate, boolean isSqlServer)
          Takes a Calendar object and returns the very end (last day, hour, minute, second and millisecond) of the month that the Calendar is in.
static java.lang.String trimDownStringToWord(java.lang.String s)
           
static java.lang.String unescapeCDATA(java.lang.String s)
           
static java.lang.String unescapeEntities(java.lang.String str)
           
static void unzipFile(java.io.File zipFile, java.io.File dirToExtractTo)
          Unzips the zip file to a folder in temp and returns the File pointing to that expanded folder.
static void unzipUrl(java.net.URL zipUrl, java.io.File dirToExtractTo)
          Unzips the zip url to a folder in temp and returns the File pointing to that expanded folder.
static java.lang.String urlDecode(java.lang.String url)
          TODO introduce deprecation: deprecated since 5.3.3.
static java.lang.String urlEncode(java.lang.String url)
          A utility method to encode HTTP form parameter/values.
static java.lang.String urlEncode(java.lang.String value, java.lang.String encoding)
          TODO introduce deprecation: deprecated since 5.3.3.
static java.lang.String wordWrap(java.lang.String str, int max)
          For really long strings that have no spaces or line breaks, browsers such as firefox, Netscape, have difficulty wrapping them inside a table cell, and so these strings end up stretching the cell longer than its suppose to be = ugly

we want to simulate IE's word-wrap/break function here

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralUtil

public GeneralUtil()
Method Detail

loadDefaultProperties

@Deprecated
public static void loadDefaultProperties()
Deprecated. since 3.0 because it doesn't do anything

See Also:
BuildInformation

getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)

format

public static java.lang.String format(java.lang.Number number)
TODO: Replace with a NumberFormatter, similar to DateFormatter

Parameters:
number - the number object to reformat
Returns:
the number formatted a String, or null if an exception occurred.

format

public static java.lang.String format(java.lang.String str)

format

public static java.lang.String format(java.lang.Object obj)

convertMailFormatDate

public static java.util.Date convertMailFormatDate(java.lang.String date)
                                            throws java.text.ParseException
Throws:
java.text.ParseException

convertToCharacter

public static java.lang.Character convertToCharacter(java.lang.Object obj)

convertToInteger

public static java.lang.Integer convertToInteger(java.lang.Object obj)

convertToBoolean

public static java.lang.Boolean convertToBoolean(java.lang.Object obj)

convertToBoolean

public static boolean convertToBoolean(java.lang.Object bool,
                                       boolean defaultValue)

convertToString

public static java.lang.String convertToString(java.lang.Object obj)

completeUrlEncode

public static java.lang.String completeUrlEncode(java.lang.String url)
A utility method to encode the given url for protocols which the CompleteURLEncoder supports. To only encode HTTP form parameter/values or fragments, use urlEncode() instead. TODO introduce deprecation: deprecated since 5.3.3. Use HtmlUtil.completeUrlEncode(String) instead.

Parameters:
url - - the entire URL to encode
Returns:
encoded url

urlEncode

public static java.lang.String urlEncode(java.lang.String url)
A utility method to encode HTTP form parameter/values. To encode entire URLs, use completeUrlEncode() instead. TODO introduce deprecation: deprecated since 5.3.3. Use HtmlUtil.urlEncode(String) instead.

Parameters:
url - - part of the url to encode
Returns:
encoded url

urlEncode

public static java.lang.String urlEncode(java.lang.String value,
                                         java.lang.String encoding)
TODO introduce deprecation: deprecated since 5.3.3. Use HtmlUtil.urlEncode(String, String) instead.


urlDecode

public static java.lang.String urlDecode(java.lang.String url)
TODO introduce deprecation: deprecated since 5.3.3. Use HtmlUtil.urlDecode(String) instead.


shouldUrlDecode

public static boolean shouldUrlDecode(java.lang.String str)
TODO introduce deprecation: deprecated since 5.3.3. Use HtmlUtil.shouldUrlDecode(String) instead.


getPageUrl

public static java.lang.String getPageUrl(VersionHistorySummary summary)

getPageUrl

public static java.lang.String getPageUrl(AbstractPage page)

getIdBasedPageUrl

public static java.lang.String getIdBasedPageUrl(AbstractPage page)
Get page URL that is id based (i.e. in the format /pages/viewpage.action?pageId=<pageId>)

Parameters:
page - the page to generate a url for
Returns:
page URL that is id based

isSafeTitleForUrl

public static boolean isSafeTitleForUrl(java.lang.String title)
Is "title" something we can safely put in a /foo/bar/title URL? Or should we reference this thing by ID just to be safe?

Parameters:
title - The title to check
Returns:
True of the title can be put in a URL, false otherwise

isSafeTitleForFilesystem

public static boolean isSafeTitleForFilesystem(java.lang.String title)
Ensure the title is safe to be written to the file system. See CONF-10741.

Parameters:
title - The title to check
Returns:
True if the title is safe for the filesystem, false otherwise

customGetPageUrl

public static java.lang.String customGetPageUrl(AbstractPage page)
Need a special case of generalutils getpageurl that appends ? or ampersand smartly this is used to prefix url parameters that are appended after this path like: showcomments=true#addcomment

Parameters:
page - The page to get the URL of
Returns:
The URL of the page with a trailing ? or &

appendAmpsandOrQuestionMark

public static java.lang.String appendAmpsandOrQuestionMark(java.lang.String str)

wordWrap

public static java.lang.String wordWrap(java.lang.String str,
                                        int max)
For really long strings that have no spaces or line breaks, browsers such as firefox, Netscape, have difficulty wrapping them inside a table cell, and so these strings end up stretching the cell longer than its suppose to be = ugly

we want to simulate IE's word-wrap/break function here

Parameters:
str - the string to wrap
max - max length of string allowed per line
Returns:
The wrapped string

highlight

public static java.lang.String highlight(java.lang.String content,
                                         java.lang.String searchwords)

doubleUrlEncode

public static java.lang.String doubleUrlEncode(java.lang.String s)

isAllAscii

public static boolean isAllAscii(java.lang.String s)

isAllLettersOrNumbers

public static boolean isAllLettersOrNumbers(java.lang.String s)

getVersionNumber

public static java.lang.String getVersionNumber()

getBuildDate

public static java.util.Date getBuildDate()

getBuildDateString

public static java.lang.String getBuildDateString()

getBuildNumber

public static java.lang.String getBuildNumber()
Returns:
The build number of the currently running Confluence instance.
See Also:
BuildInformation.getBuildNumber()

getSystemStartupTime

public static java.lang.Long getSystemStartupTime()

setSystemStartupTime

public static void setSystemStartupTime(java.lang.Long systemStartupTime)

isLicenseExpired

public static boolean isLicenseExpired()

hasTooManyUsers

public static boolean hasTooManyUsers()
Check if the current installation has more active users than is allowed by the license

Returns:
true if the number exceeds the license, false otherwise.

stringSet

public static boolean stringSet(java.lang.String str)

formatLongTime

public static java.lang.String formatLongTime(long time)

displayShortUrl

public static java.lang.String displayShortUrl(java.lang.String url)

displayShortUrl

public static java.lang.String displayShortUrl(java.lang.String url,
                                               int length)

formatDateFull

public static java.lang.String formatDateFull(java.util.Date date)

toEndOfMonth

public static java.util.Date toEndOfMonth(java.util.Calendar postDate,
                                          boolean isSqlServer)
Takes a Calendar object and returns the very end (last day, hour, minute, second and millisecond) of the month that the Calendar is in. The original Calendar object is left unaltered.

Parameters:
postDate - A calendar object
Returns:
Date object signifying the very end of the Calendar's month

copyDate

public static void copyDate(java.util.Calendar original,
                            java.util.Calendar copy)
Takes two calendar objects and sets the Date of the second to the Date of the first. Used to keep dates consistent regardless of timezones.

Parameters:
original - The source calendar object
copy - The destination calendar object

isSuperUser

@Deprecated
public static boolean isSuperUser(com.atlassian.user.User user)
Deprecated. since 3.5 calls to the PermissionManager will ensure super-user checks are performed

Parameters:
user - the user to check for (the null user will always return false
Returns:
true if the user is a super-user, false otherwise.
See Also:
PermissionManager.hasPermission(com.atlassian.user.User, com.atlassian.confluence.security.Permission, java.lang.Object)

getCharacterEncoding

public static java.lang.String getCharacterEncoding()

escapeXml

public static java.lang.String escapeXml(java.lang.String stringToEscape)

escapeXml

public static java.lang.String[] escapeXml(java.lang.Object[] args)
Produces an array of XML escaped Strings from a list of Objects. String.valueOf(Object) is used to produce Strings from the Objects

Parameters:
args - an array of objects
Returns:
an array of XML escaped Strings

escapeForJavascript

public static java.lang.String escapeForJavascript(java.lang.String s)
Escapes ', " and \ with a leading \.

Parameters:
s - the string to escape
Returns:
the escaped string

escapeForHtmlAttribute

public static java.lang.String escapeForHtmlAttribute(java.lang.String s)
Escapes " and \ with a leading \ so that strings can't break out of double-quoted HTML attributes.

Parameters:
s - the string to escape
Returns:
the escaped string

isSetupComplete

public static boolean isSetupComplete()

maskEmail

public static java.lang.String maskEmail(java.lang.String emailAddress)
If configured, masks an email address to defeat the most simplistic spam bots. If Confluence is not configured to mask email addresses, just returns the original address.

Passing in null to this method will just get you null back

Parameters:
emailAddress - the email address to mask
Returns:
the masked email address, or the original address if masking is not configured

maskEmail

public static java.lang.String maskEmail(java.lang.String emailAddress,
                                         Settings globalSettings,
                                         I18NBean i18NBean)

alwaysMaskEmail

public static java.lang.String alwaysMaskEmail(java.lang.String emailAddress)
Masks an email address by replacing '@' with 'at' and '.' with 'dot'.

Parameters:
emailAddress - an email address to mask, eg dwillis@atlassian.com
Returns:
a masked version of the email, eg dwillis at atlassian dot com

findAndMaskEmail

public static java.lang.String findAndMaskEmail(java.lang.String text,
                                                com.atlassian.user.User currentUser)

escapeCDATA

public static java.lang.String escapeCDATA(java.lang.String s)

unescapeCDATA

public static java.lang.String unescapeCDATA(java.lang.String s)

createTempDirectoryInConfluenceTemp

public static java.io.File createTempDirectoryInConfluenceTemp(java.lang.String prefix)

createTempFile

public static java.io.File createTempFile(java.lang.String directory)

unescapeEntities

public static java.lang.String unescapeEntities(java.lang.String str)

base64Decode

public static java.lang.String base64Decode(java.lang.String s)

base64Encode

public static java.lang.String base64Encode(java.lang.String s)

hackSingleQuotes

public static java.lang.String hackSingleQuotes(java.lang.String s)
hack to make strings that contain singles compatible with javascript (which also uses single quotes denote strings)

Parameters:
s - the input string
Returns:
the string with ' replaced with ' + '\\'' + '

isInLastDays

public static boolean isInLastDays(java.util.Date date,
                                   int maxDays)
Parameters:
date - the date to check
maxDays - the number of days into the past the date can fall
Returns:
Whether whether the date falls within maxDays before the present.

getRelativeTime

public static java.lang.String getRelativeTime(java.util.Date date)
Deprecated. since 2.7 use FriendlyDateFormatter

Parameters:
date - the date to convert to a relative time string
Returns:
A relative time period, 'X hours, Y minutes ago'

getFormatDateSimple

public static java.lang.String getFormatDateSimple(java.util.Date date)

setCookie

public static javax.servlet.http.Cookie setCookie(java.lang.String key,
                                                  java.lang.String value)
Sets a cookie. set to use a default cookie age of one year and the context path as the default path

Parameters:
key - the key of the cookie
value - the value of the cookie
Returns:
the new Cookie object

getCookieValue

public static java.lang.String getCookieValue(java.lang.String key)

htmlEncode

public static java.lang.String htmlEncode(java.lang.String text)
TODO introduce deprecation: deprecated since 5.3.2. Use HtmlUtil.htmlEncode(String) instead)


htmlEncodeAndReplaceSpaces

public static java.lang.String htmlEncodeAndReplaceSpaces(java.lang.String text)
TODO introduce deprecation: deprecated since 5.3.2. Use HtmlUtil.htmlEncodeAndReplaceSpaces(String) instead)


plain2html

public static java.lang.String plain2html(java.lang.String text)
Parameters:
text - the text to encode
Returns:
the html encoded text
See Also:
PlainTextToHtmlConverter

unzipFile

public static void unzipFile(java.io.File zipFile,
                             java.io.File dirToExtractTo)
                      throws java.io.IOException
Unzips the zip file to a folder in temp and returns the File pointing to that expanded folder.

Parameters:
zipFile - the zip file to extract
dirToExtractTo - the directory to extract the zip file to
Throws:
java.io.IOException - if an IOException occurs

unzipUrl

public static void unzipUrl(java.net.URL zipUrl,
                            java.io.File dirToExtractTo)
                     throws java.io.IOException
Unzips the zip url to a folder in temp and returns the File pointing to that expanded folder.

Parameters:
zipUrl - the URL of the zip file to extract
dirToExtractTo - the directory to extract the zip file to
Throws:
java.io.IOException - if an IOException occurs

getUploadFileTooLargeMessage

public static java.lang.String getUploadFileTooLargeMessage(java.lang.String errorMessage)
if this error message is of the type: "java.io.IOException: Content Length Error" convert it to something nicer

Parameters:
errorMessage - the error message to convert
Returns:
the nicer error message if it can be converted, else the input string

getDefaultResourceBundle

public static java.util.ResourceBundle getDefaultResourceBundle()

getI18n

public static I18NBean getI18n()
Returns:
The I18NBean for the current user

arraySize

public static int arraySize(int[] array)
convenience method to allow us to determine the size of an int array a velocity file

Parameters:
array - the array to find the length of
Returns:
the length of the array

escapeXMLCharacters

public static java.lang.String escapeXMLCharacters(java.lang.String input)
Take a String which may contain <, > or & and return an XML string containing entities

Parameters:
input - a string to escape for XML
Returns:
the string with XML entities escaped

replaceInvalidXmlCharacters

public static java.lang.String replaceInvalidXmlCharacters(java.lang.String text)
Take a String which may contain characters outside of the XML character range (http://www.w3.org/TR/REC-xml/#charsets) and return a String with those characters converted to Unicode "Replacement Character"s (0xFFFD). Note that this method does not "escape" the string (e.g. "&" is not converted to "&"). Similar to Verifier.checkCharacterData(String) but converts illegals instead of throwing Exceptions.

Parameters:
text - the input string
Returns:
the input string with those characters converted to Unicode "Replacement Character"s

htmlEscapeQuotes

public static java.lang.String htmlEscapeQuotes(java.lang.String input)
Take a string and escape the quotes in it with \" and HTML escape them afterwards. We need this function to escape strings containing quotes passed into JavaScript functions null input will be returned as an empty String.

Parameters:
input - string to escape
Returns:
the escaped string

filterNulls

public static <T> java.util.List<T> filterNulls(java.util.Collection<T> in)
Return a List with no null entries

Parameters:
in - a collection to filter nulls
Returns:
a list that is a copy of the collection with nulls removed

shortenString

public static java.lang.String shortenString(java.lang.String str,
                                             int max)
Returns a substring of the specified string if it is longer than max. This method also appends ELLIPSIS to the end of the string if it does truncate it.

Parameters:
str - the string to shorten
max - the maximum desired length of the result (excluding ELLIPSIS)
Returns:
a substring of the specified string if it is longer than max.
See Also:
StringUtils.abbreviate(String, int)

specialToLowerCase

public static java.lang.String specialToLowerCase(java.lang.String str)

the database lower() function in PostgreSQL only works for ASCII strings. All other unicode and multibyte characters like capital umlaut are not properly converted. At the moment, when searching for pages we do the following comparison:

lower(page.title) = :pageTitle (Where :pageTitle is normally .toLowerCase() first before being passed in)

This special lower case function will skip the JAVA .toLowerCase() for postgres whose database lower() is ineffective.

Parameters:
str - the string to convert to lower case
Returns:
the lower cased string

replaceConfluenceHomeConstant

@Deprecated
public static java.lang.String replaceConfluenceHomeConstant(java.lang.String in,
                                                                        java.lang.String confHome)
Deprecated. since 5.5. Use replaceConfluenceConstants(String, java.io.File, java.io.File) instead.


replaceConfluenceConstants

public static java.lang.String replaceConfluenceConstants(java.lang.String in,
                                                          java.io.File home,
                                                          java.io.File localHome)
Replaces ConfluenceBootstrapConstants.CONFLUENCE_HOME_CONSTANT and ConfluenceBootstrapConstants.CONFLUENCE_LOCAL_HOME_CONSTANT in the given text with the correct paths.

Parameters:
in - text to make the replacements to
home - Confluence home directory
localHome - Confluence local home directory
Returns:
text with replacements
Since:
5.5

specialLowerCaseCollection

public static java.util.Collection<java.lang.String> specialLowerCaseCollection(java.util.Collection<java.lang.String> collection)
Takes a collection of Strings and lowercases the entries.

Parameters:
collection - the collection
Returns:
lowercased collection of strings

safeSubList

public static <T> java.util.List<T> safeSubList(java.util.List<T> list,
                                                int max)

summarise

public static java.lang.String summarise(java.lang.String content)
Parameters:
content - the content to summarise
Returns:
the summarised content

makeSummary

public static com.atlassian.bonnie.search.summary.Summary makeSummary(java.lang.String content)
Create a proper summary of this content fragment.

Parameters:
content - the string to summarise
Returns:
the summary object for the string
See Also:
Summarizer

makeSummary

public static com.atlassian.bonnie.search.summary.Summary makeSummary(java.lang.String content,
                                                                      @Nullable
                                                                      java.lang.String query)
Create a proper summary of this content fragment given a query

Parameters:
content - the string to summarise
query - the lucene query
Returns:
the summary object for the content and query
See Also:
Summarizer

makeFlatSummary

public static java.lang.String makeFlatSummary(java.lang.String content)
Create a summary of this content fragment.

Parameters:
content - the content to summarise
Returns:
the summary as a string
See Also:
Summarizer

makeFlatSummary

public static java.lang.String makeFlatSummary(java.lang.String content,
                                               @Nullable
                                               java.lang.String query)
Create a summary of this content fragment given a query

Parameters:
content - the content string
query - the lucene query string
Returns:
the summarised content and query
See Also:
Summarizer

getUserAccessor

public static UserAccessor getUserAccessor()

setUserAccessor

public static void setUserAccessor(UserAccessor userAcc)

getImageInfo

public static com.atlassian.core.util.ImageInfo getImageInfo(java.io.File pathToImage)

getNiceDuration

public static java.lang.String getNiceDuration(int minutes,
                                               int seconds)

getCompactDuration

public static java.lang.String getCompactDuration(long time)
Returns the duration in a compact HH:mm:ss format.

Parameters:
time - duration in milliseconds
Returns:
the duration in a compact HH:mm:ss format.

newWiredConfluenceActionSupport

public static ConfluenceActionSupport newWiredConfluenceActionSupport()

profilePush

public static void profilePush(java.lang.String s)

profilePop

public static void profilePop(java.lang.String s)

lookupDomainName

public static java.lang.String lookupDomainName(javax.servlet.http.HttpServletRequest request)
Get the default domain name.

Parameters:
request - the request
Returns:
null if request is null, otherwise a base URL derived from the request.

getGlobalSettings

public static Settings getGlobalSettings()

personalSpaceUrl

public static java.lang.String personalSpaceUrl(java.lang.String contextPath,
                                                java.lang.String username)
Deprecated. since 5.0 You should instead retrieve the space using SpaceManager and call getUrlPath on the Space object. Also note that if a user has been renamed (which is possible from Confluence 5.3 onwards) then this method is likely to return the wrong key.


getPercentage

public static long getPercentage(long numerator,
                                 long denom)
converts a fraction into a percentage

Parameters:
numerator - the number to include in the percentage
denom - the total number
Returns:
the percentage as a long integer, rounded

subtract

@Deprecated
public long subtract(long a,
                                long b)
Deprecated. since 5.0. Just use a minus sign.


getPercentage

public static long getPercentage(java.lang.String numeratorAsString,
                                 java.lang.String denomAsString)

subtract

@Deprecated
public long subtract(java.lang.String firstOperandAsString,
                                java.lang.String secondOperandAsString)
Deprecated. since 5.0. Just say no.


getConfluenceTempDirectoryPath

@Deprecated
public static java.lang.String getConfluenceTempDirectoryPath()
Deprecated. since 5.5. Use getLocalTempDirectory() instead.


getConfluenceTempDirectory

@Deprecated
public static java.io.File getConfluenceTempDirectory()
Deprecated. since 5.5. Use getLocalTempDirectory() instead.


getLocalTempDirectory

public static java.io.File getLocalTempDirectory()
Checks if local temp directory exists before returning the path. Create it if it doesn't already exist.

Returns:
path to temp directory inside local home
Since:
5.5

getSharedTempDirectory

public static java.io.File getSharedTempDirectory()
Checks if shared temp directory exists before returning the path. Create it if it doesn't already exist.

Returns:
path to temp directory inside shared home
Since:
5.5

splitCommaDelimitedString

public static java.lang.String[] splitCommaDelimitedString(java.lang.String escapedNames)
Method will turn a String of comma separated entities into a String Array. Spaces before or after the comma will be cropped. Backslashes are treated as escaped characters. Eg when "backslash""comma" is encountered, the backslash is discarded and the comma is not treated as a delimiter.

Parameters:
escapedNames - Comma delimited string with original commas and backslashes escaped by backslashes
Returns:
String[] of escapedNames

escapeCommas

public static java.util.List<java.lang.String> escapeCommas(java.util.List<java.lang.String> toEscape)
Escape commas on each entry in the given list of strings.

Parameters:
toEscape - Strings to escape
Returns:
escaped Strings

escapeCommas

public static java.lang.String escapeCommas(java.lang.String toEscape)
Escapes commas and backslashes with leading backslashes.

Parameters:
toEscape - string to escape. If null, then null will be returned.
Returns:
the escaped string

constrainLength

public static java.lang.String constrainLength(java.lang.String s,
                                               int length)
Truncate a string after n characters

Parameters:
s - The String to truncate
length - The maximum length allowed.
Returns:
The truncated String -- or the original String if no truncation was needed.

isOutgoingMailConfigured

@Deprecated
public static boolean isOutgoingMailConfigured()
Deprecated. since v5.0. Use MailServerManager.isDefaultSMTPMailServerDefined() instead.


convertBeanToMap

public static java.util.Map<java.lang.String,java.lang.String> convertBeanToMap(java.lang.Object bean)
Parameters:
bean - a bean to be converted to a Map.
Returns:
a Map where the keys are the property names from the beans, and the values are the property values. An empty Map will be returned if the bean cannot be converted.

prefixAllMapKeys

public static <K,V> java.util.Map<K,V> prefixAllMapKeys(java.lang.String prefix,
                                                        java.util.Map<K,V> map)
Convert the supplied Map so that all of the keys in the Map are prefixed by the supplied String followed by a full stop. e.g. monkey could become howler.monkey.

If any of the keys in the Map are not Strings then they will be ignored.

Parameters:
prefix - the prefix to be pre-pended to each Map key, if null then the original Map will be returned.
map - the Map to be modified. If null, then an empty Map will be returned.
Returns:
a new Map containing the modified keys and the supplied values.

isDefaultUserProfilePicture

@Deprecated
public static boolean isDefaultUserProfilePicture(java.lang.String username)
Deprecated. since 2.7. Use UserAccessor.getUserProfilePicture(com.atlassian.user.User).

Parameters:
username - the username to check
Returns:
true of they are using the default profile picture, false otherwise

rdfEncode

public static java.lang.String rdfEncode(java.lang.String s)
A fairly evil hack to work around CONF-10364. It sucks, but is necessary.

Parameters:
s - to encode
Returns:
the input String with double hyphens replaced by --

populateSimpleMessage

public static java.lang.String populateSimpleMessage(java.lang.String template,
                                                     java.util.List<java.lang.String> values)

Populate the template String supplied using the given values. The template may contain place holders which are denoted numerically in the form {n} where n is an index into the supplied values list.

e.g. "The template called {1} will expects a colour here {0}".

This template will use value 0 and value 1 from the supplied values array. If the referenced value cannot be found then the place holder will simply be removed.

Parameters:
template - the template to be populated
values - the values used to populate the template
Returns:
a populated template with all place holder markers removed.

getRandomSubSet

public static <T> java.util.List<T> getRandomSubSet(java.util.List<T> list,
                                                    int sizeOfSubset,
                                                    java.util.Random random)
Returns a randomised subset of the list provided. If the size of the subset is larger than the list, the entire list is returned in a random order.

Parameters:
list - - the list to subset
sizeOfSubset - - the size of the subset to return
random - - the source of randomness
Returns:
a randomised subset of the list

trimDownStringToWord

public static java.lang.String trimDownStringToWord(java.lang.String s)

isDateWithin24Hours

public static boolean isDateWithin24Hours(java.util.Date date)
Determines if given date is within 24 hours

Parameters:
date -
Returns:

refineOsDestination

public static java.lang.String refineOsDestination(java.lang.String osDestination)
Escape XML and replace all space with %20

Parameters:
osDestination -
Returns:

removeEmailsFromString

public static java.lang.String removeEmailsFromString(java.lang.String text)
Remove all emails from text

Parameters:
text -
Returns:


Copyright © 2003-2014 Atlassian. All Rights Reserved.