Commit dd439bca authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Enforce UTF-8 encoding when storing/reading XML content. JM-883

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5867 b35dd754-fafc-0310-a699-88a17e54d16e
parent f8b9a9a5
......@@ -461,6 +461,7 @@ public class XMLProperties {
private void buildDoc(Reader in) throws IOException {
try {
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
document = xmlReader.read(in);
}
catch (Exception e) {
......@@ -485,7 +486,7 @@ public class XMLProperties {
Writer writer = null;
try {
tempFile = new File(file.getParentFile(), file.getName() + ".tmp");
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile)));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tempFile), "UTF-8"));
OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
xmlWriter.write(document);
......
......@@ -89,9 +89,9 @@ public class XMLWriter extends XMLFilterImpl implements LexicalHandler {
namespaceStack.push(Namespace.NO_NAMESPACE);
}
public XMLWriter() {
public XMLWriter() throws UnsupportedEncodingException {
this.format = DEFAULT_FORMAT;
this.writer = new BufferedWriter( new OutputStreamWriter( System.out ) );
this.writer = new BufferedWriter( new OutputStreamWriter( System.out, "UTF-8" ) );
this.autoFlush = true;
namespaceStack.push(Namespace.NO_NAMESPACE);
}
......
......@@ -407,7 +407,9 @@ public class OfflineMessageStore extends BasicModule implements UserEventListene
super.start();
// Initialize the pool of sax readers
for (int i=0; i<10; i++) {
xmlReaders.add(new SAXReader());
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlReaders.add(xmlReader);
}
// Add this module as a user event listener so we can delete
// all offline messages when a user is deleted
......
......@@ -15,22 +15,22 @@ import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.event.UserEventListener;
import org.jivesoftware.wildfire.event.UserEventDispatcher;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.event.UserEventDispatcher;
import org.jivesoftware.wildfire.event.UserEventListener;
import org.jivesoftware.wildfire.user.User;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.Map;
/**
* Private storage for user accounts (JEP-0049). It is used by some XMPP systems
......@@ -222,7 +222,9 @@ public class PrivateStorage extends BasicModule implements UserEventListener {
super.start();
// Initialize the pool of sax readers
for (int i=0; i<10; i++) {
xmlReaders.add(new SAXReader());
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlReaders.add(xmlReader);
}
// Add this module as a user event listener so we can delete
// all user properties when a user is deleted
......
......@@ -215,6 +215,7 @@ public class PluginManager {
File pluginConfig = new File(pluginDir, "plugin.xml");
if (pluginConfig.exists()) {
SAXReader saxReader = new SAXReader();
saxReader.setEncoding("UTF-8");
Document pluginXML = saxReader.read(pluginConfig);
// See if the plugin specifies a version of Wildfire
......@@ -716,6 +717,7 @@ public class PluginManager {
File pluginConfig = new File(pluginDir, "plugin.xml");
if (pluginConfig.exists()) {
SAXReader saxReader = new SAXReader();
saxReader.setEncoding("UTF-8");
Document pluginXML = saxReader.read(pluginConfig);
Element element = (Element)pluginXML.selectSingleNode(xpath);
if (element != null) {
......
......@@ -20,9 +20,9 @@ import java.io.StringReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -66,7 +66,9 @@ public class PrivacyListProvider {
super();
// Initialize the pool of sax readers
for (int i=0; i<50; i++) {
xmlReaders.add(new SAXReader());
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlReaders.add(xmlReader);
}
// Load the total number of privacy lists in the database. We're looking
......
......@@ -149,7 +149,9 @@ public class PubSubPersistenceManager {
static {
// Initialize the pool of sax readers
for (int i=0; i<50; i++) {
xmlReaders.add(new SAXReader());
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlReaders.add(xmlReader);
}
}
......
......@@ -481,7 +481,9 @@ public class UpdateManager extends BasicModule {
throws DocumentException {
// Reset last known update information
serverUpdate = null;
Element xmlResponse = new SAXReader().read(new StringReader(response)).getRootElement();
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
Element xmlResponse = xmlReader.read(new StringReader(response)).getRootElement();
// Parse response and keep info as Update objects
Element wildfire = xmlResponse.element("wildfire");
if (wildfire != null) {
......@@ -514,7 +516,9 @@ public class UpdateManager extends BasicModule {
availablePlugins = new HashMap<String, AvailablePlugin>();
// Parse response and keep info as AvailablePlugin objects
Element xmlResponse = new SAXReader().read(new StringReader(response)).getRootElement();
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
Element xmlResponse = xmlReader.read(new StringReader(response)).getRootElement();
Iterator plugins = xmlResponse.elementIterator("plugin");
while (plugins.hasNext()) {
Element plugin = (Element) plugins.next();
......@@ -606,7 +610,7 @@ public class UpdateManager extends BasicModule {
file.delete();
}
// Create new version.xml with returned data
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
xmlWriter.write(xmlResponse);
......@@ -662,7 +666,7 @@ public class UpdateManager extends BasicModule {
file.delete();
}
// Create new version.xml with returned data
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);
xmlWriter.write(xml);
......@@ -711,6 +715,7 @@ public class UpdateManager extends BasicModule {
try {
reader = new FileReader(file);
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlResponse = xmlReader.read(reader);
}
catch (Exception e) {
......@@ -758,6 +763,7 @@ public class UpdateManager extends BasicModule {
try {
reader = new FileReader(file);
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlResponse = xmlReader.read(reader);
}
catch (Exception e) {
......
......@@ -53,7 +53,9 @@ public class DefaultVCardProvider implements VCardProvider {
super();
// Initialize the pool of sax readers
for (int i=0; i<10; i++) {
xmlReaders.add(new SAXReader());
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
xmlReaders.add(xmlReader);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment