|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.xpn.xwiki.api.Api
com.xpn.xwiki.api.Util
public class Util
Utility APIs, available to scripting environments under the util
variable.
Field Summary |
---|
Fields inherited from class com.xpn.xwiki.api.Api |
---|
context |
Constructor Summary | |
---|---|
Util(com.xpn.xwiki.XWiki xwiki,
com.xpn.xwiki.XWikiContext context)
Simple constructor, initializes a new utility API with the current context and
the current global XWiki object. |
Method Summary | ||
---|---|---|
int |
add(int a,
int b)
Add two integer numbers. |
|
long |
add(long a,
long b)
Add two long numbers. |
|
String |
add(String a,
String b)
Add two numbers, specified as strings. |
|
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 |
encodeURI(String text)
Translates a string into application/x-www-form-urlencoded format, so that it can be safely used in
a query string as a parameter value. |
|
String |
escapeSQL(String text)
Escape text so that it can be used in a HQL/SQL query, in a like clause or in a test for equality clause. |
|
String |
escapeText(String text)
Protect Text from Wiki transformation. |
|
String |
escapeURL(String url)
Protect URLs from Wiki transformation. |
|
String |
generateRandomString(int size)
Generate a random string, containing only alpha-numeric characters. |
|
|
getArrayList()
Creates an ArrayList . |
|
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. |
|
|
getHashMap()
Creates a HashMap , a generic map implementation optimized for performance. |
|
|
getLinkedHashMap()
Creates a LinkedHashMap , a map implementation which preserves the order of insertion. |
|
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. |
|
|
getTreeMap()
Creates a TreeMap , a map implementation which always maintains the natural order of the elements. |
|
void |
outputImage(BufferedImage image)
Output a BufferedImage object into the response outputstream. |
|
Boolean |
parseBoolean(String str)
Convert a String to a Boolean object. |
|
double |
parseDouble(String str)
Convert a String to a primitive double . |
|
float |
parseFloat(String str)
Convert a String to a primitive float . |
|
int |
parseInt(String str)
Convert a String to a primitive int . |
|
Integer |
parseInteger(String str)
Convert a String to an Integer object. |
|
long |
parseLong(String str)
Convert a String to a primitive long . |
|
String |
printStrackTrace(Throwable e)
Get a stack trace as a String. |
|
|
reverseList(List<T> list)
Reverse the order of the elements within a list, so that the last element is moved to the beginning of the list, the next-to-last element to the second position, and so on. |
|
|
sort(List<T> list)
Sort a list using a standard comparator. |
|
String[] |
split(String text,
String separator)
Split a text into an array of texts, according to a list of separator characters. |
|
Number |
toNumber(Object object)
Convert an Object to a number and return null if the object is not a Number. |
Methods inherited from class com.xpn.xwiki.api.Api |
---|
convert, convert, 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 |
---|
public Util(com.xpn.xwiki.XWiki xwiki, com.xpn.xwiki.XWikiContext context)
context
and
the current global XWiki
object.
xwiki
- the current global XWiki objectcontext
- the current contextApi.Api(com.xpn.xwiki.XWikiContext)
Method Detail |
---|
public String escapeText(String text)
text
- the text to escape
public String escapeURL(String url)
url
- the url to escape
public String encodeURI(String text)
application/x-www-form-urlencoded
format, so that it can be safely used in
a query string as a parameter value.
text
- the non encoded text
decodeURI(String)
public String decodeURI(String text)
application/x-www-form-urlencoded
string, the reverse of encodeURI(String)
.
text
- the encoded text
encodeURI(String)
public <T> List<T> getArrayList()
ArrayList
. This is useful from Velocity since new objects cannot be created.
ArrayList
objectpublic <T,U> Map<T,U> getHashMap()
HashMap
, a generic map implementation optimized for performance. This is useful from Velocity
since new objects cannot be created.
HashMap
objectpublic <T,U> Map<T,U> getTreeMap()
TreeMap
, a map implementation which always maintains the natural order of the elements. This is
useful from Velocity since new objects cannot be created.
TreeMap
objectpublic <T,U> Map<T,U> getLinkedHashMap()
LinkedHashMap
, a map implementation which preserves the order of insertion. This is useful from
Velocity since new objects cannot be created.
LinkedHashMap
objectpublic Date getDate()
Date
object corresponding to the current time. This is useful from Velocity since new
objects cannot be created.
public Date getDate(long time)
Date
object corresponding to the specified time. This is useful from Velocity since new
objects cannot be created.
time
- time in milliseconds since 1970, 00:00:00 GMT
Date
Objectpublic int getTimeDelta(long time)
time
- the time in milliseconds
public String[] split(String text, String separator)
text
- the original textseparator
- the separator characters
public <T> List<T> reverseList(List<T> list)
list
- the list to reverse
public String printStrackTrace(Throwable e)
e
- the exception to convert to a String
public <T extends Comparable<T>> List<T> sort(List<T> list)
list
- the list to sort
java.util.Collections#sort(java.util.List)}
public String generateRandomString(int size)
size
- the desired size of the string
public void outputImage(BufferedImage image) throws IOException
$context.setFinished(true)
to avoid template output. The image is served as
image/jpeg.
image
- the BufferedImage to output
IOException
- if the output failspublic Object getNull()
null
object for comparisons.
null
Objectpublic String getNewline()
public Number toNumber(Object object)
null
if the object is not a Number.
object
- the object to convert
Number
, or null
public Boolean parseBoolean(String str)
String
to a Boolean
object.
str
- the String containing the boolean representation to be parsed
false
if the string is not representing a booleanpublic int parseInt(String str)
String
to a primitive int
.
str
- the String to convert to an integer
public Integer parseInteger(String str)
String
to an Integer
object.
str
- the String to convert to an Integer Object
public long parseLong(String str)
String
to a primitive long
.
str
- the String to convert to a long
public float parseFloat(String str)
String
to a primitive float
.
str
- the String to convert to a float
public double parseDouble(String str)
String
to a primitive double
.
str
- the String to convert to a double
public String escapeSQL(String text)
text
- the text to escape
public String clearAccents(String text)
text
- the text to parse
public int add(int a, int b)
a
- the first number to addb
- the second number to add
public long add(long a, long b)
a
- the first number to addb
- the second number to add
public String add(String a, String b)
a
- a string representing a number to addb
- a string representing a number to add
public String clearName(String documentName)
documentName
- the document name to normalize
public String convertToAlphaNumeric(String text)
text
- the text to convert
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |