Class VelocityUtil

java.lang.Object
com.atlassian.confluence.util.VelocityUtil
Direct Known Subclasses:
GeneralUtil

public class VelocityUtil extends Object
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 Details

  • Constructor Details

    • VelocityUtil

      protected VelocityUtil()
  • Method Details

    • customGetPageUrl

      public 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
      Parameters:
      page - The page to get the URL of
      Returns:
      The URL of the page with a trailing ? or &
    • appendAmpersandOrQuestionMark

      @Deprecated(forRemoval=true) public static String appendAmpersandOrQuestionMark(String str)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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 public static String doubleUrlEncode(String url)
      Deprecated.
      since 6.10.0, No replacement
    • isAllAscii

      public static boolean isAllAscii(String s)
    • isAscii

      protected static boolean isAscii(char c)
    • getVersionNumber

      public static String getVersionNumber()
    • getBuildNumber

      public static String getBuildNumber()
      Returns:
      The build number of the currently running Confluence instance.
      See Also:
    • isLicenseExpired

      @Deprecated public static boolean isLicenseExpired()
      Deprecated.
      since 8.7 Use LicenseService.retrieve() and ProductLicense.isExpired()
    • getCharacterEncoding

      public static String getCharacterEncoding()
    • escapeXml

      public static String escapeXml(String stringToEscape)
    • escapeXml

      public static String[] escapeXml(Object[] args)
      Produces an array of XML escaped Strings from a list of Objects. String.valueOf(Object) is used to produce Strings from the Objects
      Parameters:
      args - an array of objects
      Returns:
      an array of XML escaped Strings
    • maskEmail

      public static String maskEmail(String emailAddress, Settings globalSettings)
      Since:
      7.3.0
    • findAndMaskEmail

      public static String findAndMaskEmail(String text, com.atlassian.user.User currentUser)
    • base64Decode

      public static String base64Decode(String s)
    • base64Encode

      public static String base64Encode(String s)
    • isInLastDays

      public static boolean isInLastDays(Date date, int maxDays)
      Parameters:
      date - the date to check
      maxDays - the number of days into the past the date can fall
      Returns:
      whether the date falls within maxDays before the present.
    • getFormatDateSimple

      public static String getFormatDateSimple(Date date)
    • plain2html

      public static String plain2html(String text)
      Parameters:
      text - the text to encode
      Returns:
      the html encoded text
      See Also:
    • htmlEscapeQuotes

      @Deprecated public static String htmlEscapeQuotes(String input)
      Deprecated.
      since 7.3.0, use StringEscapeUtils.escapeEcmaScript(String) combined with HtmlUtil.htmlEncode(String) or template-level automatic escaping
      Take 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 functions

      null input will be returned as an empty String.

      Parameters:
      input - string to escape
      Returns:
      the escaped string
    • shortenString

      public static String shortenString(String str, int max)
      Returns a substring of the specified string if it is longer than max. This method also appends ELLIPSIS to the end of the string if it does truncate it.
      Parameters:
      str - the string to shorten
      max - the maximum desired length of the result (excluding ELLIPSIS)
      Returns:
      a substring of the specified string if it is longer than max.
      See Also:
      • StringUtils.abbreviate(String, int)
    • replaceConfluenceConstants

      public static String replaceConfluenceConstants(String in, File home, File localHome)
      Parameters:
      in - text to make the replacements to
      home - Confluence home directory
      localHome - Confluence local home directory
      Returns:
      text with replacements
      Since:
      5.5
    • safeSubList

      public static <T> List<T> safeSubList(List<T> list, int max)
    • summarise

      public static String summarise(String content)
      Parameters:
      content - the content to summarise
      Returns:
      the summarised content
    • makeSummary

      public static Summary makeSummary(String content, @Nullable String query)
      Create a proper summary of this content fragment given a query
      Parameters:
      content - the string to summarise
      query - the lucene query
      Returns:
      the summary object for the content and query
      See Also:
    • makeFlatSummary

      public static String makeFlatSummary(String content, @Nullable String query)
      Create a summary of this content fragment given a query
      Parameters:
      content - the content string
      query - the lucene query string
      Returns:
      the summarised content and query
      See Also:
    • lookupDomainName

      public static String lookupDomainName(javax.servlet.http.HttpServletRequest request)
      Get the default domain name.
      Parameters:
      request - the request
      Returns:
      null if request is null, otherwise a base URL derived from the request.
    • trimDownStringToWord

      public static String trimDownStringToWord(String s)
    • isDateWithin24Hours

      public static boolean isDateWithin24Hours(Date date)
      Determines if given date is within 24 hours
    • getServerRenderTime

      public static Duration getServerRenderTime(javax.servlet.ServletRequest servletRequest)
      Calculates the duration of the request
      Since:
      5.9.0
    • getRequestCorrelationId

      public static String 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

      public static void elapse(String tag)
      Add elapsed time to HttpRequestStats
      Since:
      5.9.1
      See Also:
    • sortList

      public static List<String> sortList(List<String> list)
      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 public static void profilePush(String s)
      Deprecated.
      since 7.0. Use Timers.start(String).
      Parameters:
      s - the profiling frame name to push
    • profilePop

      @Deprecated public static void profilePop(String s)
      Deprecated.
      since 7.0. Use Timers.start(String) and a try-finally block.
      Parameters:
      s - the profiling frame name to pop
    • getLinkLoginUrl

      public static String getLinkLoginUrl(javax.servlet.http.HttpServletRequest request)
      This method deliberately duplicates the method in SeraphUtils for the purpose of exposing it on the Velocity context via VelocityUtil. The SeraphUtils class is not safe for direct exposure on the Velocity context.
    • getLinkLoginPath

      public static String getLinkLoginPath(javax.servlet.http.HttpServletRequest request)
      This method deliberately duplicates the method in SeraphUtils for the purpose of exposing it on the Velocity context via VelocityUtil. The SeraphUtils class is not safe for direct exposure on the Velocity context.
    • intArrayToList

      public static List<Integer> intArrayToList(int[] array)
      Velocity <=1.6 cannot invoke methods against an array.