Package com.xpn.xwiki.api
Class Util
- java.lang.Object
-
- com.xpn.xwiki.api.Api
-
- com.xpn.xwiki.api.Util
-
public class Util extends Api
Utility APIs, available to scripting environments under theutil
variable.- Version:
- $Id: a581bc36e2fa571ef7793f8d2b730a8217edb2c9 $
-
-
Constructor Summary
Constructors Constructor Description Util(XWiki xwiki, XWikiContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
clearAccents(String text)
Replace all accented characters by their ASCII equivalent.String
clearName(String documentName)
Cleans up the passed text by removing all accents and special characters to make it a valid page name.String
convertToAlphaNumeric(String text)
Removes all non alpha numerical characters from the passed text.String
decodeURI(String text)
Decodes aapplication/x-www-form-urlencoded
string.String
generateRandomString(int size)
Generate a random string, containing only alpha-numeric characters.Date
getDate()
Deprecated.use$datetool.date
insteadDate
getDate(long time)
Deprecated.use$datetool.toDate(time)
insteadString
getNewline()
Get a New Line character.Object
getNull()
Get a Null value.int
getTimeDelta(long time)
Compute the elapsed time, in milliseconds, since the specified unix-epoch timestamp.void
outputImage(BufferedImage image)
Output a BufferedImage object into the response outputstream.Boolean
parseBoolean(String str)
Convert aString
to aBoolean
object.String
printStrackTrace(Throwable e)
Get a stack trace as a String.-
Methods inherited from class com.xpn.xwiki.api.Api
convert, convert, convert, convertAttachments, getAuthorizationManager, getContextualAuthorizationManager, getXWikiContext, hasAccess, hasAccessLevel, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
-
-
-
-
Constructor Detail
-
Util
public Util(XWiki xwiki, XWikiContext context)
Simple constructor, initializes a new utility API with the currentcontext
and the current globalXWiki
object.- Parameters:
xwiki
- the current global XWiki objectcontext
- the current context- See Also:
Api(com.xpn.xwiki.XWikiContext)
-
-
Method Detail
-
decodeURI
public String decodeURI(String text)
Decodes aapplication/x-www-form-urlencoded
string.- Parameters:
text
- the encoded text- Returns:
- decoded text
- Since:
- 1.3 Milestone 2
-
getDate
@Deprecated public Date getDate()
Deprecated.use$datetool.date
insteadCreates a newDate
object corresponding to the current time. This is useful from Velocity since new objects cannot be created.- Returns:
- the current date
- Since:
- 1.3 Milestone 2
-
getDate
@Deprecated public Date getDate(long time)
Deprecated.use$datetool.toDate(time)
insteadCreates a newDate
object corresponding to the specified time. This is useful from Velocity since new objects cannot be created.- Parameters:
time
- time in milliseconds since 1970, 00:00:00 GMT- Returns:
- Date a date from a time in milliseconds since 01/01/1970 as a Java
Date
Object - Since:
- 1.3 Milestone 2
-
getTimeDelta
public int getTimeDelta(long time)
Compute the elapsed time, in milliseconds, since the specified unix-epoch timestamp. This is useful from Velocity since new objects cannot be created.- Parameters:
time
- the time in milliseconds- Returns:
- the time delta in milliseconds between the current date and the time passed as parameter
- Since:
- 1.3 Milestone 2
-
printStrackTrace
public String printStrackTrace(Throwable e)
Get a stack trace as a String.- Parameters:
e
- the exception to convert to a String- Returns:
- the exception stack trace as a String
- Since:
- 1.3 Milestone 2
-
generateRandomString
public String generateRandomString(int size)
Generate a random string, containing only alpha-numeric characters.- Parameters:
size
- the desired size of the string- Returns:
- the randomly generated string
- Since:
- 1.3 Milestone 2
-
outputImage
public void outputImage(BufferedImage image) throws IOException
Output a BufferedImage object into the response outputstream. Once this method has been called, no further action is possible. Users should set$xcontext.setFinished(true)
to avoid template output. The image is served as image/jpeg.- Parameters:
image
- the BufferedImage to output- Throws:
IOException
- if the output fails- Since:
- 1.3 Milestone 2
-
getNull
public Object getNull()
Get a Null value. This is useful in Velocity where there is no realnull
object for comparisons.- Returns:
- a
null
Object - Since:
- 1.3 Milestone 2
-
getNewline
public String getNewline()
Get a New Line character. This is useful in Velocity where there is no real new line character for inclusion in texts.- Returns:
- a new line character
- Since:
- 1.3 Milestone 2
-
parseBoolean
public Boolean parseBoolean(String str)
Convert aString
to aBoolean
object.- Parameters:
str
- the String containing the boolean representation to be parsed- Returns:
- the boolean represented by the string argument,
false
if the string is not representing a boolean - Since:
- 1.8 Milestone 2
-
clearAccents
public String clearAccents(String text)
Replace all accented characters by their ASCII equivalent.- Parameters:
text
- the text to parse- Returns:
- a string with accents replaced with their alpha equivalent
- Since:
- 1.3 Milestone 2
-
clearName
public String clearName(String documentName)
Cleans up the passed text by removing all accents and special characters to make it a valid page name.- Parameters:
documentName
- the document name to normalize- Returns:
- the equivalent valid document name
- Since:
- 1.3 Milestone 2
-
convertToAlphaNumeric
public String convertToAlphaNumeric(String text)
Removes all non alpha numerical characters from the passed text. First tries to convert accented chars to their ASCII representation. Then it removes all the remaining non-alphanumeric non-ASCII characters.- Parameters:
text
- the text to convert- Returns:
- the alpha numeric equivalent
- Since:
- 1.3 Milestone 2
-
-