Author: jvdrean
Date: 2008-02-14 19:18:12 +0100 (Thu, 14 Feb 2008)
New Revision: 7732
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/XWikiCompatibilityAspect.aj
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/api/
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/api/XWikiCompatibilityAspect.aj
Removed:
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/aspect/
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
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/XWiki.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/export/html/HtmlPackager.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/charts/actions/ChartingAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/packaging/PackageAPI.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiRadeoxRenderEngine.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/TOCGenerator.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/Util.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DotAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadRevAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SVGAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SkinAction.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/XWikiTest.java
Log:
XWIKI-2103 : Add encodeURI and decodeURI to Util, deprecate
XWiki.getURLEncoded, Utils.encode, Utils.decode
Added:
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/XWikiCompatibilityAspect.aj
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/XWikiCompatibilityAspect.aj
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/XWikiCompatibilityAspect.aj
2008-02-14 18:18:12 UTC (rev 7732)
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+import com.xpn.xwiki.XWiki;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.*;
+
+/**
+ * Add a backward compatibility layer to the [EMAIL PROTECTED]
com.xpn.xwiki.XWiki} class.
+ *
+ * @version $Id: $
+ */
+public privileged aspect XWikiCompatibilityAspect
+{
+ /**
+ * Transform a text in a URL compatible text
+ *
+ * @param content text to transform
+ * @return encoded result
+ * @deprecated replaced by Util#encodeURI since 1.3M2
+ */
+ public String XWiki.getURLEncoded(String content)
+ {
+ try {
+ return URLEncoder.encode(content, this.getEncoding());
+ } catch (UnsupportedEncodingException e) {
+ return content;
+ }
+ }
+}
Copied:
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/api/XWikiCompatibilityAspect.aj
(from rev 7725,
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/aspect/compatibility/XWikiCompatibilityAspect.aj)
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/api/XWikiCompatibilityAspect.aj
(rev 0)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/aspect/compatibility/com/xpn/xwiki/api/XWikiCompatibilityAspect.aj
2008-02-14 18:18:12 UTC (rev 7732)
@@ -0,0 +1,465 @@
+/*
+ * 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.api.XWiki;
+import com.xpn.xwiki.api.Util;
+import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.stats.api.XWikiStatsService;
+
+import java.io.IOException;
+import java.awt.image.BufferedImage;
+import java.util.*;
+
+/**
+ * Add a backward compatibility layer to the [EMAIL PROTECTED]
com.xpn.xwiki.api.XWiki} class.
+ *
+ * @version $Id: $
+ */
+public privileged aspect XWikiCompatibilityAspect
+{
+ /**
+ * 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 XWiki.util;
+
+ /**
+ * Capture the api.XWiki constructor so that we can initialize this.util.
+ */
+ private pointcut xwikiCreation(XWiki x): this(x) && execution( public
XWiki.new(..) );
+
+ after(XWiki x): xwikiCreation(x)
+ {
+ x.util = new Util(x.xwiki, x.context);
+ }
+
+ /**
+ * API to protect Text from Wiki transformation
+ * @param text
+ * @return escaped text
+ * @deprecated replaced by Util#escapeText since 1.3M2
+ */
+ public String XWiki.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 since 1.3M2
+ */
+ public String XWiki.escapeURL(String url)
+ {
+ return this.util.escapeURL(url);
+ }
+
+ /**
+ * @deprecated use [EMAIL PROTECTED] #getLanguagePreference()} instead
+ */
+ public String XWiki.getDocLanguagePreference()
+ {
+ return xwiki.getDocLanguagePreference(getXWikiContext());
+ }
+
+ /**
+ * Privileged API to send a message to an email address
+ *
+ * @param sender email of the sender of the message
+ * @param recipient email of the recipient of the message
+ * @param message Message to send
+ * @throws XWikiException if the mail was not send successfully
+ * @deprecated replaced by the
+ * <a
href="http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin">Mail Sender
+ * Plugin</a> since 1.3M2
+ */
+ public void XWiki.sendMessage(String sender, String recipient, String
message)
+ throws XWikiException
+ {
+ if (hasProgrammingRights())
+ xwiki.sendMessage(sender, recipient, message, getXWikiContext());
+ }
+
+ /**
+ * Privileged API to send a message to an email address
+ *
+ * @param sender email of the sender of the message
+ * @param recipient emails of the recipients of the message
+ * @param message Message to send
+ * @throws XWikiException if the mail was not send successfully
+ * @deprecated replaced by the
+ * <a
href="http://code.xwiki.org/xwiki/bin/view/Plugins/MailSenderPlugin">Mail Sender
+ * Plugin</a> since 1.3M2
+ */
+ public void XWiki.sendMessage(String sender, String[] recipient, String
message)
+ throws XWikiException
+ {
+ if (hasProgrammingRights())
+ xwiki.sendMessage(sender, recipient, message, getXWikiContext());
+ }
+
+ /**
+ * @return the current date
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getDate()} since 1.3M2
+ */
+ public Date XWiki.getCurrentDate()
+ {
+ return this.util.getDate();
+ }
+
+ /**
+ * @return the current date
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getDate()} since 1.3M2
+ */
+ public Date XWiki.getDate()
+ {
+ return this.util.getDate();
+ }
+
+ /**
+ * @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)} since 1.3M2
+ */
+ public int XWiki.getTimeDelta(long time)
+ {
+ return this.util.getTimeDelta(time);
+ }
+
+ /**
+ * @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
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#getDate(long)} since 1.3M2
+ */
+ public Date XWiki.getDate(long time)
+ {
+ return this.util.getDate(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
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#split(String, String)} since 1.3M2
+ */
+ public String[] XWiki.split(String text, String sep)
+ {
+ return this.util.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
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#printStrackTrace(Throwable)}
+ since 1.3M2
+ */
+ public String XWiki.printStrackTrace(Throwable e)
+ {
+ return this.util.printStrackTrace(e);
+ }
+
+ /**
+ * 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()} since 1.3M2
+ */
+ public Object XWiki.getNull()
+ {
+ return this.util.getNull();
+ }
+
+ /**
+ * 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()} since 1.3M2
+ */
+ public String XWiki.getNl()
+ {
+ return this.util.getNewline();
+ }
+
+ /**
+ * @see #getExoService(String)
+ * @deprecated use [EMAIL PROTECTED] #getExoService(String)} instead
+ */
+ public java.lang.Object XWiki.getService(String className) throws
XWikiException
+ {
+ return getExoService(className);
+ }
+
+ /**
+ * @see #getExoPortalService(String)
+ * @deprecated use [EMAIL PROTECTED] #getExoPortalService(String)} instead
+ */
+ public java.lang.Object XWiki.getPortalService(String className) throws
XWikiException
+ {
+ return getExoPortalService(className);
+ }
+
+ /**
+ * 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()} since 1.3M2
+ */
+ public List XWiki.getArrayList()
+ {
+ return this.util.getArrayList();
+ }
+
+ /**
+ * 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()} since 1.3M2
+ */
+ public Map XWiki.getHashMap()
+ {
+ 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()} since 1.3M2
+ */
+ public Map XWiki.getTreeMap()
+ {
+ return this.util.getTreeMap();
+ }
+
+ /**
+ * 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)} since 1.3M2
+ */
+ public List XWiki.sort(List list)
+ {
+ return this.util.sort(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}
+ * @deprecated replaced by [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#toNumber(Object)} since 1.3M2
+ */
+ public Number XWiki.toNumber(Object object)
+ {
+ return this.util.toNumber(object);
+ }
+
+ /**
+ * Generate a random 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)}
+ since 1.3M2
+ */
+ public String XWiki.generateRandomString(int size)
+ {
+ return this.util.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
+ * @deprecated replaced by
+ * [EMAIL PROTECTED]
com.xpn.xwiki.api.Util#outputImage(java.awt.image.BufferedImage)}
+ * since 1.3M2
+ */
+ public void XWiki.outputImage(BufferedImage image) throws IOException
+ {
+ this.util.outputImage(image);
+ }
+
+ /**
+ * Returns the recently visited pages for a specific action
+ *
+ * @param action ("view" or "edit")
+ * @param size how many recent actions to retrieve
+ * @return a ArrayList of document names
+ * @deprecated use [EMAIL PROTECTED] #getStatsService()} instead
+ */
+ public java.util.Collection XWiki.getRecentActions(String action, int size)
+ {
+ XWikiStatsService stats =
getXWikiContext().getWiki().getStatsService(getXWikiContext());
+ if (stats == null)
+ return Collections.EMPTY_LIST;
+ return stats.getRecentActions(action, size, getXWikiContext());
+ }
+
+ /**
+ * @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)} since
1.3M2
+ */
+ public int XWiki.parseInt(String str)
+ {
+ return this.util.parseInt(str);
+ }
+
+ /**
+ * @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)}
since 1.3M2
+ */
+ public Integer XWiki.parseInteger(String str)
+ {
+ return this.util.parseInteger(str);
+ }
+
+ /**
+ * @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)} since
1.3M2
+ */
+ public long XWiki.parseLong(String str)
+ {
+ return this.util.parseLong(str);
+ }
+
+ /**
+ * @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)}
since 1.3M2
+ */
+ public float XWiki.parseFloat(String str)
+ {
+ return this.util.parseFloat(str);
+ }
+
+ /**
+ * @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)}
since 1.3M2
+ */
+ public double XWiki.parseDouble(String str)
+ {
+ return this.util.parseDouble(str);
+ }
+
+ /**
+ * 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)} since
1.3M2
+ */
+ public String XWiki.sqlfilter(String text)
+ {
+ return this.util.escapeSQL(text);
+ }
+
+ /**
+ * 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)} since
1.3M2
+ */
+ public String XWiki.clearName(String name)
+ {
+ return this.util.clearName(name);
+ }
+
+ /**
+ * 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)}
since 1.3M2
+ */
+ public String XWiki.clearAccents(String text)
+ {
+ return this.util.clearAccents(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
+ * @deprecated replaced by [EMAIL PROTECTED] Util#add(int, int)} since
1.3M2
+ */
+ public int XWiki.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 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)} since
1.3M2
+ */
+ public long XWiki.add(long a, long b)
+ {
+ return this.util.add(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)}
since 1.3M2
+ */
+ public String XWiki.add(String a, String b)
+ {
+ return this.util.add(a, b);
+ }
+}
\ No newline at end of file
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
2008-02-14 14:38:39 UTC (rev 7731)
+++ xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -33,7 +33,6 @@
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLEncoder;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -1181,8 +1180,8 @@
if (name.equals(""))
name = "WebHome";
- web = Utils.decode(web, context);
- name = Utils.decode(name, context);
+ web = Util.decodeURI(web, context);
+ name = Util.decodeURI(name, context);
String fullname = web + "." + name;
return fullname;
}
@@ -1247,15 +1246,6 @@
return scontent;
}
- public String getURLEncoded(String content)
- {
- try {
- return URLEncoder.encode(content, this.getEncoding());
- } catch (UnsupportedEncodingException e) {
- return content;
- }
- }
-
public static String getXMLEncoded(String content)
{
Filter filter = new CharacterFilter();
Modified:
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
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/Util.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -80,6 +80,29 @@
}
/**
+ * Make a text URI compliant
+ * @param text the non encoded text
+ * @return encoded text
+ * @since 1.3 Milestone 2
+ */
+ public String encodeURI(String text)
+ {
+ return com.xpn.xwiki.util.Util.encodeURI(text, context);
+ }
+
+ /**
+ * Make an URI compliant text readable
+ * @param text the encoded text
+ * @return decoded text
+ * @since 1.3 Milestone 2
+ */
+ public String decodeURI(String text)
+ {
+ return com.xpn.xwiki.util.Util.decodeURI(text, context);
+ }
+
+
+ /**
* Creates an Array List. This is useful from Velocity since you cannot
create Object from
* Velocity with our secure uberspector.
*
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-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/api/XWiki.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -238,18 +238,6 @@
}
/**
- * Transform a text in a URL compatible text
- *
- * @param content text to transform
- * @return encoded result
- */
-
- public String getURLEncoded(String content)
- {
- return xwiki.getURLEncoded(content);
- }
-
- /**
* Transform a text in a XML compatible text
*
* @param content text to transform
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/export/html/HtmlPackager.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/export/html/HtmlPackager.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/export/html/HtmlPackager.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -15,6 +15,7 @@
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.api.Document;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.render.XWikiVelocityRenderer;
@@ -229,7 +230,7 @@
{
context.getResponse().setContentType("application/zip");
context.getResponse().addHeader("Content-disposition",
- "attachment; filename=" + context.getWiki().getURLEncoded(name) +
".zip");
+ "attachment; filename=" + Util.encodeURI(name, context) + ".zip");
context.setFinished(true);
ZipOutputStream zos = new
ZipOutputStream(context.getResponse().getOutputStream());
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/charts/actions/ChartingAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/charts/actions/ChartingAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/charts/actions/ChartingAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -23,7 +23,7 @@
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.plugin.charts.ChartingPluginApi;
-import com.xpn.xwiki.web.Utils;
+import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.XWikiAction;
import com.xpn.xwiki.web.XWikiRequest;
@@ -33,7 +33,7 @@
public String render(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
String path = request.getRequestURI();
- String filename =
Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
+ String filename =
Util.decodeURI(path.substring(path.lastIndexOf("/")+1),context);
try {
((ChartingPluginApi)context.getWiki().getPluginApi("charting",context)).outputFile(filename,
context);
} catch (IOException e) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/packaging/PackageAPI.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/packaging/PackageAPI.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/plugin/packaging/PackageAPI.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -21,10 +21,10 @@
package com.xpn.xwiki.plugin.packaging;
-import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.util.Util;
import java.io.IOException;
import java.util.ArrayList;
@@ -164,7 +164,7 @@
public String export() throws IOException, XWikiException {
getXWikiContext().getResponse().setContentType("application/zip");
getXWikiContext().getResponse().addHeader("Content-disposition",
"attachment; filename="
- + getXWikiContext().getWiki().getURLEncoded(plugin.getName()) +
".xar");
+ + Util.encodeURI(plugin.getName(), context) + ".xar");
getXWikiContext().setFinished(true);
return
plugin.export(getXWikiContext().getResponse().getOutputStream(),
getXWikiContext());
}
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiRadeoxRenderEngine.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiRadeoxRenderEngine.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiRadeoxRenderEngine.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -262,7 +262,7 @@
buffer.append("<span class=\"wikilink\"><a href=\"#");
buffer.append(anchor);
buffer.append("\">");
- if (view.length() == 0) view = Utils.decode(anchor, getXWikiContext());
+ if (view.length() == 0) view = Util.decodeURI(anchor,
getXWikiContext());
buffer.append(cleanText(view));
buffer.append("</a></span>");
}
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/TOCGenerator.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/TOCGenerator.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/TOCGenerator.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -107,7 +107,7 @@
}
public static String makeHeadingID (String text, int occurence, XWikiContext
context) {
- text = "H" + context.getWiki().getURLEncoded(text);
+ text = "H" + Util.encodeURI(text, context);
text = text.replaceAll("[^a-zA-Z0-9]", "");
if (occurence > 0) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/Util.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/Util.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/util/Util.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -33,7 +33,8 @@
import java.io.StreamTokenizer;
import java.io.StringReader;
import java.util.*;
-
+import java.net.URLEncoder;
+import java.net.URLDecoder;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -62,6 +63,7 @@
import com.xpn.xwiki.monitor.api.MonitorPlugin;
import com.xpn.xwiki.render.WikiSubstitution;
import com.xpn.xwiki.web.XWikiRequest;
+import com.novell.ldap.util.Base64;
public class Util {
@@ -698,6 +700,46 @@
}
/**
+ * API to make a text URI compliant
+ * @param text
+ * @param context
+ * @return encoded text
+ */
+ public static String encodeURI(String text, XWikiContext context)
+ {
+ try {
+ return URLEncoder.encode(text, context.getWiki().getEncoding());
+ } catch (Exception e) {
+ return text;
+ }
+ }
+
+ /**
+ * API to make readable an URI compliant text
+ * @param text
+ * @param context
+ * @return decoded text
+ */
+ public static String decodeURI(String text, XWikiContext context)
+ {
+ try {
+ // Make sure + is considered as a space
+ String result = text.replaceAll("\\+", " ");
+
+ // It seems Internet Explorer can send us back UTF-8
+ // instead of ISO-8859-1 for URLs
+ if (Base64.isValidUTF8(result.getBytes(), false)) {
+ result = new String(result.getBytes(), "UTF-8");
+ }
+
+ // Still need to decode URLs
+ return URLDecoder.decode(result, context.getWiki().getEncoding());
+ } catch (Exception e) {
+ return text;
+ }
+ }
+
+ /**
* Removes all non alpha numerical characters from the passed text. First
tries to convert
* accented chars to their alpha numeric representation.
*
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -23,6 +23,7 @@
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.util.Util;
import java.util.ArrayList;
@@ -41,7 +42,7 @@
// Note: We use getRequestURI() because the spec says the server
doesn't decode it, as
// we want to use our own decoding.
String requestUri = request.getRequestURI();
- filename =
Utils.decode(requestUri.substring(requestUri.lastIndexOf("/") + 1), context);
+ filename =
Util.decodeURI(requestUri.substring(requestUri.lastIndexOf("/") + 1), context);
}
XWikiDocument newdoc = (XWikiDocument) doc.clone();
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DotAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DotAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DotAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -23,6 +23,7 @@
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.plugin.graphviz.GraphVizPlugin;
+import com.xpn.xwiki.util.Util;
import java.io.IOException;
@@ -31,7 +32,7 @@
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
String path = request.getRequestURI();
- String filename =
Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
+ String filename =
Util.decodeURI(path.substring(path.lastIndexOf("/")+1),context);
try {
((GraphVizPlugin)context.getWiki().getPlugin("graphviz",context)).outputDotImageFromFile(filename,
context);
} catch (IOException e) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -19,14 +19,15 @@
*/
package com.xpn.xwiki.web;
-import java.io.IOException;
-
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.plugin.XWikiPluginManager;
+import com.xpn.xwiki.util.Util;
+import java.io.IOException;
+
public class DownloadAction extends XWikiAction
{
public String getFileName(String path, String action)
@@ -48,7 +49,7 @@
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
String path = request.getRequestURI();
- String filename = Utils.decode(getFileName(path, "download"), context);
+ String filename = Util.decodeURI(getFileName(path, "download"),
context);
XWikiAttachment attachment;
if (request.getParameter("id") != null) {
@@ -74,7 +75,7 @@
response.setContentType(mimetype);
String ofilename =
-
context.getWiki().getURLEncoded(attachment.getFilename()).replaceAll("\\+", "
");
+ Util.encodeURI(attachment.getFilename(),
context).replaceAll("\\+", " ");
// The inline attribute of Content-Disposition tells the browser that
they should display
// the downloaded file in the page (see
http://www.ietf.org/rfc/rfc1806.txt for more
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadRevAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadRevAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/DownloadRevAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -5,6 +5,7 @@
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.plugin.XWikiPluginManager;
+import com.xpn.xwiki.util.Util;
import java.io.IOException;
@@ -15,7 +16,7 @@
XWikiDocument doc = context.getDoc();
String rev = request.getParameter("rev");
String path = request.getRequestURI();
- String filename =
Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
+ String filename =
Util.decodeURI(path.substring(path.lastIndexOf("/")+1),context);
XWikiAttachment attachment = null;
if (request.getParameter("id")!=null) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SVGAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SVGAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SVGAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -22,6 +22,7 @@
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
+import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.plugin.svg.SVGPlugin;
import java.io.IOException;
@@ -31,7 +32,7 @@
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
String path = request.getRequestURI();
- String filename =
Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
+ String filename =
Util.decodeURI(path.substring(path.lastIndexOf("/")+1),context);
try {
((SVGPlugin)context.getWiki().getPlugin("svg",context)).outputSVGImageFromFile(filename,
context);
} catch (IOException e) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SkinAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SkinAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/SkinAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -20,20 +20,20 @@
*/
package com.xpn.xwiki.web;
-import java.io.IOException;
-import java.util.Date;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
+import com.xpn.xwiki.util.Util;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import java.io.IOException;
+import java.util.Date;
+
/**
* <p>
* Action for serving skin files. It allows skins to be defined using
XDocuments as skins, by
@@ -80,7 +80,7 @@
boolean found = false;
while (idx > 0) {
try {
- String filename = Utils.decode(path.substring(idx + 1),
context);
+ String filename = Util.decodeURI(path.substring(idx + 1),
context);
LOG.debug("Trying '" + filename + "'");
if (renderSkin(filename, doc, context)) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/Utils.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -424,7 +424,10 @@
}
}
- // TODO: Duplicate of XWiki.getURLEncoded(). Keep only one
+ // TODO: Duplicate of Util.encodeURI(). Keep only one
+ /**
+ * @deprecated replaced by Util#encodeURI since 1.3M2
+ */
public static String encode(String name, XWikiContext context)
{
try {
@@ -434,6 +437,10 @@
}
}
+ // TODO: Duplicate of Util.decodeURI(). Keep only one
+ /**
+ * @deprecated replaced by Util#decodeURI since 1.3M2
+ */
public static String decode(String name, XWikiContext context)
{
try {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/web/ViewAttachRevAction.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -26,6 +26,7 @@
import com.xpn.xwiki.api.Document;
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.util.Util;
import org.apache.velocity.VelocityContext;
public class ViewAttachRevAction extends XWikiAction {
@@ -38,7 +39,7 @@
if (context.getMode() == XWikiContext.MODE_PORTLET)
filename = request.getParameter("filename");
else
- filename = Utils.decode(path.substring(path.lastIndexOf("/") + 1),
context);
+ filename = Util.decodeURI(path.substring(path.lastIndexOf("/") +
1), context);
XWikiAttachment attachment = null;
if (request.getParameter("id") != null) {
Modified:
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/XWikiTest.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/XWikiTest.java
2008-02-14 14:38:39 UTC (rev 7731)
+++
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/XWikiTest.java
2008-02-14 18:18:12 UTC (rev 7732)
@@ -201,25 +201,25 @@
assertFalse(xwiki.getDocument("XWiki.Skin", context).isNew());
assertEquals(skin, xwiki.getDocument("XWiki.Skin", context));
assertEquals("parsing a field", xwiki.parseTemplate("template.vm",
context));
- }
-
- public void testClearNameWithoutStripDotsWithoutAscii()
- {
- assertEquals("ee{&.txt", this.xwiki.clearName("\u00E9\u00EA{&.txt",
false, false, context));
- }
-
- public void testClearNameWithoutStripDotsWithAscii()
- {
- assertEquals("ee.txt", this.xwiki.clearName("\u00E9\u00EA{&.txt",
false, true, context));
- }
-
- public void testClearNameWithStripDotsWithoutAscii()
- {
- assertEquals("ee{&txt", this.xwiki.clearName("\u00E9\u00EA{&.txt",
true, false, context));
- }
-
- public void testClearNameWithStripDotsWithAscii()
- {
- assertEquals("eetxt", this.xwiki.clearName("\u00E9\u00EA{&.txt", true,
true, context));
}
+
+ public void testClearNameWithoutStripDotsWithoutAscii()
+ {
+ assertEquals("ee{&.txt", this.xwiki.clearName("\u00E9\u00EA{&.txt",
false, false, context));
+ }
+
+ public void testClearNameWithoutStripDotsWithAscii()
+ {
+ assertEquals("ee.txt", this.xwiki.clearName("\u00E9\u00EA{&.txt",
false, true, context));
+ }
+
+ public void testClearNameWithStripDotsWithoutAscii()
+ {
+ assertEquals("ee{&txt", this.xwiki.clearName("\u00E9\u00EA{&.txt",
true, false, context));
+ }
+
+ public void testClearNameWithStripDotsWithAscii()
+ {
+ assertEquals("eetxt", this.xwiki.clearName("\u00E9\u00EA{&.txt", true,
true, context));
+ }
}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications