Fix i18n encodding issue.

This commit is contained in:
Paulo Gustavo Veiga 2012-11-19 22:47:20 -03:00
parent b717a5f910
commit c3dcd8f3a9
3 changed files with 21 additions and 44 deletions

View File

@ -82,14 +82,14 @@ public class Mindmap {
throws IOException {
byte[] result = this.xml;
if (result != null) {
result = ZipUtils.stringToZip(new String(result, UTF_8));
result = ZipUtils.bytesToZip(result);
}
return result;
}
public void setZippedXml(byte[] xml)
throws IOException {
this.xml = ZipUtils.zipToString(xml).getBytes(UTF_8);
this.xml = ZipUtils.zipToBytes(xml);
}
public Set<Collaboration> getCollaborations() {

View File

@ -18,67 +18,46 @@
package com.wisemapping.util;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipEntry;
public class ZipUtils {
public static String zipToString(byte[] zip) throws IOException {
public static byte[] zipToBytes(byte[] zip) throws IOException {
String result = null;
if (zip != null)
{
byte[] result = null;
if (zip != null) {
final ByteArrayInputStream in = new ByteArrayInputStream(zip);
final ZipInputStream zipIn = new ZipInputStream(in);
zipIn.getNextEntry();
byte[] buffer = new byte[512];
int len;
StringBuilder sb_result = new StringBuilder();
while ((len = zipIn.read(buffer)) > 0) {
sb_result.append(new String(buffer, 0, len, Charset.forName("UTF-8")));
}
result = IOUtils.toByteArray(zipIn);
zipIn.closeEntry();
zipIn.close();
result = sb_result.toString();
}
return result;
}
public static byte[] stringToZip(String content) throws IOException {
public static byte[] bytesToZip(@NotNull final byte[] content) throws IOException {
ZipOutputStream zip = null;
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
try {
zip = new ZipOutputStream(byteArray);
ZipEntry zEntry = new ZipEntry("content");
zip.putNextEntry(zEntry);
int bytesRead;
byte[] buffer = new byte[8192];
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
zip.write(buffer, 0, bytesRead);
}
IOUtils.write(content, zip);
zip.closeEntry();
}
finally
{
if (zip != null)
{
} finally {
if (zip != null) {
zip.flush();
zip.close();
}

View File

@ -26,8 +26,9 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.text.DateFormat;
import java.util.*;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MindMapBean {
private Mindmap mindmap;
@ -124,10 +125,7 @@ public class MindMapBean {
}
public String getXmlAsJsLiteral() throws IOException {
final String xmlAsJsLiteral = this.mindmap.getXmlAsJsLiteral();
// Firefox is failing for this. Need to be reviewed ...
return xmlAsJsLiteral.replace("\\u0000","");
return this.mindmap.getXmlAsJsLiteral();
}
public String getProperties() throws WiseMappingException {