Class Util


  • public class Util
    extends Object
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • match

        public boolean match​(String pattern,
                             String text)
      • matched

        public boolean matched()
      • getMatcher

        public org.apache.oro.text.regex.Perl5Matcher getMatcher()
      • getP5util

        public org.apache.oro.text.perl.Perl5Util getP5util()
      • getAllMatches

        public List<String> getAllMatches​(String content,
                                          String spattern,
                                          int group)
                                   throws org.apache.oro.text.regex.MalformedPatternException
        Throws:
        org.apache.oro.text.regex.MalformedPatternException
      • getUniqueMatches

        public List<String> getUniqueMatches​(String content,
                                             String spattern,
                                             int group)
                                      throws org.apache.oro.text.regex.MalformedPatternException
        Throws:
        org.apache.oro.text.regex.MalformedPatternException
      • cleanValue

        public static String cleanValue​(String value)
      • restoreValue

        public static String restoreValue​(String value)
      • keyValueToHashtable

        public static Hashtable<String,​String> keyValueToHashtable​(String mapString)
                                                                  throws IOException
        Create a Map from a string holding a space separated list of key=value pairs. If keys or values must contain spaces, they can be placed inside quotes, like "this key"="a larger value". To use a quote as part of a key/value, use %_Q_%.
        Parameters:
        mapString - The string that must be parsed.
        Returns:
        A Map containing the keys and values. If a key is defined more than once, the last value is used.
        Throws:
        IOException
      • getPatterns

        public static org.apache.oro.text.PatternCache getPatterns()
      • noaccents

        public static String noaccents​(String text)
      • isAlphaNumeric

        public static boolean isAlphaNumeric​(String text)
      • getCookie

        public static javax.servlet.http.Cookie getCookie​(String cookieName,
                                                          XWikiContext context)
      • getCookie

        public static javax.servlet.http.Cookie getCookie​(String cookieName,
                                                          javax.servlet.http.HttpServletRequest request)
      • escapeText

        @Deprecated
        public static String escapeText​(String text)
        Deprecated.
        dedicated to Radeox which is deprecated since a long time
        API to protect Text from Radeox transformation
        Parameters:
        text -
        Returns:
        escaped text
      • escapeURL

        @Deprecated
        public static String escapeURL​(String url)
        Deprecated.
        dedicated to Radeox which is deprecated since a long time
        API to protect URLs from Radeox transformation
        Parameters:
        url -
        Returns:
        encoded URL
      • encodeURI

        public static String encodeURI​(String text,
                                       XWikiContext context)
        Translates a string into application/x-www-form-urlencoded format, so that it can be safely used in URIs, as a parameter value in a query string or as a segment in the URI path. This uses the UTF-8 encoding, the default encoding for URIs, as stated in RFC 3986.
        Parameters:
        text - the non encoded text
        context - the current context
        Returns:
        encoded text
        See Also:
        decodeURI(String, XWikiContext)
      • convertToAlphaNumeric

        public static String convertToAlphaNumeric​(String text)
        Removes all non alpha numerical characters from the passed text. First tries to convert accented chars to their alpha numeric representation.
        Parameters:
        text - the text to convert
        Returns:
        the alpha numeric equivalent
      • getFileLastModificationDate

        public static Date getFileLastModificationDate​(String path)
      • isValidXMLElementName

        public static boolean isValidXMLElementName​(String elementName)
        Validate a XML element name. XML elements must follow these naming rules :
        • Names can contain letters, numbers, and the following characters [., -, _].
        • Names must not start with a number or punctuation character.
        • Names must not start (case-insensitive) with the letters xml.
        • Names cannot contain spaces.
        Parameters:
        elementName - the XML element name to validate
        Returns:
        true if the element name is valid, false if it is not
      • getResourceAsStream

        public static InputStream getResourceAsStream​(String resource)
        Load resources from: 1. FileSystem 2. ServletContext 3. ClassPath in this order.
        Parameters:
        resource - resource path to load
        Returns:
        InputStream of resource or null if not found
      • getResource

        public static URL getResource​(String resource)
        Load resources from: 1. FileSystem 2. ServletContext 3. ClassPath in this order.
        Parameters:
        resource - resource path to load
        Returns:
        InputStream of resource or null if not found
        Since:
        11.5RC1
      • normalizeLanguage

        public static String normalizeLanguage​(String languageCode)
        Normalize the given language code. Converts the given language code to lower case and checks its validity (i.e. whether it is an ISO 639 language code or the string "default").
         Util.normalizeLanguage(null)      = null
         Util.normalizeLanguage("")        = ""
         Util.normalizeLanguage("  ")      = ""
         Util.normalizeLanguage("default") = "default"
         Util.normalizeLanguage("DeFault") = "default"
         Util.normalizeLanguage("invalid") = "default"
         Util.normalizeLanguage("en")      = "en"
         Util.normalizeLanguage("DE_at")   = "de_AT"
         
        Parameters:
        languageCode - the language code to normalize
        Returns:
        normalized language code or the string "default" if the code is invalid
      • getHash

        public static long getHash​(String uid)
        Get a likely unique 64bit hash representing the provided uid string. Use the MD5 hashing algorithm.
        Parameters:
        uid - an uid string usually provided by LocalUidStringEntityReferenceSerializer or UidStringEntityReferenceSerializer
        Returns:
        64bit hash
        Since:
        4.0M1