Class GeneralUtil

java.lang.Object
com.atlassian.confluence.util.VelocityUtil
com.atlassian.confluence.util.GeneralUtil

public final class GeneralUtil extends VelocityUtil
Extension of VelocityUtil that contain methods that are not needed or safe for use in Velocity templates.
  • Field Details

  • Constructor Details

    • GeneralUtil

      public GeneralUtil()
  • Method Details

    • setSystemStartupTime

      public static void setSystemStartupTime(Long systemStartupTime)
    • getSystemStartupTime

      public static Long getSystemStartupTime()
    • createTempDirectoryInConfluenceTemp

      public static File createTempDirectoryInConfluenceTemp(String prefix)
    • getRequestPath

      public static String getRequestPath(javax.servlet.http.HttpServletRequest request)
      As opposed to getOriginalPath(javax.servlet.http.HttpServletRequest), the returned path will be decoded.
    • getRequestUrl

      public static String getRequestUrl(javax.servlet.http.HttpServletRequest request)
    • getOriginalPath

      public static String getOriginalPath(javax.servlet.http.HttpServletRequest request)
      Get the original request path, i.e. the path that was requested by the user.
    • getOriginalUrl

      public static String getOriginalUrl(javax.servlet.http.HttpServletRequest request)
    • 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
    • isAllAsciiLettersOrNumbers

      @Deprecated(since="9.3") public static boolean isAllAsciiLettersOrNumbers(String s)
      Deprecated.
      since 9.3 unused
    • displayShortUrl

      public static String displayShortUrl(String url)
    • displayShortUrl

      public static String displayShortUrl(String url, int length)
    • 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.6
      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 object
      copy - The destination calendar object
    • getDefaultCharset

      public static Charset getDefaultCharset()
    • escapeForJavascript

      public static String escapeForJavascript(String s)
      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

      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
    • escapeCDATA

      public static String escapeCDATA(String s)
    • unescapeCDATA

      public static String unescapeCDATA(String s)
    • getI18n

      public static I18NBean getI18n()
      Returns:
      The I18NBean for the current user
    • 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 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

      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
    • specialToLowerCase

      public static String specialToLowerCase(String str, com.atlassian.config.ApplicationConfiguration appConfig)
      Since:
      9.3
    • getGlobalSettings

      public static Settings getGlobalSettings()
    • 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
    • convertBeanToMap

      @Deprecated(forRemoval=true) public static Map<String,String> convertBeanToMap(Object bean)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 8.6 use BeanUtils.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

      public static <T, S> S applyIfNonNull(T delegate, Function<T,S> wrapper)
    • unescapeEntities

      public static String unescapeEntities(String str)
    • executeRetryableTransaction

      public static <T> T executeRetryableTransaction(com.atlassian.sal.api.rdbms.TransactionalExecutor executor, com.atlassian.sal.api.rdbms.ConnectionCallback<T> callback)
      Imperative alternative to RetryableTransaction.
      Since:
      9.1