Package com.atlassian.confluence.util
Class GeneralUtil
java.lang.Object
com.atlassian.confluence.util.VelocityUtil
com.atlassian.confluence.util.GeneralUtil
Extension of
VelocityUtil
that contain methods that are not needed or safe for use in Velocity templates.-
Field Summary
FieldsFields inherited from class com.atlassian.confluence.util.VelocityUtil
DEFAULT_CHARACTER_ENCODING, ELLIPSIS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
alwaysMaskEmail
(String emailAddress) Masks an email address by replacing '@' with 'at' and '.' with 'dot'.static <T,
S> S applyIfNonNull
(T delegate, Function<T, S> wrapper) convertBeanToMap
(Object bean) Deprecated, for removal: This API element is subject to removal in a future version.static void
Takes two calendar objects and sets the Date of the second to the Date of the first.static File
static String
displayShortUrl
(String url) static String
displayShortUrl
(String url, int length) static String
static String
Escapes ', " and \ with a leading \.static <T> T
executeRetryableTransaction
(com.atlassian.sal.api.rdbms.TransactionalExecutor executor, com.atlassian.sal.api.rdbms.ConnectionCallback<T> callback) Imperative alternative toRetryableTransaction
.static String
getAttachmentUrl
(Attachment attachment) Get the permalink URL to preview the given attachment in the previewer.static String
getCommentUrl
(Attachment attachment, Comment comment) Get the permalink URL to preview the given comment (annotation) in the previewer.static Charset
static String
getEditPageUrl
(AbstractPage page) Get a resume draft URL that includes the shareDraftidstatic Settings
static I18NBean
getI18n()
static String
Get page URL that is id based (i.e.static String
getOriginalPath
(javax.servlet.http.HttpServletRequest request) Get the original request path, i.e.static String
getOriginalUrl
(javax.servlet.http.HttpServletRequest request) 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 String
getRequestPath
(javax.servlet.http.HttpServletRequest request) As opposed togetOriginalPath(javax.servlet.http.HttpServletRequest)
, the returned path will be decoded.static String
getRequestUrl
(javax.servlet.http.HttpServletRequest request) static Long
static boolean
Deprecated.since 9.3 unusedstatic boolean
Returns whether container is ready and setup is complete.static boolean
static String
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 void
setSystemStartupTime
(Long systemStartupTime) static String
specialToLowerCase
(String str) The database lower() function in PostgreSQL only works for ASCII strings.static String
specialToLowerCase
(String str, com.atlassian.config.ApplicationConfiguration appConfig) static String[]
splitCommaDelimitedString
(String escapedNames) Method will turn a String of comma separated entities into a String Array.static Date
toEndOfMonth
(Calendar postDate, boolean isSqlServer) Deprecated, for removal: This API element is subject to removal in a future version.since 8.6static String
static String
unescapeEntities
(String str) Methods inherited from class com.atlassian.confluence.util.VelocityUtil
appendAmpersandOrQuestionMark, base64Decode, base64Encode, customGetPageUrl, doubleUrlEncode, elapse, escapeXml, escapeXml, findAndMaskEmail, flushResponse, getBuildNumber, getCharacterEncoding, getFormatDateSimple, getLinkLoginPath, getLinkLoginUrl, getRequestCorrelationId, getServerRenderTime, getVersionNumber, htmlEscapeQuotes, intArrayToList, isAllAscii, isAscii, isDateWithin24Hours, isInLastDays, isLicenseExpired, lookupDomainName, makeFlatSummary, makeSummary, maskEmail, plain2html, profilePop, profilePush, replaceConfluenceConstants, safeSubList, shortenString, sortList, summarise, trimDownStringToWord
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
GeneralUtil
public GeneralUtil()
-
-
Method Details
-
setSystemStartupTime
-
getSystemStartupTime
-
createTempDirectoryInConfluenceTemp
-
getRequestPath
As opposed togetOriginalPath(javax.servlet.http.HttpServletRequest)
, the returned path will be decoded. -
getRequestUrl
-
getOriginalPath
Get the original request path, i.e. the path that was requested by the user. -
getOriginalUrl
-
getIdBasedPageUrl
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
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
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
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
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
Returns the top-level comment that the comment is attached to- Parameters:
comment
- comment to check for parent comment- Returns:
- top-level parent comment
-
isAllAsciiLettersOrNumbers
Deprecated.since 9.3 unused -
displayShortUrl
-
displayShortUrl
-
toEndOfMonth
@Deprecated(forRemoval=true) public static Date toEndOfMonth(Calendar postDate, boolean isSqlServer) Deprecated, for removal: This API element is subject to removal in a future version.since 8.6Takes 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
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
-
getDefaultCharset
-
escapeForJavascript
Escapes ', " and \ with a leading \.- Parameters:
s
- the string to escape- Returns:
- the escaped string
-
isSetupComplete
public static boolean isSetupComplete() -
isReadyToServe
public static boolean isReadyToServe()Returns whether container is ready and setup is complete. The result is memoized once true.- Since:
- 9.0.0
-
alwaysMaskEmail
Masks an email address by replacing '@' with 'at' and '.' with 'dot'.- Parameters:
emailAddress
- an email address to mask, eg dwillis@atlassian.com.rproxy.goskope.com- Returns:
- a masked version of the email, eg dwillis at atlassian dot com
-
escapeCDATA
-
unescapeCDATA
-
getI18n
- Returns:
- The
I18NBean
for the current user
-
replaceInvalidXmlCharacters
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
org.jdom.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
-
specialToLowerCase
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
-
specialToLowerCase
public static String specialToLowerCase(String str, com.atlassian.config.ApplicationConfiguration appConfig) - Since:
- 9.3
-
getGlobalSettings
-
splitCommaDelimitedString
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
-
convertBeanToMap
Deprecated, for removal: This API element is subject to removal in a future version.since 8.6 useBeanUtils.describe(Object)
- 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.
-
applyIfNonNull
-
unescapeEntities
-
executeRetryableTransaction
public static <T> T executeRetryableTransaction(com.atlassian.sal.api.rdbms.TransactionalExecutor executor, com.atlassian.sal.api.rdbms.ConnectionCallback<T> callback) Imperative alternative toRetryableTransaction
.- Since:
- 9.1
-
BeanUtils.describe(Object)