com.xpn.xwiki.api
Class Util

java.lang.Object
  extended by com.xpn.xwiki.api.Api
      extended by com.xpn.xwiki.api.Util

public class Util
extends Api

Utility APIs, available to scripting environments under the util variable.

Version:
$Id: 3c641d217cffb3a0935153fd8ae9b934217bea87 $

Field Summary
 
Fields inherited from class com.xpn.xwiki.api.Api
context
 
Constructor Summary
Util(XWiki xwiki, XWikiContext context)
          Simple constructor, initializes a new utility API with the current context and the current global XWiki object.
 
Method Summary
 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 a application/x-www-form-urlencoded string, the reverse of #encodeURI(String).
 String generateRandomString(int size)
          Generate a random string, containing only alpha-numeric characters.
 Date getDate()
          Creates a new Date object corresponding to the current time.
 Date getDate(long time)
          Creates a new Date object corresponding to the specified time.
 String 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 a String to a Boolean 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, getXWikiContext, hasAccessLevel, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util(XWiki xwiki,
            XWikiContext context)
Simple constructor, initializes a new utility API with the current context and the current global XWiki object.

Parameters:
xwiki - the current global XWiki object
context - the current context
See Also:
Api.Api(com.xpn.xwiki.XWikiContext)
Method Detail

decodeURI

public String decodeURI(String text)
Decodes a application/x-www-form-urlencoded string, the reverse of #encodeURI(String).

Parameters:
text - the encoded text
Returns:
decoded text
Since:
1.3 Milestone 2
See Also:
#encodeURI(String)

getDate

public Date getDate()
Creates a new Date 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

public Date getDate(long time)
Creates a new Date 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 $context.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 real null 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 a String to a Boolean 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


Copyright © 2004–2014 XWiki. All rights reserved.