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
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringstatic final VelocityUtil -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringDeprecated, for removal: This API element is subject to removal in a future version.static Stringstatic Stringstatic StringcustomGetPageUrl(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 StringdoubleUrlEncode(String url) Deprecated.since 6.10.0, No replacementstatic voidAdd elapsed time to HttpRequestStatsstatic String[]Produces an array of XML escapedStrings from a list of Objects.static Stringstatic StringfindAndMaskEmail(String text, com.atlassian.user.User currentUser) static voidFlushes response writer.static Stringstatic Stringstatic StringgetFormatDateSimple(Date date) static StringgetLinkLoginPath(jakarta.servlet.http.HttpServletRequest request) This method deliberately duplicates the method inSeraphUtilsfor the purpose of exposing it on the Velocity context viaVelocityUtil.static StringgetLinkLoginUrl(jakarta.servlet.http.HttpServletRequest request) This method deliberately duplicates the method inSeraphUtilsfor the purpose of exposing it on the Velocity context viaVelocityUtil.static StringReturns request correlation idstatic DurationgetServerRenderTime(jakarta.servlet.ServletRequest servletRequest) Calculates the duration of the requeststatic Stringstatic StringhtmlEscapeQuotes(String input) Deprecated.since 7.3.0, useStringEscapeUtils.escapeEcmaScript(String)combined withHtmlUtil.htmlEncode(String)or template-level automatic escapingintArrayToList(int[] array) Velocity invalid input: '<'=1.6 cannot invoke methods against an array.static booleanisAllAscii(String s) protected static booleanisAscii(char c) static booleanisDateWithin24Hours(Date date) Determines if given date is within 24 hoursstatic booleanisInLastDays(Date date, int maxDays) static booleanDeprecated.since 8.7 UseLicenseService.retrieve()andProductLicense.isExpired()static StringlookupDomainName(jakarta.servlet.http.HttpServletRequest request) Get the default domain name.static StringmakeFlatSummary(String content, @Nullable String query) Create a summary of this content fragment given a querystatic SummarymakeSummary(String content, @Nullable String query) Create a proper summary of this content fragment given a querystatic Stringstatic Stringplain2html(String text) static voidprofilePop(String s) Deprecated.since 7.0.static voidDeprecated.since 7.0.static StringreplaceConfluenceConstants(String in, File home, File localHome) ReplacesConfluenceBootstrapConstants.CONFLUENCE_HOME_CONSTANTandConfluenceBootstrapConstants.CONFLUENCE_LOCAL_HOME_CONSTANTin the given text with the correct paths.static <T> List<T> safeSubList(List<T> list, int max) static StringshortenString(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 Stringstatic 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 invalid input: '&'
-
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 escapedStrings from a list of Objects.String.valueOf(Object)is used to produceStrings from theObjects- Parameters:
args- an array of objects- Returns:
- an array of XML escaped
Strings
-
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 functionsnullinput 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 appendsELLIPSISto 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:
-
replaceConfluenceConstants
ReplacesConfluenceBootstrapConstants.CONFLUENCE_HOME_CONSTANTandConfluenceBootstrapConstants.CONFLUENCE_LOCAL_HOME_CONSTANTin 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 inSeraphUtilsfor the purpose of exposing it on the Velocity context viaVelocityUtil. TheSeraphUtilsclass is not safe for direct exposure on the Velocity context. -
getLinkLoginPath
This method deliberately duplicates the method inSeraphUtilsfor the purpose of exposing it on the Velocity context viaVelocityUtil. TheSeraphUtilsclass is not safe for direct exposure on the Velocity context. -
intArrayToList
Velocity invalid input: '<'=1.6 cannot invoke methods against an array.
-
UrlUtils.appendAmpersandOrQuestionMark(String)