Class GeneralUtil
- java.lang.Object
-
- com.atlassian.confluence.util.GeneralUtil
-
public final class GeneralUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description GeneralUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
alwaysMaskEmail(String emailAddress)
Masks an email address by replacing '@' with 'at' and '.' with 'dot'.static String
appendAmpersandOrQuestionMark(String str)
Appends an ampersand if the given string already contains a question mark, or a question mark otherwise.static int
arraySize(int[] array)
Deprecated.since 7.3.0, no replacementstatic String
base64Decode(String s)
static String
base64Encode(String s)
static String
cleanQuietly(String stringToClean)
Sanitizes the input by removing unsafe elements or attributes.static String
completeUrlEncode(String url)
Deprecated.since 6.10.0 UseHtmlUtil.completeUrlEncode(String)
instead.static String
constrainLength(String s, int length)
Deprecated.since 7.3.0, useStringUtils.truncate(String, int)
insteadstatic Map<String,String>
convertBeanToMap(Object bean)
static Date
convertMailFormatDate(String date)
static @Nullable Boolean
convertToBoolean(Object obj)
Deprecated.since 7.3.0, no replacementstatic boolean
convertToBoolean(Object bool, boolean defaultValue)
Deprecated.since 7.3.0, no replacementstatic Character
convertToCharacter(Object obj)
Deprecated.since 7.3.0, no replacementstatic Integer
convertToInteger(Object obj)
static String
convertToString(Object obj)
Deprecated.since 7.3.0, no replacementstatic void
copyDate(Calendar original, Calendar copy)
Takes two calendar objects and sets the Date of the second to the Date of the first.static File
createTempDirectoryInConfluenceTemp(String prefix)
static File
createTempFile(String directory)
static 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#addcommentstatic String
displayShortUrl(String url)
static String
displayShortUrl(String url, int length)
static String
doubleUrlEncode(String url)
Deprecated.since 6.10.0, No replacementstatic void
elapse(String tag)
Add elapsed time to HttpRequestStatsstatic String
escapeCDATA(String s)
static String
escapeCommas(String toEscape)
Escapes commas and backslashes with leading backslashes.static List<String>
escapeCommas(List<String> toEscape)
Deprecated.since 7.3.0, no replacement, use java stream api in combination withescapeCommas(String)
static String
escapeForHtmlAttribute(String s)
Deprecated.since 7.3.0, useHtmlUtil.htmlEncode(String)
to escape an HTML attribute orStringEscapeUtils.escapeEcmaScript(String)
to have similar behaviourstatic String
escapeForJavascript(String s)
Escapes ', " and \ with a leading \.static String[]
escapeXml(Object[] args)
Produces an array of XML escapedString
s from a list of Objects.static String
escapeXml(String stringToEscape)
static @Nullable String
escapeXMLCharacters(@Nullable String input)
Deprecated.since 7.3.0, useescapeXml(String)
static <T> List<T>
filterNulls(Collection<T> in)
Deprecated.since 7.3.0, no replacement, use Java's stream apistatic String
findAndMaskEmail(String text, com.atlassian.user.User currentUser)
static void
flushResponse()
Flushes response writer.static String
formatLongTime(long time)
static String
getAttachmentUrl(Attachment attachment)
Get the permalink URL to preview the given attachment in the previewer.static Date
getBuildDate()
static String
getBuildDateString()
static String
getBuildNumber()
static String
getCharacterEncoding()
static String
getCommentUrl(Attachment attachment, Comment comment)
Get the permalink URL to preview the given comment (annotation) in the previewer.static String
getCompactDuration(long time)
Returns the duration in a compact HH:mm:ss format.static File
getConfluenceTempDirectory()
Deprecated.since 5.5.static String
getConfluenceTempDirectoryPath()
Deprecated.since 5.5.static String
getCookieValue(String key)
static String
getCookieValue(javax.servlet.http.HttpServletRequest request, String key)
static ResourceBundle
getDefaultResourceBundle()
static String
getEditPageUrl(AbstractPage page)
Get a resume draft URL that includes the shareDraftidstatic String
getFormatDateSimple(Date date)
static Settings
getGlobalSettings()
static I18NBean
getI18n()
static String
getIdBasedPageUrl(AbstractPage page)
Get page URL that is id based (i.e.static com.atlassian.core.util.ImageInfo
getImageInfo(File pathToImage)
static File
getLocalTempDirectory()
Deprecated.since 7.12static String
getNiceDuration(int minutes, int seconds)
static String
getOriginalUrl(javax.servlet.http.HttpServletRequest request)
static String
getPageUrl(VersionHistorySummary summary)
static String
getPageUrl(AbstractPage page)
static Comment
getParentComment(Comment comment)
Returns the top-level comment that the comment is attached tostatic @Nullable AbstractPage
getParentPageOrBlog(Contained content)
returns the page or blog that the content is attached to, or null if it is not attached to a page or blog.static long
getPercentage(long numerator, long denom)
converts a fraction into a percentagestatic long
getPercentage(String numeratorAsString, String denomAsString)
static <T> List<T>
getRandomSubSet(List<T> list, int sizeOfSubset, Random random)
Returns a randomised subset of the list provided.static String
getRelativeTime(Date date)
Deprecated.since 2.7 useFriendlyDateFormatter
static String
getRequestCorrelationId()
Returns request correlation idstatic Duration
getServerRenderTime(javax.servlet.ServletRequest servletRequest)
Calculates the duration of the requeststatic File
getSharedTempDirectory()
Deprecated.since 7.12static String
getStackTrace(Throwable t)
static Long
getSystemStartupTime()
static Unzipper
getUnzipper(File zipFile, File dirToExtractTo)
static Unzipper
getUnzipper(URL zipUrl, File dirToExtractTo)
static String
getUploadFileTooLargeMessage(String errorMessage)
If this error message is of the type: "Content Length Error" convert it to something nicer.static UserAccessor
getUserAccessor()
Deprecated.since 7.3.0, use component injectionstatic String
getVersionNumber()
static String
hackSingleQuotes(String s)
Deprecated.since 7.3.0, useStringEscapeUtils.escapeEcmaScript(String)
insteadstatic boolean
hasTooManyUsers()
Deprecated.since 5.10 UseUserAccessor.isLicensedToAddMoreUsers()
static String
highlight(String content, String searchWords)
static String
htmlEncode(String text)
Deprecated.since 6.10.0 UseHtmlUtil.htmlEncode(String)
instead)static String
htmlEncodeAndReplaceSpaces(String text)
Deprecated.since 6.10.0 UseHtmlUtil.htmlEncodeAndReplaceSpaces(String)
instead)static String
htmlEscapeQuotes(String input)
Deprecated.since 7.3.0, useStringEscapeUtils.escapeEcmaScript(String)
combined withHtmlUtil.htmlEncode(String)
or template-level automatic escapingstatic boolean
isAllAscii(String s)
static boolean
isAllLettersOrNumbers(String s)
static boolean
isDateWithin24Hours(Date date)
Determines if given date is within 24 hoursstatic boolean
isInLastDays(Date date, int maxDays)
static boolean
isLicenseExpired()
static boolean
isSafeTitleForFilesystem(String title)
Ensure the title is safe to be written to the file system.static boolean
isSafeTitleForUrl(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 String
lookupDomainName(javax.servlet.http.HttpServletRequest request)
Get the default domain name.static String
makeFlatSummary(String content)
Create a summary of this content fragment.static String
makeFlatSummary(String content, @Nullable String query)
Create a summary of this content fragment given a querystatic Summary
makeSummary(String content)
Create a proper summary of this content fragment.static Summary
makeSummary(String content, @Nullable String query)
Create a proper summary of this content fragment given a querystatic String
maskEmail(String emailAddress)
If configured, masks an email address to defeat the most simplistic spam bots.static String
maskEmail(String emailAddress, Settings globalSettings)
static String
maskEmail(String emailAddress, Settings globalSettings, I18NBean i18NBean)
Deprecated.since 7.3.0, usemaskEmail(String, Settings)
static ConfluenceActionSupport
newWiredConfluenceActionSupport()
Deprecated.since 8.0 no replacementstatic ConfluenceActionSupport
newWiredConfluenceActionSupport(@Nullable Space space)
Deprecated.since 8.0 no replacementstatic String
plain2html(String text)
static String
populateSimpleMessage(String template, List<String> values)
Populate the template String supplied using the given values.static <K,V>
Map<K,V>prefixAllMapKeys(String prefix, 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(String s)
Deprecated.since 7.0.static void
profilePush(String s)
Deprecated.since 7.0.static String
rdfEncode(String s)
A fairly evil hack to work around CONF-10364.static String
refineOsDestination(String osDestination)
Escape XML and replace all space with %20static String
removeEmailsFromString(String text)
Remove all emails from textstatic String
replaceConfluenceConstants(String in, File home, File localHome)
ReplacesConfluenceBootstrapConstants.CONFLUENCE_HOME_CONSTANT
andConfluenceBootstrapConstants.CONFLUENCE_LOCAL_HOME_CONSTANT
in the given text with the correct paths.static String
replaceConfluenceHomeConstant(String in, String confHome)
Deprecated.since 5.5.static String
replaceInvalidXmlCharacters(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> List<T>
safeSubList(List<T> list, int max)
static javax.servlet.http.Cookie
setCookie(String key, String value)
Sets a cookie.static void
setSystemStartupTime(Long systemStartupTime)
static String
shortenString(String str, int max)
Returns a substring of the specified string if it is longer than max.static boolean
shouldUrlDecode(String str)
Deprecated.since 6.10.0 UseHtmlUtil.shouldUrlDecode(String)
instead.List<String>
sortList(List<String> list)
Sorts a list of strings alphabetically in ascending order.static Collection<String>
specialLowerCaseCollection(Collection<String> collection)
Deprecated.since 7.3.0, no replacement, use java stream api in combination withspecialToLowerCase(String)
static String
specialToLowerCase(String str)
the database lower() function in PostgreSQL only works for ASCII strings.static String[]
splitCommaDelimitedString(String escapedNames)
Method will turn a String of comma separated entities into a String Array.static boolean
stringSet(String str)
Deprecated.since 5.10 UseStringUtils.isNotEmpty(CharSequence)
static String
summarise(String content)
static Date
toEndOfMonth(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 String
trimDownStringToWord(String s)
static String
unescapeCDATA(String s)
static String
unescapeEntities(String str)
static void
unzipFile(File zipFile, File dirToExtractTo)
Unzips the zip file to the destination directorystatic void
unzipUrl(URL zipUrl, File dirToExtractTo)
Unzips the zip url to the destination directory.static String
urlDecode(String url)
Deprecated.since 6.10.0 UseHtmlUtil.urlDecode(String)
instead.static String
urlEncode(String url)
Deprecated.since 6.10.0 UseHtmlUtil.urlEncode(String)
instead.static String
urlEncode(String value, String encoding)
Deprecated.since 6.10.0 UseHtmlUtil.urlEncode(String, String)
instead.static String
wordWrap(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
-
-
-
Method Detail
-
convertMailFormatDate
public static Date convertMailFormatDate(String date) throws ParseException
- Throws:
ParseException
-
convertToCharacter
@Deprecated public static Character convertToCharacter(Object obj)
Deprecated.since 7.3.0, no replacement
-
convertToBoolean
@Deprecated public static @Nullable Boolean convertToBoolean(Object obj)
Deprecated.since 7.3.0, no replacement
-
convertToBoolean
@Deprecated public static boolean convertToBoolean(Object bool, boolean defaultValue)
Deprecated.since 7.3.0, no replacement
-
convertToString
@Deprecated public static String convertToString(Object obj)
Deprecated.since 7.3.0, no replacement
-
getOriginalUrl
public static String getOriginalUrl(javax.servlet.http.HttpServletRequest request)
-
completeUrlEncode
@Deprecated public static String completeUrlEncode(String url)
Deprecated.since 6.10.0 UseHtmlUtil.completeUrlEncode(String)
instead.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.- Parameters:
url
- - the entire URL to encode- Returns:
- encoded url
-
urlEncode
@Deprecated public static String urlEncode(String url)
Deprecated.since 6.10.0 UseHtmlUtil.urlEncode(String)
instead.A utility method to encode HTTP form parameter/values. To encode entire URLs, use completeUrlEncode() instead.- Parameters:
url
- - part of the url to encode- Returns:
- encoded url
-
urlEncode
@Deprecated public static String urlEncode(String value, String encoding)
Deprecated.since 6.10.0 UseHtmlUtil.urlEncode(String, String)
instead.
-
urlDecode
@Deprecated public static String urlDecode(String url)
Deprecated.since 6.10.0 UseHtmlUtil.urlDecode(String)
instead.
-
shouldUrlDecode
@Deprecated public static boolean shouldUrlDecode(String str)
Deprecated.since 6.10.0 UseHtmlUtil.shouldUrlDecode(String)
instead.
-
getPageUrl
public static String getPageUrl(VersionHistorySummary summary)
-
getPageUrl
public static String getPageUrl(AbstractPage page)
-
getIdBasedPageUrl
public static 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
-
getEditPageUrl
public static String getEditPageUrl(AbstractPage page)
Get a resume draft URL that includes the shareDraftid- Parameters:
page
- the page to generate an edit url for- Returns:
- The edit URL for that page
- Since:
- 6.1
-
getAttachmentUrl
public static String getAttachmentUrl(Attachment attachment)
Get the permalink URL to preview the given attachment in the previewer.- Parameters:
attachment
- the attachment to generate an URL for.- Returns:
- permalink URL for the attachment.
-
getCommentUrl
public static String getCommentUrl(Attachment attachment, Comment comment)
Get the permalink URL to preview the given comment (annotation) in the previewer.- Parameters:
attachment
- the attachment that the annotation is on.comment
- the annotation to generate the url for.- Returns:
- permalink URL for the annotation.
-
getParentPageOrBlog
public static @Nullable AbstractPage getParentPageOrBlog(Contained content)
returns the page or blog that the content is attached to, or null if it is not attached to a page or blog.- Parameters:
content
- content to check for containing page or blog.- Returns:
- container page or blog.
-
getParentComment
public static Comment getParentComment(Comment comment)
Returns the top-level comment that the comment is attached to- Parameters:
comment
- comment to check for parent comment- Returns:
- top-level parent comment
-
isSafeTitleForUrl
public static boolean isSafeTitleForUrl(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(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 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 &
-
appendAmpersandOrQuestionMark
public static String appendAmpersandOrQuestionMark(String str)
Appends an ampersand if the given string already contains a question mark, or a question mark otherwise.- Parameters:
str
- the string to prepare for adding a query param to.- Returns:
- the given string with a question mark
- Since:
- 5.7
-
wordWrap
public static String wordWrap(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 = uglywe want to simulate IE's word-wrap/break function here
- Parameters:
str
- the string to wrapmax
- max length of string allowed per line- Returns:
- The wrapped string
-
doubleUrlEncode
@Deprecated public static String doubleUrlEncode(String url)
Deprecated.since 6.10.0, No replacement
-
isAllAscii
public static boolean isAllAscii(String s)
-
isAllLettersOrNumbers
public static boolean isAllLettersOrNumbers(String s)
-
getVersionNumber
public static String getVersionNumber()
-
getBuildDate
public static Date getBuildDate()
-
getBuildDateString
public static String getBuildDateString()
-
getBuildNumber
public static String getBuildNumber()
- Returns:
- The build number of the currently running Confluence instance.
- See Also:
BuildInformation.getBuildNumber()
-
getSystemStartupTime
public static Long getSystemStartupTime()
-
setSystemStartupTime
public static void setSystemStartupTime(Long systemStartupTime)
-
isLicenseExpired
public static boolean isLicenseExpired()
-
hasTooManyUsers
@Deprecated public static boolean hasTooManyUsers()
Deprecated.since 5.10 UseUserAccessor.isLicensedToAddMoreUsers()
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
@Deprecated public static boolean stringSet(String str)
Deprecated.since 5.10 UseStringUtils.isNotEmpty(CharSequence)
-
formatLongTime
public static String formatLongTime(long time)
-
toEndOfMonth
public static Date toEndOfMonth(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(Calendar original, 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 objectcopy
- The destination calendar object
-
getCharacterEncoding
public static String getCharacterEncoding()
-
cleanQuietly
public static String cleanQuietly(String stringToClean)
Sanitizes the input by removing unsafe elements or attributes. It will keep the safe tags.For example, the input below,
<div><script>alert(1);</script></div>
will generate the following output,
<div></div>
- Parameters:
stringToClean
- - the string might contain unsafe contents.- Returns:
- the string where the unsafe contents have been removed.
-
escapeXml
public static String[] escapeXml(Object[] args)
Produces an array of XML escapedString
s from a list of Objects.String.valueOf(Object)
is used to produceString
s from theObject
s- Parameters:
args
- an array of objects- Returns:
- an array of XML escaped
String
s
-
escapeForJavascript
public static String escapeForJavascript(String s)
Escapes ', " and \ with a leading \.- Parameters:
s
- the string to escape- Returns:
- the escaped string
-
escapeForHtmlAttribute
@Deprecated public static String escapeForHtmlAttribute(String s)
Deprecated.since 7.3.0, useHtmlUtil.htmlEncode(String)
to escape an HTML attribute orStringEscapeUtils.escapeEcmaScript(String)
to have similar behaviourEscapes " 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 String maskEmail(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
@Deprecated public static String maskEmail(String emailAddress, Settings globalSettings, I18NBean i18NBean)
Deprecated.since 7.3.0, usemaskEmail(String, Settings)
-
maskEmail
public static String maskEmail(String emailAddress, Settings globalSettings)
- Since:
- 7.3.0
-
alwaysMaskEmail
public static String alwaysMaskEmail(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 String findAndMaskEmail(String text, com.atlassian.user.User currentUser)
-
createTempDirectoryInConfluenceTemp
public static File createTempDirectoryInConfluenceTemp(String prefix)
-
hackSingleQuotes
@Deprecated public static String hackSingleQuotes(String s)
Deprecated.since 7.3.0, useStringEscapeUtils.escapeEcmaScript(String)
insteadhack 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(Date date, int maxDays)
- Parameters:
date
- the date to checkmaxDays
- 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 String getRelativeTime(Date date)
Deprecated.since 2.7 useFriendlyDateFormatter
- Parameters:
date
- the date to convert to a relative time string- Returns:
- A relative time period, 'X hours, Y minutes ago'
-
setCookie
public static javax.servlet.http.Cookie setCookie(String key, 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 cookievalue
- the value of the cookie- Returns:
- the new Cookie object
-
getCookieValue
public static String getCookieValue(javax.servlet.http.HttpServletRequest request, String key)
-
htmlEncode
@Deprecated public static String htmlEncode(String text)
Deprecated.since 6.10.0 UseHtmlUtil.htmlEncode(String)
instead)
-
htmlEncodeAndReplaceSpaces
@Deprecated public static String htmlEncodeAndReplaceSpaces(String text)
Deprecated.since 6.10.0 UseHtmlUtil.htmlEncodeAndReplaceSpaces(String)
instead)
-
plain2html
public static String plain2html(String text)
- Parameters:
text
- the text to encode- Returns:
- the html encoded text
- See Also:
PlainTextToHtmlConverter
-
unzipFile
public static void unzipFile(File zipFile, File dirToExtractTo) throws IOException
Unzips the zip file to the destination directory- Parameters:
zipFile
- the zip file to extractdirToExtractTo
- the directory to extract the zip file to- Throws:
IOException
- if an IOException occurs
-
getUnzipper
public static Unzipper getUnzipper(File zipFile, File dirToExtractTo) throws IOException
- Throws:
IOException
-
unzipUrl
public static void unzipUrl(URL zipUrl, File dirToExtractTo) throws IOException
Unzips the zip url to the destination directory.- Parameters:
zipUrl
- the URL of the zip file to extractdirToExtractTo
- the directory to extract the zip file to- Throws:
IOException
- if an IOException occurs
-
getUploadFileTooLargeMessage
public static String getUploadFileTooLargeMessage(String errorMessage)
If this error message is of the type: "Content Length Error" convert it to something nicer.Error message is generated at
ConfluenceJakartaMultiPartRequest.buildIOExceptionMessage(org.apache.commons.fileupload.FileUploadException)
then first reformatted inFileUploadUtils.checkMultiPartRequestForErrors(org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper)
.- Parameters:
errorMessage
- the error message to convert- Returns:
- the nicer error message if it can be converted, else the input string
-
getDefaultResourceBundle
public static ResourceBundle getDefaultResourceBundle()
-
arraySize
@Deprecated public static int arraySize(int[] array)
Deprecated.since 7.3.0, no replacementconvenience 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
@Deprecated public static @Nullable String escapeXMLCharacters(@Nullable String input)
Deprecated.since 7.3.0, useescapeXml(String)
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 String replaceInvalidXmlCharacters(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
@Deprecated public static String htmlEscapeQuotes(String input)
Deprecated.since 7.3.0, useStringEscapeUtils.escapeEcmaScript(String)
combined withHtmlUtil.htmlEncode(String)
or template-level automatic escapingTake 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 functionsnull
input will be returned as an empty String.- Parameters:
input
- string to escape- Returns:
- the escaped string
-
filterNulls
@Deprecated public static <T> List<T> filterNulls(Collection<T> in)
Deprecated.since 7.3.0, no replacement, use Java's stream apiReturn 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 String shortenString(String str, int max)
Returns a substring of the specified string if it is longer than max. This method also appendsELLIPSIS
to the end of the string if it does truncate it.- Parameters:
str
- the string to shortenmax
- the maximum desired length of the result (excludingELLIPSIS
)- Returns:
- a substring of the specified string if it is longer than max.
- See Also:
StringUtils.abbreviate(String, int)
-
specialToLowerCase
public static String specialToLowerCase(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 String replaceConfluenceHomeConstant(String in, String confHome)
Deprecated.since 5.5. UsereplaceConfluenceConstants(String, java.io.File, java.io.File)
instead.
-
replaceConfluenceConstants
public static String replaceConfluenceConstants(String in, File home, File localHome)
ReplacesConfluenceBootstrapConstants.CONFLUENCE_HOME_CONSTANT
andConfluenceBootstrapConstants.CONFLUENCE_LOCAL_HOME_CONSTANT
in the given text with the correct paths.- Parameters:
in
- text to make the replacements tohome
- Confluence home directorylocalHome
- Confluence local home directory- Returns:
- text with replacements
- Since:
- 5.5
-
specialLowerCaseCollection
@Deprecated public static Collection<String> specialLowerCaseCollection(Collection<String> collection)
Deprecated.since 7.3.0, no replacement, use java stream api in combination withspecialToLowerCase(String)
Takes a collection of Strings and lowercases the entries.- Parameters:
collection
- the collection- Returns:
- lowercased collection of strings
-
summarise
public static String summarise(String content)
- Parameters:
content
- the content to summarise- Returns:
- the summarised content
-
makeSummary
public static Summary makeSummary(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 Summary makeSummary(String content, @Nullable String query)
Create a proper summary of this content fragment given a query- Parameters:
content
- the string to summarisequery
- the lucene query- Returns:
- the summary object for the content and query
- See Also:
Summarizer
-
makeFlatSummary
public static String makeFlatSummary(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 String makeFlatSummary(String content, @Nullable String query)
Create a summary of this content fragment given a query- Parameters:
content
- the content stringquery
- the lucene query string- Returns:
- the summarised content and query
- See Also:
Summarizer
-
getUserAccessor
@Deprecated public static UserAccessor getUserAccessor()
Deprecated.since 7.3.0, use component injection
-
getImageInfo
public static com.atlassian.core.util.ImageInfo getImageInfo(File pathToImage)
-
getNiceDuration
public static String getNiceDuration(int minutes, int seconds)
-
getCompactDuration
public static 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
@Deprecated(since="8.0") public static ConfluenceActionSupport newWiredConfluenceActionSupport()
Deprecated.since 8.0 no replacement
-
newWiredConfluenceActionSupport
@Deprecated(since="8.0") public static ConfluenceActionSupport newWiredConfluenceActionSupport(@Nullable Space space)
Deprecated.since 8.0 no replacementCreate a wiredConfluenceActionSupport
to be used for rendering a decorator.- Parameters:
space
- A space to add to the rendering context, if provided.- Since:
- 7.5.0
-
profilePush
@Deprecated public static void profilePush(String s)
Deprecated.since 7.0. UseTimers.start(String)
.- Parameters:
s
- the profiling frame name to push
-
profilePop
@Deprecated public static void profilePop(String s)
Deprecated.since 7.0. UseTimers.start(String)
and a try-finally block.- Parameters:
s
- the profiling frame name to pop
-
lookupDomainName
public static 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()
-
getPercentage
public static long getPercentage(long numerator, long denom)
converts a fraction into a percentage- Parameters:
numerator
- the number to include in the percentagedenom
- the total number- Returns:
- the percentage as a long integer, rounded
-
getConfluenceTempDirectoryPath
@Deprecated public static String getConfluenceTempDirectoryPath()
Deprecated.since 5.5. UsegetLocalTempDirectory()
instead.
-
getConfluenceTempDirectory
@Deprecated public static File getConfluenceTempDirectory()
Deprecated.since 5.5. UsegetLocalTempDirectory()
instead.
-
getLocalTempDirectory
@Deprecated public static File getLocalTempDirectory()
Deprecated.since 7.12Checks 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
@Deprecated public static File getSharedTempDirectory()
Deprecated.since 7.12Checks 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 String[] splitCommaDelimitedString(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
@Deprecated public static List<String> escapeCommas(List<String> toEscape)
Deprecated.since 7.3.0, no replacement, use java stream api in combination withescapeCommas(String)
Escape commas on each entry in the given list of strings.
-
escapeCommas
public static String escapeCommas(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
@Deprecated public static String constrainLength(String s, int length)
Deprecated.since 7.3.0, useStringUtils.truncate(String, int)
insteadTruncate a string after n characters- Parameters:
s
- The String to truncatelength
- The maximum length allowed.- Returns:
- The truncated String -- or the original String if no truncation was needed.
-
convertBeanToMap
public static Map<String,String> convertBeanToMap(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> Map<K,V> prefixAllMapKeys(String prefix, 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.
-
rdfEncode
public static String rdfEncode(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 String populateSimpleMessage(String template, List<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 populatedvalues
- the values used to populate the template- Returns:
- a populated template with all place holder markers removed.
-
getRandomSubSet
public static <T> List<T> getRandomSubSet(List<T> list, int sizeOfSubset, 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 subsetsizeOfSubset
- - the size of the subset to returnrandom
- - the source of randomness- Returns:
- a randomised subset of the list
-
isDateWithin24Hours
public static boolean isDateWithin24Hours(Date date)
Determines if given date is within 24 hours- Parameters:
date
-- Returns:
-
refineOsDestination
public static String refineOsDestination(String osDestination)
Escape XML and replace all space with %20- Parameters:
osDestination
-- Returns:
-
removeEmailsFromString
public static String removeEmailsFromString(String text)
Remove all emails from text- Parameters:
text
-- Returns:
-
getServerRenderTime
public static Duration getServerRenderTime(javax.servlet.ServletRequest servletRequest)
Calculates the duration of the request- Since:
- 5.9.0
-
getRequestCorrelationId
public static String getRequestCorrelationId()
Returns request correlation id- Since:
- 5.9.0
-
flushResponse
public static void flushResponse()
Flushes response writer. Logs error if exception occurs.- Since:
- 5.9.1
-
elapse
public static void elapse(String tag)
Add elapsed time to HttpRequestStats- Since:
- 5.9.1
- See Also:
HttpRequestStats
-
-