Author: vmassol
Date: 2008-02-01 15:10:21 +0100 (Fri, 01 Feb 2008)
New Revision: 7262
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Util.java
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
Log:
XWIKI-2055: Move utility APIs from the api.XWiki class to a new api.Util class
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Util.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Util.java
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Util.java
2008-02-01 14:10:21 UTC (rev 7262)
@@ -0,0 +1,418 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package com.xpn.xwiki.api;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.web.Utils;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+import com.sun.image.codec.jpeg.JPEGCodec;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.TreeMap;
+import java.util.Collections;
+import java.util.Date;
+import java.lang.*;
+import java.lang.Object;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Utility APIs, available from Velocity/Groovy scripting.
+ *
+ * @version $Id: $
+ */
+public class Util extends Api
+{
+ private com.xpn.xwiki.XWiki xwiki;
+
+ /**
+ * [EMAIL PROTECTED]
+ * @see Api#Api(com.xpn.xwiki.XWikiContext)
+ */
+ public Util(com.xpn.xwiki.XWiki xwiki, XWikiContext context)
+ {
+ super(context);
+ this.xwiki = xwiki;
+ }
+
+ /**
+ * Protect Text from Wiki transformation.
+ *
+ * @param text the text to escape
+ * @return the escaped text
+ * @since 1.3 Milestone 2
+ */
+ public String escapeText(String text)
+ {
+ return com.xpn.xwiki.util.Util.escapeText(text);
+ }
+
+ /**
+ * Protect URLs from Wiki transformation.
+ *
+ * @param url the url to escape
+ * @return the encoded URL
+ * @since 1.3 Milestone 2
+ */
+ public String escapeURL(String url)
+ {
+ return com.xpn.xwiki.util.Util.escapeURL(url);
+ }
+
+ /**
+ * Creates an Array List. This is useful from Velocity since you cannot
+ * create Object from Velocity with our secure uberspector.
+ *
+ * @return a [EMAIL PROTECTED] ArrayList} object
+ * @since 1.3 Milestone 2
+ */
+ public List getArrayList()
+ {
+ return new ArrayList();
+ }
+
+ /**
+ * Creates a Hash Map. This is useful from Velocity since you cannot
+ * create Object from Velocity with our secure uberspector.
+ *
+ * @return a [EMAIL PROTECTED] HashMap} object
+ * @since 1.3 Milestone 2
+ */
+ public Map getHashMap()
+ {
+ return new HashMap();
+ }
+
+ /**
+ * Creates a Tree Map. This is useful from Velocity since you cannot
+ * create Object from Velocity with our secure uberspector.
+ *
+ * @return a [EMAIL PROTECTED] TreeMap} object
+ * @since 1.3 Milestone 2
+ */
+ public Map getTreeMap()
+ {
+ return new TreeMap();
+ }
+
+ /**
+ * @return the current date
+ * @since 1.3 Milestone 2
+ */
+ public Date getDate()
+ {
+ return this.xwiki.getCurrentDate();
+ }
+
+ /**
+ * @param time time in milliseconds since 1970, 00:00:00 GMT
+ * @return Date a date from a time in milliseconds since 01/01/1970 as a
+ * Java [EMAIL PROTECTED] Date} Object
+ * @since 1.3 Milestone 2
+ */
+ public Date getDate(long time)
+ {
+ return this.xwiki.getDate(time);
+ }
+
+ /**
+ * @param time the time in milliseconds
+ * @return the time delta in milliseconds between the current date and the
time passed
+ * as parameter
+ * @since 1.3 Milestone 2
+ */
+ public int getTimeDelta(long time)
+ {
+ return this.xwiki.getTimeDelta(time);
+ }
+
+ /**
+ * Split a text to an array of texts, according to a separator.
+ *
+ * @param text the original text
+ * @param sep the separator characters. The separator is one or more of the
+ * separator characters
+ * @return An array containing the split text
+ * @since 1.3 Milestone 2
+ */
+ public String[] split(String text, String sep)
+ {
+ return this.xwiki.split(text, sep);
+ }
+
+ /**
+ * Get a stack trace as a String
+ *
+ * @param e the exception to convert to a String
+ * @return the exception stack trace as a String
+ * @since 1.3 Milestone 2
+ */
+ public String printStrackTrace(Throwable e)
+ {
+ return this.xwiki.printStrackTrace(e);
+ }
+
+ /**
+ * Sort a list using a standard comparator. Elements need to be mutally
comparable and
+ * implement the Comparable interface.
+ *
+ * @param list the list to sort
+ * @return the sorted list (as the same oject reference)
+ * @see [EMAIL PROTECTED] java.util.Collections#sort(java.util.List)}
+ * @since 1.3 Milestone 2
+ */
+ public List sort(List list)
+ {
+ Collections.sort(list);
+ return list;
+ }
+
+ /**
+ * Convert an Object to a number and return null if the object is not a
Number.
+ *
+ * @param object the object to convert
+ * @return the object as a [EMAIL PROTECTED] Number}
+ * @since 1.3 Milestone 2
+ */
+ public Number toNumber(java.lang.Object object)
+ {
+ try {
+ return new Long(object.toString());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /**
+ * Generate a random string.
+ *
+ * @param size the desired size of the string
+ * @return the randomly generated string
+ * @since 1.3 Milestone 2
+ */
+ public String generateRandomString(int size)
+ {
+ return this.xwiki.generateRandomString(size);
+ }
+
+ /**
+ * Output a BufferedImage object into the response outputstream.
+ * Once this method has been called, not further action is possible.
+ * Users should set $context.setFinished(true) to
+ * avoid template output The image is outpout as image/jpeg.
+ *
+ * @param image the BufferedImage to output
+ * @throws java.io.IOException if the output fails
+ * @since 1.3 Milestone 2
+ */
+ public void outputImage(BufferedImage image) throws IOException
+ {
+ JPEGImageEncoder encoder;
+ OutputStream ostream =
getXWikiContext().getResponse().getOutputStream();
+ encoder = JPEGCodec.createJPEGEncoder(ostream);
+ encoder.encode(image);
+ ostream.flush();
+ }
+
+ /**
+ * Get a Null object. This is useful in Velocity where there is no real
null object
+ * for comparaisons.
+ *
+ * @return a Null Object
+ * @since 1.3 Milestone 2
+ */
+ public Object getNull()
+ {
+ return null;
+ }
+
+ /**
+ * Get a New Line character. This is useful in Velocity where there is no
real new
+ * line character for inclusion in texts.
+ *
+ * @return a new line character
+ * @since 1.3 Milestone 2
+ */
+ public String getNewline()
+ {
+ return "\n";
+ }
+
+ /**
+ * @param str the String to convert to an integer
+ * @return the parsed integer or zero in case of exception
+ * @since 1.3 Milestone 2
+ */
+ public int parseInt(String str)
+ {
+ try {
+ return Integer.parseInt(str);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ /**
+ * @param str the String to convert to an Integer Object
+ * @return the parsed integer or zero in case of exception
+ * @since 1.3 Milestone 2
+ */
+ public Integer parseInteger(String str)
+ {
+ return new Integer(parseInt(str));
+ }
+
+ /**
+ * @param str the String to convert to a long
+ * @return the parsed long or zero in case of exception
+ * @since 1.3 Milestone 2
+ */
+ public long parseLong(String str)
+ {
+ try {
+ return Long.parseLong(str);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ /**
+ * @param str the String to convert to a float
+ * @return the parsed float or zero in case of exception
+ * @since 1.3 Milestone 2
+ */
+ public float parseFloat(String str)
+ {
+ try {
+ return Float.parseFloat(str);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ /**
+ * @param str the String to convert to a double
+ * @return the parsed double or zero in case of exception
+ * @since 1.3 Milestone 2
+ */
+ public double parseDouble(String str)
+ {
+ try {
+ return Double.parseDouble(str);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
+
+ /**
+ * Escape text so that it can be used in a like clause or in a test for
equality clause.
+ * For example it escapes single quote characters.
+ *
+ * @param text the text to escape
+ * @return filtered text
+ * @since 1.3 Milestone 2
+ */
+ public String escapeSQL(String text)
+ {
+ return Utils.SQLFilter(text);
+ }
+
+ /**
+ * Replace all accents by their alpha equivalent.
+ *
+ * @param text the text to parse
+ * @return a string with accents replaced with their alpha equivalent
+ * @since 1.3 Milestone 2
+ */
+ public String clearAccents(String text)
+ {
+ return com.xpn.xwiki.util.Util.noaccents(text);
+ }
+
+ /**
+ * Add a and b because Velocity operations are not always working.
+ *
+ * @param a an integer to add
+ * @param b an integer to add
+ * @return the sum of a and b
+ * @since 1.3 Milestone 2
+ */
+ public int add(int a, int b)
+ {
+ return a + b;
+ }
+
+ /**
+ * Add a and b because Velocity operations are not working with longs.
+ *
+ * @param a a long to add
+ * @param b a long to add
+ * @return the sum of a and b
+ * @since 1.3 Milestone 2
+ */
+ public long add(long a, long b)
+ {
+ return a + b;
+ }
+
+ /**
+ * Add a and b where a and b are non decimal numbers specified as Strings.
+ *
+ * @param a a string representing a non decimal number
+ * @param b a string representing a non decimal number
+ * @return the sum of a and b as a String
+ * @since 1.3 Milestone 2
+ */
+ public String add(String a, String b)
+ {
+ long c = Long.parseLong(a) + Long.parseLong(b);
+ return "" + c;
+ }
+
+ /**
+ * Cleans up the passed text by removing all accents and special
characters to make it
+ * a valid page name.
+ *
+ * @param name the page name to normalize
+ * @return the valid page name
+ * @since 1.3 Milestone 2
+ */
+ public String clearName(String name)
+ {
+ return this.xwiki.clearName(name, getXWikiContext());
+ }
+
+ /**
+ * Removes all non alpha numerical characters from the passed text. First
tries to convert
+ * accented chars to their alpha numeric representation.
+ *
+ * @param text the text to convert
+ * @return the alpha numeric equivalent
+ * @since 1.3 Milestone 2
+ */
+ public String convertToAlphaNumeric(String text)
+ {
+ return com.xpn.xwiki.util.Util.convertToAlphaNumeric(text);
+ }
+}
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
2008-02-01 13:24:12 UTC (rev 7261)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
2008-02-01 14:10:21 UTC (rev 7262)
@@ -20,12 +20,9 @@
package com.xpn.xwiki.api;
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.user.api.XWikiUser;
-import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.plugin.query.XWikiQuery;
import com.xpn.xwiki.plugin.query.XWikiCriteria;
import com.xpn.xwiki.doc.XWikiDeletedDocument;
@@ -33,7 +30,6 @@
import com.xpn.xwiki.objects.meta.MetaClass;
import com.xpn.xwiki.stats.api.XWikiStatsService;
import com.xpn.xwiki.stats.impl.DocumentStats;
-import com.xpn.xwiki.web.Utils;
import com.xpn.xwiki.web.XWikiEngineContext;
import org.suigeneris.jrcs.diff.delta.Chunk;
import org.apache.commons.logging.Log;
@@ -41,7 +37,6 @@
import java.awt.image.BufferedImage;
import java.io.IOException;
-import java.io.OutputStream;
import java.lang.Object;
import java.util.*;
@@ -49,6 +44,13 @@
{
protected static final Log LOG = LogFactory.getLog(XWiki.class);
+ /**
+ * Utility methods have been moved in version 1.3 Milestone 2 to the
[EMAIL PROTECTED] Util} class.
+ * However to preserve backward compatibility we have deprecated them in
this class and
+ * not removed them yet. All calls are funnelled through this class
variable.
+ */
+ private Util util;
+
private com.xpn.xwiki.XWiki xwiki;
/**
@@ -67,6 +69,7 @@
super(context);
this.xwiki = xwiki;
this.statsService = new StatsService(context);
+ this.util = new Util(xwiki, context);
}
/**
@@ -271,18 +274,22 @@
* API to protect Text from Wiki transformation
* @param text
* @return escaped text
+ * @deprecated replaced by Util#escapeText
*/
- public String escapeText(String text) {
- return Util.escapeText(text);
+ public String escapeText(String text)
+ {
+ return this.util.escapeText(text);
}
/**
* API to protect URLs from Wiki transformation
* @param url
* @return encoded URL
+ * @deprecated replaced by Util#escapeURL
*/
- public String escapeURL(String url) {
- return Util.escapeURL(url);
+ public String escapeURL(String url)
+ {
+ return this.util.escapeURL(url);
}
/**
@@ -1516,69 +1523,69 @@
}
/**
- * API to retrieve a java object with the current date
- *
* @return the current date
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getDate()}
*/
public Date getCurrentDate()
{
- return xwiki.getCurrentDate();
+ return this.util.getDate();
}
/**
- * API to retrieve a java object with the current date
- *
* @return the current date
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getDate()}
*/
public Date getDate()
{
- return xwiki.getCurrentDate();
+ return this.util.getDate();
}
/**
- * API to retrieve the time delta in milliseconds between the current date
and the time passed
- * as parameter.
- *
- * @param time
- * @return delta of the time in milliseconds
+ * @param time the time in milliseconds
+ * @return the time delta in milliseconds between the current date and the
time passed
+ * as parameter
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getTimeDelta(long)}
*/
public int getTimeDelta(long time)
{
- return xwiki.getTimeDelta(time);
+ return this.util.getTimeDelta(time);
}
/**
- * API to convert a date from a time in milliseconds since 01/01/1970 to a
Java Date Object
- *
* @param time time in milliseconds since 1970, 00:00:00 GMT
- * @return Date object
+ * @return Date a date from a time in milliseconds since 01/01/1970 as a
+ * Java [EMAIL PROTECTED] Date} Object
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getDate(long)}
*/
public Date getDate(long time)
{
- return xwiki.getDate(time);
+ return this.util.getDate(time);
}
/**
- * API to split a text to an array of texts, according to a separator
- *
- * @param str original text
- * @param sep separator characters. The separator is one or more of the
separator characters
- * @return An array of the splitted text
+ * Split a text to an array of texts, according to a separator.
+ *
+ * @param text the original text
+ * @param sep the separator characters. The separator is one or more of the
+ * separator characters
+ * @return An array containing the split text
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#split(String, String)}
*/
- public String[] split(String str, String sep)
+ public String[] split(String text, String sep)
{
- return xwiki.split(str, sep);
+ return this.util.split(text, sep);
}
/**
- * API to retrieve an exception stack trace in a String
- *
- * @param e Exception to retrieve the stack trace from
- * @return Text showing the exception stack trace
+ * Get a stack trace as a String
+ *
+ * @param e the exception to convert to a String
+ * @return the exception stack trace as a String
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#printStrackTrace(Throwable)}
*/
public String printStrackTrace(Throwable e)
{
- return xwiki.printStrackTrace(e);
+ return this.util.printStrackTrace(e);
}
/**
@@ -1593,25 +1600,27 @@
}
/**
- * API to retrieve a NULL object This is usefull in Velocity where there
is no real null object
- * for comparaisons
- *
- * @return A null Object
+ * Get a Null object. This is useful in Velocity where there is no real
null object
+ * for comparaisons.
+ *
+ * @return a Null Object
+ * @deprecated replaced by [EMAIL PROTECTED] Util#getNull()}
*/
public Object getNull()
{
- return null;
+ return this.util.getNull();
}
/**
- * API to retrieve a New Line character This is usefull in Velocity where
there is no real new
- * line character for inclusion in texts
- *
- * @return A new line character
+ * Get a New Line character. This is useful in Velocity where there is no
real new
+ * line character for inclusion in texts.
+ *
+ * @return a new line character
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getNewline()}
*/
public String getNl()
{
- return "\n";
+ return this.util.getNewline();
}
/**
@@ -1746,79 +1755,92 @@
}
/**
- * API to retrieve an List object This is usefull is velocity where you
cannot create objects
- *
- * @return a java.util.ArrayList object casted to List
+ * Creates an Array List. This is useful from Velocity since you cannot
+ * create Object from Velocity with our secure uberspector.
+ *
+ * @return a [EMAIL PROTECTED] ArrayList} object
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getArrayList()}
*/
public List getArrayList()
{
- return new ArrayList();
+ return this.util.getArrayList();
}
/**
- * API to retrieve an Map object This is usefull is velocity where you
cannot create objects
- *
- * @return a java.util.HashMap object casted to Map
+ * Creates a Hash Map. This is useful from Velocity since you cannot
+ * create Object from Velocity with our secure uberspector.
+ *
+ * @return a [EMAIL PROTECTED] HashMap} object
+ * @deprecated replaced by [EMAIL PROTECTED] Util#getHashMap()} ()}
*/
public Map getHashMap()
{
- return new HashMap();
+ return this.util.getHashMap();
}
+ /**
+ * Creates a Tree Map. This is useful from Velocity since you cannot
+ * create Object from Velocity with our secure uberspector.
+ *
+ * @return a [EMAIL PROTECTED] TreeMap} object
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getTreeMap()} ()}
+ */
public Map getTreeMap()
{
- return new TreeMap();
+ return this.util.getTreeMap();
}
/**
- * API to sort a list over standard comparator. Elements need to be
mutally comparable and
- * implement the Comparable interface
- *
- * @param list List to sort
- * @return the sorted list (in the same oject)
- * @see Collections void sort(List list)
+ * Sort a list using a standard comparator. Elements need to be mutally
comparable and
+ * implement the Comparable interface.
+ *
+ * @param list the list to sort
+ * @return the sorted list (as the same oject reference)
+ * @see [EMAIL PROTECTED] java.util.Collections#sort(java.util.List)}
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#sort(java.util.List)}
*/
public List sort(List list)
{
- Collections.sort(list);
- return list;
+ return this.util.sort(list);
}
- public Number toNumber(Object o)
+ /**
+ * Convert an Object to a number and return null if the object is not a
Number.
+ *
+ * @param object the object to convert
+ * @return the object as a [EMAIL PROTECTED] Number}
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#toNumber(Object)}
+ */
+ public Number toNumber(Object object)
{
- try {
- return new Long(o.toString());
- } catch (Exception e) {
- return null;
- }
+ return this.util.toNumber(object);
}
/**
- * API to generate a random string
+ * Generate a random string.
*
- * @param size Desired size of the string
- * @return the generated string
+ * @param size the desired size of the string
+ * @return the randomly generated string
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#generateRandomString(int)}
*/
public String generateRandomString(int size)
{
- return xwiki.generateRandomString(size);
+ return this.util.generateRandomString(size);
}
/**
- * API to Outpout an BufferedImage object into the response outputstream
Once this function has
- * been called, not further action is possible Users should set
$context.setFinished(true) to
- * avoid template output The image is outpout as image/jpeg
- *
- * @param image BufferedImage to output
- * @throws IOException exception if the output fails
+ * Output a BufferedImage object into the response outputstream.
+ * Once this method has been called, not further action is possible.
+ * Users should set $context.setFinished(true) to
+ * avoid template output The image is outpout as image/jpeg.
+ *
+ * @param image the BufferedImage to output
+ * @throws java.io.IOException if the output fails
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#outputImage(java.awt.image.BufferedImage)}
*/
public void outputImage(BufferedImage image) throws IOException
{
- JPEGImageEncoder encoder;
- OutputStream ostream =
getXWikiContext().getResponse().getOutputStream();
- encoder = JPEGCodec.createJPEGEncoder(ostream);
- encoder.encode(image);
- ostream.flush();
+ this.util.outputImage(image);
}
/**
@@ -2139,74 +2161,53 @@
}
/**
- * Retrieves a int from a String
- *
- * @param str String to convert to int
- * @return the int or zero in case of exception
+ * @param str the String to convert to an integer
+ * @return the parsed integer or zero in case of exception
+ * @deprecated replaced by [EMAIL PROTECTED] Util#parseInt(String)}
*/
public int parseInt(String str)
{
- try {
- return Integer.parseInt(str);
- } catch (Exception e) {
- return 0;
- }
+ return this.util.parseInt(str);
}
/**
- * Retrieves a int from a String
- *
- * @param str String to convert to int
- * @return the int or zero in case of exception
+ * @param str the String to convert to an Integer Object
+ * @return the parsed integer or zero in case of exception
+ * @deprecated replaced by [EMAIL PROTECTED] Util#parseInteger(String)}
*/
public Integer parseInteger(String str)
{
- return new Integer(parseInt(str));
+ return this.util.parseInteger(str);
}
/**
- * Retrieves a long from a String
- *
- * @param str String to convert to long
- * @return the long or zero in case of exception
+ * @param str the String to convert to a long
+ * @return the parsed long or zero in case of exception
+ * @deprecated replaced by [EMAIL PROTECTED] Util#parseLong(String)}
*/
public long parseLong(String str)
{
- try {
- return Long.parseLong(str);
- } catch (Exception e) {
- return 0;
- }
+ return this.util.parseLong(str);
}
/**
- * Retrieves a float from a String
- *
- * @param str String to convert to float
- * @return the float or zero in case of exception
+ * @param str the String to convert to a float
+ * @return the parsed float or zero in case of exception
+ * @deprecated replaced by [EMAIL PROTECTED] Util#parseFloat(String)}
*/
public float parseFloat(String str)
{
- try {
- return Float.parseFloat(str);
- } catch (Exception e) {
- return 0;
- }
+ return this.util.parseFloat(str);
}
/**
- * Retrieves a double from a String
- *
- * @param str String to convert to double
- * @return the double or zero in case of exception
+ * @param str the String to convert to a double
+ * @return the parsed double or zero in case of exception
+ * @deprecated replaced by [EMAIL PROTECTED] Util#parseDouble(String)}
*/
public double parseDouble(String str)
{
- try {
- return Double.parseDouble(str);
- } catch (Exception e) {
- return 0;
- }
+ return this.util.parseDouble(str);
}
/**
@@ -2318,14 +2319,16 @@
}
/**
- * Filters text to be include in = or like clause in SQL
- *
- * @param text text to filter
+ * Escape text so that it can be used in a like clause or in a test for
equality clause.
+ * For example it escapes single quote characters.
+ *
+ * @param text the text to escape
* @return filtered text
+ * @deprecated replaced by [EMAIL PROTECTED] Util#escapeSQL(String)}
*/
public String sqlfilter(String text)
{
- return Utils.SQLFilter(text);
+ return this.util.escapeSQL(text);
}
/**
@@ -2788,14 +2791,16 @@
}
/**
- * Cleans up the page name to make it valid
- *
- * @param name
- * @return A valid page name
+ * Cleans up the passed text by removing all accents and special
characters to make it
+ * a valid page name.
+ *
+ * @param name the page name to normalize
+ * @return the valid page name
+ * @deprecated replaced by [EMAIL PROTECTED] Util#clearName(String)}
*/
public String clearName(String name)
{
- return xwiki.clearName(name, getXWikiContext());
+ return this.util.clearName(name);
}
/**
@@ -2841,11 +2846,16 @@
return xwiki.addMandatory(getXWikiContext());
}
- /*
- * Clear accents
+ /**
+ * Replace all accents by their alpha equivalent.
+ *
+ * @param text the text to parse
+ * @return a string with accents replaced with their alpha equivalent
+ * @deprecated replaced by [EMAIL PROTECTED] Util#clearAccents(String)}
*/
- public String clearAccents(String text) {
- return Util.noaccents(text);
+ public String clearAccents(String text)
+ {
+ return this.util.clearAccents(text);
}
/**
@@ -2915,34 +2925,42 @@
}
/**
- * Add a and b because velocity operations are not always working
- * @param a
- * @param b
- * @return a+b
+ * Add a and b because Velocity operations are not always working.
+ *
+ * @param a an integer to add
+ * @param b an integer to add
+ * @return the sum of a and b
+ * @deprecated replaced by [EMAIL PROTECTED] Util#add(int, int)}
*/
- public int add(int a, int b) {
- return a+b;
+ public int add(int a, int b)
+ {
+ return this.util.add(a, b);
}
/**
- * Add a and b because velocity operations are not working with longs
- * @param a
- * @param b
- * @return a+b
+ * Add a and b because Velocity operations are not working with longs.
+ *
+ * @param a a long to add
+ * @param b a long to add
+ * @return the sum of a and b
+ * @deprecated replaced by [EMAIL PROTECTED] Util#add(long, long)}
*/
- public long add(long a, long b) {
- return a+b;
+ public long add(long a, long b)
+ {
+ return this.util.add(a, b);
}
/**
- * Add a and b because velocity operations are not working with longs
- * @param a
- * @param b
- * @return a+b
+ * Add a and b where a and b are non decimal numbers specified as Strings.
+ *
+ * @param a a string representing a non decimal number
+ * @param b a string representing a non decimal number
+ * @return the sum of a and b as a String
+ * @deprecated replaced by [EMAIL PROTECTED] Util#add(String, String)}
*/
- public String add(String a, String b) {
- long c = Long.parseLong(a) + Long.parseLong(b);
- return "" + c;
+ public String add(String a, String b)
+ {
+ return this.util.add(a, b);
}
/**
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
2008-02-01 13:24:12 UTC (rev 7261)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
2008-02-01 14:10:21 UTC (rev 7262)
@@ -132,6 +132,9 @@
// what the user can access.
vcontext.put("context", new Context(context));
+ // Put the Util API in the Velocity context.
+ vcontext.put("util", new com.xpn.xwiki.api.Util(context.getWiki(),
context));
+
// Save the Velocity Context in the XWiki context so that users can
access the objects
// we've put in it (xwiki, request, response, etc).
context.put("vcontext", vcontext);
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications