Index: core/src/main/java/com/xpn/xwiki/i18n/i18n.java =================================================================== --- core/src/main/java/com/xpn/xwiki/i18n/i18n.java (revision 2475) +++ core/src/main/java/com/xpn/xwiki/i18n/i18n.java (working copy) @@ -34,5 +34,6 @@ public static final String LANGUAGE_GERMAN = "de"; public static final String LANGUAGE_SPANISH = "es"; public static final String LANGUAGE_ITALIAN = "it"; + public static final String LANGUAGE_CHINESE = "zh"; } Index: core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java =================================================================== --- core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java (revision 2475) +++ core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java (working copy) @@ -35,12 +35,14 @@ import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.io.StringReader; import java.io.StringWriter; @@ -673,12 +675,15 @@ private Document readPackage(InputStream is) throws IOException, DocumentException { - byte[] data = new byte[4096]; + //UTF-8 characters could cause encoding as continued bytes over 4096 boundary, + // so change byte to char. ---Jackson + char[] data = new char[4096]; + BufferedReader in= new BufferedReader(new InputStreamReader(is)); StringBuffer XmlFile = new StringBuffer(); int Cnt; - while ((Cnt = is.read(data, 0, 4096)) != -1) { + while ((Cnt = in.read(data, 0, 4096)) != -1) { XmlFile.append(new String(data, 0, Cnt)); - } + } return fromXml(XmlFile.toString()); } Index: core/src/main/java/com/xpn/xwiki/web/Utils.java =================================================================== --- core/src/main/java/com/xpn/xwiki/web/Utils.java (revision 2475) +++ core/src/main/java/com/xpn/xwiki/web/Utils.java (working copy) @@ -393,18 +393,36 @@ } } + // Suppose a normal iso-8859-1 string encode as a byte sequence not large than 0x80, + // and incorrect encoded utf-8 (as 8859) will generate a byte sequence in which + // some bytes value >0x80. + // Normal UTF-8 string converted to 8859 will get the bytes sequence mixed 8859 normal + // byte with '?' ,both of them less then 0x80. + // It's works fine on resource file encoded as utf-8. + // TODO: This is a temporary solution. + public static String FixUtf8(String str) + { + try { + byte b[]=str.getBytes("ISO-8859-1"); + int lp=b.length; + while(--lp>=0 && b[lp]>=0) {}; + if(lp>=0) + return new String(b,"UTF-8"); + } + catch(Exception e) + { + } + return str; + } + public static String decode(String name, XWikiContext context) { try { // Make sure + is considered as a space String result = name.replaceAll("\\+", " "); - + String ret=URLDecoder.decode(result, context.getWiki().getEncoding()); // 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()); + return FixUtf8(ret); } catch (Exception e) { return name; } Index: core/src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java =================================================================== --- core/src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java (revision 2475) +++ core/src/main/java/com/xpn/xwiki/web/XWikiMessageTool.java (working copy) @@ -138,7 +138,8 @@ String translation = getTranslation(key); if (translation == null) { try { - translation = this.bundle.getString(key); + //translation = this.bundle.getString(key); + translation = Utils.FixUtf8(this.bundle.getString(key)); } catch (Exception e) { translation = key; } Index: core/src/main/java/com/xpn/xwiki/web/XWikiServletRequest.java =================================================================== --- core/src/main/java/com/xpn/xwiki/web/XWikiServletRequest.java (revision 2475) +++ core/src/main/java/com/xpn/xwiki/web/XWikiServletRequest.java (working copy) @@ -39,6 +39,7 @@ import java.util.Locale; import java.util.Map; + public class XWikiServletRequest implements XWikiRequest { private HttpServletRequest request; @@ -87,7 +88,7 @@ } public String getPathInfo() { - return request.getPathInfo(); + return Utils.FixUtf8(request.getPathInfo()); } public String getPathTranslated() {