com.xpn.xwiki.util
Class Util

java.lang.Object
  extended by com.xpn.xwiki.util.Util

public class Util
extends Object


Constructor Summary
Util()
           
 
Method Summary
static String cleanValue(String value)
           
static boolean contains(String name, String list, String sep)
           
static String convertToAlphaNumeric(String text)
          Removes all non alpha numerical characters from the passed text.
static String decodeURI(String text, XWikiContext context)
          Decodes a application/x-www-form-urlencoded string, the reverse of encodeURI(String, XWikiContext).
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.
static String escapeText(String text)
          API to protect Text from Radeox transformation
static String escapeURL(String url)
          API to protect URLs from Radeox transformation
 List<String> getAllMatches(String content, String spattern, int group)
           
static javax.servlet.http.Cookie getCookie(String cookieName, javax.servlet.http.HttpServletRequest request)
           
static javax.servlet.http.Cookie getCookie(String cookieName, XWikiContext context)
           
 Document getDOMDocument()
          API to get a new DOM document
 Document getDOMForString(String str)
          API to obtain a DOM document for the specified string
static Date getFileLastModificationDate(String path)
           
static long getHash(String uid)
          Get a likely unique 64bit hash representing the provided uid string.
static String getHTMLExceptionMessage(XWikiException xe, XWikiContext context)
           
 org.apache.oro.text.regex.Perl5Matcher getMatcher()
           
static MonitorPlugin getMonitorPlugin(XWikiContext context)
           
static String getName(String name)
           
static String getName(String name, XWikiContext context)
           
static Map<String,String[]> getObject(XWikiRequest request, String prefix)
           
 org.apache.oro.text.perl.Perl5Util getP5util()
           
static org.apache.oro.text.PatternCache getPatterns()
           
static InputStream getResourceAsStream(String resource)
          Load resources from: 1.
static
<T> Map<String,T>
getSubMap(Map<String,T> map, String prefix)
           
 List<String> getUniqueMatches(String content, String spattern, int group)
           
static String getWeb(String fullname)
           
static boolean isAlphaNumeric(String text)
           
static boolean isValidXMLElementName(String elementName)
          Validate a XML element name.
static Hashtable<String,String> keyValueToHashtable(String mapString)
          Create a Map from a string holding a space separated list of key=value pairs.
 boolean match(String pattern, String text)
           
 boolean matched()
           
static String noaccents(String text)
           
static String normalizeLanguage(String languageCode)
          Normalize the given language code.
static String restoreValue(String value)
           
 Vector<String> split(String pattern, String text)
           
 String substitute(String pattern, String text)
           
 String substitute(String pattern, String substitution, String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

substitute

public String substitute(String pattern,
                         String text)

match

public boolean match(String pattern,
                     String text)

matched

public boolean matched()

substitute

public String substitute(String pattern,
                         String substitution,
                         String text)

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()

getObject

public static Map<String,String[]> getObject(XWikiRequest request,
                                             String prefix)

getSubMap

public static <T> Map<String,T> getSubMap(Map<String,T> map,
                                          String prefix)

getWeb

public static String getWeb(String fullname)

split

public Vector<String> split(String pattern,
                            String text)

contains

public static boolean contains(String name,
                               String list,
                               String sep)

noaccents

public static String noaccents(String text)

isAlphaNumeric

public static boolean isAlphaNumeric(String text)

getName

public static String getName(String name)

getName

public static String getName(String name,
                             XWikiContext context)

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)

getHTMLExceptionMessage

public static String getHTMLExceptionMessage(XWikiException xe,
                                             XWikiContext context)

getMonitorPlugin

public static MonitorPlugin getMonitorPlugin(XWikiContext context)

getDOMForString

public Document getDOMForString(String str)
API to obtain a DOM document for the specified string

Parameters:
str - The parsed text
Returns:
A DOM document element corresponding to the string, or null on error

getDOMDocument

public Document getDOMDocument()
API to get a new DOM document

Returns:
a new DOM document element, or null on error

escapeText

public static String escapeText(String text)
API to protect Text from Radeox transformation

Parameters:
text -
Returns:
escaped text

escapeURL

public static String escapeURL(String url)
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)

decodeURI

public static String decodeURI(String text,
                               XWikiContext context)
Decodes a application/x-www-form-urlencoded string, the reverse of encodeURI(String, XWikiContext). This uses the UTF-8 encoding, the default encoding for URIs, as stated in RFC 3986.

Parameters:
text - the encoded text
context - the current context
Returns:
decoded text
See Also:
encodeURI(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 :

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

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 internal.reference.LocalUidStringEntityReferenceSerializer or internal.reference.UidStringEntityReferenceSerializer
Returns:
64bit hash
Since:
4.0M1


Copyright © 2004–2014 XWiki. All rights reserved.