|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.confluence.util.GeneralUtil
public final class GeneralUtil
Constructor Summary | |
---|---|
GeneralUtil()
|
Method Summary | ||
---|---|---|
static String |
alwaysMaskEmail(String emailAddress)
Masks an email address by replacing '@' with 'at' and '.' with 'dot'. |
|
static String |
appendAmpsandOrQuestionMark(String str)
|
|
int |
arraySize(int[] array)
convenience method to allow us to determine the size of an int array a velocity file |
|
static String |
base64Decode(String s)
|
|
static String |
base64Encode(String s)
|
|
static String |
completeUrlEncode(String url)
A utility method to encode the given url for protocols which the CompleteURLEncoder supports. |
|
static String |
constrainLength(String s,
int length)
Truncate a string after n characters |
|
static Map<String,String> |
convertBeanToMap(Object bean)
|
|
static Date |
convertMailFormatDate(String date)
|
|
static Boolean |
convertToBoolean(Object obj)
|
|
static boolean |
convertToBoolean(Object bool,
boolean defaultValue)
|
|
static Character |
convertToCharacter(Object obj)
|
|
static Integer |
convertToInteger(Object obj)
|
|
static String |
convertToString(Object obj)
|
|
static 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#addcomment |
|
static String |
displayShortUrl(String url)
|
|
static String |
displayShortUrl(String url,
int length)
|
|
static String |
doubleUrlEncode(String s)
|
|
static String |
escapeCDATA(String s)
|
|
static List<String> |
escapeCommas(List<String> toEscape)
Escape commas on each entry in the given list of strings. |
|
static String |
escapeCommas(String toEscape)
Escapes commas and backslashes with leading backslashes. |
|
static String |
escapeForHtmlAttribute(String s)
Escapes " and \ with a leading \ so that strings can't break out of double-quoted HTML attributes. |
|
static String |
escapeForJavascript(String s)
Escapes ', " and \ with a leading \. |
|
static String[] |
escapeXml(Object[] args)
Produces an array of XML escaped String s from a list of Objects. |
|
static String |
escapeXml(String stringToEscape)
|
|
static String |
escapeXMLCharacters(String input)
Take a String which may contain <, > or & and return an XML string containing entities |
|
static
|
filterNulls(Collection<T> in)
Return a List with no null entries |
|
static String |
findAndMaskEmail(String text,
com.atlassian.user.User currentUser)
|
|
static String |
format(Number number)
TODO: Replace with a NumberFormatter, similar to DateFormatter |
|
static String |
format(Object obj)
|
|
static String |
format(String str)
|
|
static String |
formatDateFull(Date date)
|
|
static String |
formatLongTime(long time)
|
|
static Date |
getBuildDate()
|
|
static String |
getBuildDateString()
|
|
static String |
getBuildNumber()
|
|
static String |
getCharacterEncoding()
|
|
static String |
getCompactDuration(long time)
Returns the duration in a compact HH:mm:ss format. |
|
static File |
getConfluenceTempDirectory()
|
|
static String |
getConfluenceTempDirectoryPath()
Checks if temp directory exists before returning the path. |
|
static String |
getCookieValue(String key)
|
|
static ResourceBundle |
getDefaultResourceBundle()
|
|
static 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 String |
getNiceDuration(int minutes,
int seconds)
|
|
static String |
getPageUrl(AbstractPage page)
|
|
static String |
getPageUrl(VersionHistorySummary summary)
|
|
long |
getPercentage(long numerator,
long denom)
converts a fraction into a percentage |
|
long |
getPercentage(String numeratorAsString,
String denomAsString)
|
|
static
|
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 use FriendlyDateFormatter |
|
static String |
getStackTrace(Throwable t)
|
|
static Long |
getSystemStartupTime()
|
|
static String |
getUploadFileTooLargeMessage(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 String |
getVersionNumber()
|
|
static String |
hackSingleQuotes(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 String |
highlight(String content,
String searchwords)
|
|
static String |
htmlEncode(String text)
|
|
static String |
htmlEncodeAndReplaceSpaces(String text)
|
|
static String |
htmlEscapeQuotes(String input)
Take a string and escape the quotes in it with \" and HTML escape them afterwards. |
|
static boolean |
isAllAscii(String s)
|
|
static boolean |
isAllLettersOrNumbers(String s)
|
|
static boolean |
isDefaultUserProfilePicture(String username)
Deprecated. This method must not be used anymore, it is horribly inefficient. Rather use the ProfilePictureInfo: since it is never null, you can ask that object is the user has a default profile picture or not |
|
static boolean |
isInLastDays(Date date,
int maxDays)
|
|
static boolean |
isLicenseExpired()
|
|
static boolean |
isOutgoingMailConfigured()
Deprecated. since v5.0. Use MailServerManager.isDefaultSMTPMailServerDefined() instead. |
|
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 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 String |
lookupDomainName(HttpServletRequest request)
Get the default domain name. |
|
static String |
makeFlatSummary(String content)
Create a summary of this content fragment. |
|
static String |
makeFlatSummary(String content,
String query)
Create a summary of this content fragment given a query |
|
static com.atlassian.bonnie.search.summary.Summary |
makeSummary(String content)
Create a proper summary of this content fragment. |
|
static com.atlassian.bonnie.search.summary.Summary |
makeSummary(String content,
String query)
Create a proper summary of this content fragment given a query |
|
static String |
maskEmail(String emailAddress)
If configured, masks an email address to defeat the most simplistic spam bots. |
|
static ConfluenceActionSupport |
newWiredConfluenceActionSupport()
|
|
static String |
personalSpaceUrl(String contextPath,
String username)
Deprecated. since 5.0 You should instead retrieve the space using SpaceManager
and call getUrlPath on the Space object. |
|
static String |
plain2html(String text)
|
|
static String |
populateSimpleMessage(String template,
List<String> values)
Populate the template String supplied using the given values. |
|
static
|
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)
|
|
static void |
profilePush(String s)
|
|
static String |
rdfEncode(String s)
A fairly evil hack to work around CONF-10364. |
|
static String |
replaceConfluenceHomeConstant(String in,
String confHome)
|
|
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
|
safeSubList(List<T> list,
int max)
|
|
static Cookie |
setCookie(String key,
String value)
Sets a cookie. |
|
static void |
setSystemStartupTime(Long systemStartupTime)
|
|
static void |
setUserAccessor(UserAccessor userAcc)
|
|
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)
|
|
static Collection<String> |
specialLowerCaseCollection(Collection<String> collection)
Takes a collection of Strings and lowercases the entries. |
|
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)
|
|
long |
subtract(long a,
long b)
Deprecated. since 5.0. Just use a minus sign. |
|
long |
subtract(String firstOperandAsString,
String secondOperandAsString)
Deprecated. since 5.0. Just say no. |
|
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 a folder in temp and returns the File pointing to that expanded folder. |
|
static void |
unzipUrl(URL zipUrl,
File dirToExtractTo)
Unzips the zip url to a folder in temp and returns the File pointing to that expanded folder. |
|
static String |
urlDecode(String url)
|
|
static String |
urlEncode(String url)
A utility method to encode HTTP form parameter/values. |
|
static String |
urlEncode(String value,
String encoding)
|
|
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 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 |
---|
public GeneralUtil()
Method Detail |
---|
@Deprecated public static void loadDefaultProperties()
BuildInformation
public static String getStackTrace(Throwable t)
public static String format(Number number)
DateFormatter
number
- the number object to reformat
public static String format(String str)
public static String format(Object obj)
public static Date convertMailFormatDate(String date) throws ParseException
ParseException
public static Character convertToCharacter(Object obj)
public static Integer convertToInteger(Object obj)
public static Boolean convertToBoolean(Object obj)
public static boolean convertToBoolean(Object bool, boolean defaultValue)
public static String convertToString(Object obj)
public static String completeUrlEncode(String url)
url
- - the entire URL to encode
public static String urlEncode(String url)
url
- - part of the url to encode
public static String urlEncode(String value, String encoding)
public static String urlDecode(String url)
public static boolean shouldUrlDecode(String str)
public static String getPageUrl(VersionHistorySummary summary)
public static String getPageUrl(AbstractPage page)
public static String getIdBasedPageUrl(AbstractPage page)
page
- the page to generate a url for
public static boolean isSafeTitleForUrl(String title)
title
- The title to check
public static boolean isSafeTitleForFilesystem(String title)
title
- The title to check
public static String customGetPageUrl(AbstractPage page)
page
- The page to get the URL of
public static String appendAmpsandOrQuestionMark(String str)
public static String wordWrap(String str, int max)
str
- the string to wrapmax
- max length of string allowed per line
public static String highlight(String content, String searchwords)
public static String doubleUrlEncode(String s)
public static boolean isAllAscii(String s)
public static boolean isAllLettersOrNumbers(String s)
public static String getVersionNumber()
public static Date getBuildDate()
public static String getBuildDateString()
public static String getBuildNumber()
BuildInformation.getBuildNumber()
public static Long getSystemStartupTime()
public static void setSystemStartupTime(Long systemStartupTime)
public static boolean isLicenseExpired()
public static boolean hasTooManyUsers()
public static boolean stringSet(String str)
public static String formatLongTime(long time)
public static String displayShortUrl(String url)
public static String displayShortUrl(String url, int length)
public static String formatDateFull(Date date)
public static Date toEndOfMonth(Calendar postDate, boolean isSqlServer)
postDate
- A calendar object
public static void copyDate(Calendar original, Calendar copy)
original
- The source calendar objectcopy
- The destination calendar object@Deprecated public static boolean isSuperUser(com.atlassian.user.User user)
user
- the user to check for (the null user will always return false
PermissionManager.hasPermission(com.atlassian.user.User, com.atlassian.confluence.security.Permission, java.lang.Object)
public static String getCharacterEncoding()
public static String escapeXml(String stringToEscape)
public static String[] escapeXml(Object[] args)
String
s from a list of Objects. String.valueOf(Object)
is used
to produce String
s from the Object
s
args
- an array of objects
String
spublic static String escapeForJavascript(String s)
s
- the string to escape
public static String escapeForHtmlAttribute(String s)
s
- the string to escape
public static boolean isSetupComplete()
public static String maskEmail(String emailAddress)
emailAddress
- the email address to mask
public static String alwaysMaskEmail(String emailAddress)
emailAddress
- an email address to mask, eg [email protected]
public static String findAndMaskEmail(String text, com.atlassian.user.User currentUser)
public static String escapeCDATA(String s)
public static String unescapeCDATA(String s)
public static File createTempDirectoryInConfluenceTemp(String prefix)
public static File createTempFile(String directory)
public static String unescapeEntities(String str)
public static String base64Decode(String s)
public static String base64Encode(String s)
public static String hackSingleQuotes(String s)
s
- the input string
public static boolean isInLastDays(Date date, int maxDays)
date
- the date to checkmaxDays
- the number of days into the past the date can fall
public static String getRelativeTime(Date date)
FriendlyDateFormatter
date
- the date to convert to a relative time string
public static String getFormatDateSimple(Date date)
public static Cookie setCookie(String key, String value)
key
- the key of the cookievalue
- the value of the cookie
public static String getCookieValue(String key)
public static String htmlEncode(String text)
public static String htmlEncodeAndReplaceSpaces(String text)
public static String plain2html(String text)
text
- the text to encode
PlainTextToHtmlConverter
public static void unzipFile(File zipFile, File dirToExtractTo) throws IOException
zipFile
- the zip file to extractdirToExtractTo
- the directory to extract the zip file to
IOException
- if an IOException occurspublic static void unzipUrl(URL zipUrl, File dirToExtractTo) throws IOException
zipUrl
- the URL of the zip file to extractdirToExtractTo
- the directory to extract the zip file to
IOException
- if an IOException occurspublic static String getUploadFileTooLargeMessage(String errorMessage)
errorMessage
- the error message to convert
public static ResourceBundle getDefaultResourceBundle()
public static I18NBean getI18n()
I18NBean
for the current userpublic int arraySize(int[] array)
array
- the array to find the length of
public static String escapeXMLCharacters(String input)
input
- a string to escape for XML
public static String replaceInvalidXmlCharacters(String text)
Verifier.checkCharacterData(String)
but converts illegals instead of throwing Exceptions.
text
- the input string
public static String htmlEscapeQuotes(String input)
null
input will be returned as an empty String.
input
- string to escape
public static <T> List<T> filterNulls(Collection<T> in)
in
- a collection to filter nulls
public static String shortenString(String str, int max)
ELLIPSIS
to the end of the
string if it does truncate it.
str
- the string to shortenmax
- the maximum desired length of the result (excluding ELLIPSIS
)
StringUtils.abbreviate(String, int)
public static String specialToLowerCase(String str)
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.
str
- the string to convert to lower case
public static String replaceConfluenceHomeConstant(String in, String confHome)
public static Collection<String> specialLowerCaseCollection(Collection<String> collection)
collection
- the collection
public static <T> List<T> safeSubList(List<T> list, int max)
public static String summarise(String content)
content
- the content to summarise
public static com.atlassian.bonnie.search.summary.Summary makeSummary(String content)
content
- the string to summarise
Summarizer
public static com.atlassian.bonnie.search.summary.Summary makeSummary(String content, @Nullable String query)
content
- the string to summarisequery
- the lucene query
Summarizer
public static String makeFlatSummary(String content)
content
- the content to summarise
Summarizer
public static String makeFlatSummary(String content, @Nullable String query)
content
- the content stringquery
- the lucene query string
Summarizer
public static UserAccessor getUserAccessor()
public static void setUserAccessor(UserAccessor userAcc)
public static com.atlassian.core.util.ImageInfo getImageInfo(File pathToImage)
public static String getNiceDuration(int minutes, int seconds)
public static String getCompactDuration(long time)
time
- duration in milliseconds
public static ConfluenceActionSupport newWiredConfluenceActionSupport()
public static void profilePush(String s)
public static void profilePop(String s)
public static String lookupDomainName(HttpServletRequest request)
request
- the request
public static Settings getGlobalSettings()
public static String personalSpaceUrl(String contextPath, String username)
SpaceManager
and call getUrlPath on the Space object.
public long getPercentage(long numerator, long denom)
numerator
- the number to include in the percentagedenom
- the total number
@Deprecated public long subtract(long a, long b)
public long getPercentage(String numeratorAsString, String denomAsString)
@Deprecated public long subtract(String firstOperandAsString, String secondOperandAsString)
public static String getConfluenceTempDirectoryPath()
public static File getConfluenceTempDirectory()
public static String[] splitCommaDelimitedString(String escapedNames)
escapedNames
- Comma delimited string with original commas and backslashes escaped by backslashes
public static List<String> escapeCommas(List<String> toEscape)
toEscape
- String
s to escape
String
spublic static String escapeCommas(String toEscape)
toEscape
- string to escape. If null, then null will be returned.
public static String constrainLength(String s, int length)
s
- The String to truncatelength
- The maximum length allowed.
@Deprecated public static boolean isOutgoingMailConfigured()
MailServerManager.isDefaultSMTPMailServerDefined()
instead.
public static Map<String,String> convertBeanToMap(Object bean)
bean
- a bean to be converted to a Map.
public static <K,V> Map<K,V> prefixAllMapKeys(String prefix, Map<K,V> map)
If any of the keys in the Map are not Strings then they will be ignored.
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.
@Deprecated public static boolean isDefaultUserProfilePicture(String username)
username
- the username to check
public static String rdfEncode(String s)
s
- to encode
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.
template
- the template to be populatedvalues
- the values used to populate the template
public static <T> List<T> getRandomSubSet(List<T> list, int sizeOfSubset, Random random)
list
- - the list to subsetsizeOfSubset
- - the size of the subset to returnrandom
- - the source of randomness
public static String trimDownStringToWord(String s)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |