Package com.xpn.xwiki.util
Class Util
- java.lang.Object
-
- com.xpn.xwiki.util.Util
-
public class Util extends Object
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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 aapplication/x-www-form-urlencoded
string, the reverse ofencodeURI(String, XWikiContext)
.static String
encodeURI(String text, XWikiContext context)
Translates a string intoapplication/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)
Deprecated.dedicated to Radeox which is deprecated since a long timestatic String
escapeURL(String url)
Deprecated.dedicated to Radeox which is deprecated since a long timeList<String>
getAllMatches(String content, String spattern, int group)
static javax.servlet.http.Cookie
getCookie(String cookieName, XWikiContext context)
static javax.servlet.http.Cookie
getCookie(String cookieName, javax.servlet.http.HttpServletRequest request)
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 URL
getResource(String resource)
Load resources from: 1.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)
-
-
-
Method Detail
-
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
-
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)
-
isAlphaNumeric
public static boolean isAlphaNumeric(String text)
-
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)
-
escapeText
@Deprecated public static String escapeText(String text)
Deprecated.dedicated to Radeox which is deprecated since a long timeAPI 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 timeAPI to protect URLs from Radeox transformation- Parameters:
url
-- Returns:
- encoded URL
-
encodeURI
public static String encodeURI(String text, XWikiContext context)
Translates a string intoapplication/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 textcontext
- the current context- Returns:
- encoded text
- See Also:
decodeURI(String, XWikiContext)
-
decodeURI
public static String decodeURI(String text, XWikiContext context)
Decodes aapplication/x-www-form-urlencoded
string, the reverse ofencodeURI(String, XWikiContext)
. This uses the UTF-8 encoding, the default encoding for URIs, as stated in RFC 3986.- Parameters:
text
- the encoded textcontext
- 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
-
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 byLocalUidStringEntityReferenceSerializer
orUidStringEntityReferenceSerializer
- Returns:
- 64bit hash
- Since:
- 4.0M1
-
-