Package com.atlassian.confluence.util
Class VelocityUtil
java.lang.Object
com.atlassian.confluence.util.VelocityUtil
- Direct Known Subclasses:
GeneralUtil
Utility class for use in Velocity templates. Do NOT add any methods which mutate application state, or returns an
object which can. Such methods should be added to
GeneralUtil
instead.- Since:
- 9.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
static final VelocityUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Deprecated, for removal: This API element is subject to removal in a future version.static String
static String
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
doubleUrlEncode
(String url) Deprecated.since 6.10.0, No replacementstatic void
Add elapsed time to HttpRequestStatsstatic String[]
Produces an array of XML escapedString
s from a list of Objects.static String
static String
findAndMaskEmail
(String text, com.atlassian.user.User currentUser) static void
Flushes response writer.static String
static String
static String
getFormatDateSimple
(Date date) static String
getLinkLoginPath
(javax.servlet.http.HttpServletRequest request) This method deliberately duplicates the method inSeraphUtils
for the purpose of exposing it on the Velocity context viaVelocityUtil
.static String
getLinkLoginUrl
(javax.servlet.http.HttpServletRequest request) This method deliberately duplicates the method inSeraphUtils
for the purpose of exposing it on the Velocity context viaVelocityUtil
.static String
Returns request correlation idstatic Duration
getServerRenderTime
(javax.servlet.ServletRequest servletRequest) Calculates the duration of the requeststatic String
static String
htmlEscapeQuotes
(String input) Deprecated.since 7.3.0, useStringEscapeUtils.escapeEcmaScript(String)
combined withHtmlUtil.htmlEncode(String)
or template-level automatic escapingintArrayToList
(int[] array) Velocity <=1.6 cannot invoke methods against an array.static boolean
isAllAscii
(String s) protected static boolean
isAscii
(char c) static boolean
isDateWithin24Hours
(Date date) Determines if given date is within 24 hoursstatic boolean
isInLastDays
(Date date, int maxDays) static boolean
Deprecated.since 8.7 UseLicenseService.retrieve()
andProductLicense.isExpired()
static String
lookupDomainName
(javax.servlet.http.HttpServletRequest request) Get the default domain name.static String
makeFlatSummary
(String content, @Nullable String query) Create a summary of this content fragment given a querystatic Summary
makeSummary
(String content, @Nullable String query) Create a proper summary of this content fragment given a querystatic String
static String
plain2html
(String text) static void
profilePop
(String s) Deprecated.since 7.0.static void
Deprecated.since 7.0.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.static <T> List<T>
safeSubList
(List<T> list, int max) static String
shortenString
(String str, int max) Returns a substring of the specified string if it is longer than max.Sorts a list of strings alphabetically in ascending order without the mutating original list.static String
static String
-
Field Details
-
INSTANCE
-
DEFAULT_CHARACTER_ENCODING
- See Also:
-
ELLIPSIS
- See Also:
-
-
Constructor Details
-
VelocityUtil
protected VelocityUtil()
-
-
Method Details
-
customGetPageUrl
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
Deprecated, for removal: This API element is subject to removal in a future version.since 8.6 useUrlUtils.appendAmpersandOrQuestionMark(String)
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
-
doubleUrlEncode
Deprecated.since 6.10.0, No replacement -
isAllAscii
-
isAscii
protected static boolean isAscii(char c) -
getVersionNumber
-
getBuildNumber
- Returns:
- The build number of the currently running Confluence instance.
- See Also:
-
isLicenseExpired
Deprecated.since 8.7 UseLicenseService.retrieve()
andProductLicense.isExpired()
-
getCharacterEncoding
-
escapeXml
-
escapeXml
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
-
maskEmail
- Since:
- 7.3.0
-
findAndMaskEmail
-
base64Decode
-
base64Encode
-
isInLastDays
- Parameters:
date
- the date to checkmaxDays
- the number of days into the past the date can fall- Returns:
- whether the date falls within maxDays before the present.
-
getFormatDateSimple
-
plain2html
- Parameters:
text
- the text to encode- Returns:
- the html encoded text
- See Also:
-
htmlEscapeQuotes
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
-
shortenString
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)
-
replaceConfluenceConstants
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
-
safeSubList
-
summarise
- Parameters:
content
- the content to summarise- Returns:
- the summarised content
-
makeSummary
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:
-
makeFlatSummary
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:
-
lookupDomainName
Get the default domain name.- Parameters:
request
- the request- Returns:
- null if request is null, otherwise a base URL derived from the request.
-
trimDownStringToWord
-
isDateWithin24Hours
Determines if given date is within 24 hours -
getServerRenderTime
Calculates the duration of the request- Since:
- 5.9.0
-
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
Add elapsed time to HttpRequestStats- Since:
- 5.9.1
- See Also:
-
sortList
Sorts a list of strings alphabetically in ascending order without the mutating original list.- Parameters:
list
- a list of strings- Returns:
- the list sorted alphabetically
-
profilePush
Deprecated.since 7.0. UseTimers.start(String)
.- Parameters:
s
- the profiling frame name to push
-
profilePop
Deprecated.since 7.0. UseTimers.start(String)
and a try-finally block.- Parameters:
s
- the profiling frame name to pop
-
getLinkLoginUrl
This method deliberately duplicates the method inSeraphUtils
for the purpose of exposing it on the Velocity context viaVelocityUtil
. TheSeraphUtils
class is not safe for direct exposure on the Velocity context. -
getLinkLoginPath
This method deliberately duplicates the method inSeraphUtils
for the purpose of exposing it on the Velocity context viaVelocityUtil
. TheSeraphUtils
class is not safe for direct exposure on the Velocity context. -
intArrayToList
Velocity <=1.6 cannot invoke methods against an array.
-
UrlUtils.appendAmpersandOrQuestionMark(String)