Commit 28676315 authored by Ryan Graham's avatar Ryan Graham Committed by ryang

added schema validation

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@2757 b35dd754-fafc-0310-a699-88a17e54d16e
parent b9e91c9c
...@@ -101,6 +101,16 @@ public class ImportExportPlugin implements Plugin { ...@@ -101,6 +101,16 @@ public class ImportExportPlugin implements Plugin {
return importUsers(document, previousDomain); return importUsers(document, previousDomain);
} }
public boolean validateImportFile(FileItem file) {
try {
return new UserSchemaValidator(file, "messenger-user-schema.xsd.xml").validate();
}
catch (Exception e) {
Log.error(e);
return false;
}
}
private Document exportUsers() { private Document exportUsers() {
Document document = DocumentHelper.createDocument(); Document document = DocumentHelper.createDocument();
Element root = document.addElement("JiveMessenger"); Element root = document.addElement("JiveMessenger");
...@@ -150,7 +160,7 @@ public class ImportExportPlugin implements Plugin { ...@@ -150,7 +160,7 @@ public class ImportExportPlugin implements Plugin {
return document; return document;
} }
private List<String> importUsers(Document document, String previousDomain) throws DocumentException { private List<String> importUsers(Document document, String previousDomain) {
List<String> duplicateUsers = new ArrayList<String>(); List<String> duplicateUsers = new ArrayList<String>();
UserManager userManager = UserManager.getInstance(); UserManager userManager = UserManager.getInstance();
......
...@@ -5,6 +5,7 @@ import com.sun.msv.reader.util.IgnoreController; ...@@ -5,6 +5,7 @@ import com.sun.msv.reader.util.IgnoreController;
import com.sun.msv.verifier.DocumentDeclaration; import com.sun.msv.verifier.DocumentDeclaration;
import com.sun.msv.verifier.Verifier; import com.sun.msv.verifier.Verifier;
import org.apache.commons.fileupload.FileItem;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
...@@ -15,8 +16,7 @@ import org.xml.sax.ErrorHandler; ...@@ -15,8 +16,7 @@ import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import java.io.File; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
...@@ -25,12 +25,11 @@ public class UserSchemaValidator { ...@@ -25,12 +25,11 @@ public class UserSchemaValidator {
private Document doc; private Document doc;
private String schema; private String schema;
UserSchemaValidator(String usersFile, String schemaFile) throws MalformedURLException, DocumentException { UserSchemaValidator(FileItem usersFile, String schemaFile) throws DocumentException, IOException {
URL usersURL = new File(usersFile).toURL();
URL schemaURL = this.getClass().getClassLoader().getResource(schemaFile);
SAXReader reader = new SAXReader(); SAXReader reader = new SAXReader();
doc = reader.read(usersURL); doc = reader.read(usersFile.getInputStream());
URL schemaURL = this.getClass().getClassLoader().getResource(schemaFile);
schema = schemaURL.toExternalForm(); schema = schemaURL.toExternalForm();
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
FileItem pd = (FileItem) i.next(); FileItem pd = (FileItem) i.next();
String previousDomain = pd.getString(); String previousDomain = pd.getString();
if (plugin.validateImportFile(fi)) {
try { try {
if (isEmpty(previousDomain)) { if (isEmpty(previousDomain)) {
duplicateUsers.addAll(plugin.importUserData(fi, null)); duplicateUsers.addAll(plugin.importUserData(fi, null));
...@@ -53,6 +54,10 @@ ...@@ -53,6 +54,10 @@
errors.put("DocumentException", "DocumentException"); errors.put("DocumentException", "DocumentException");
} }
} }
else {
errors.put("invalidUserFile", "invalidUserFile");
}
}
%> %>
<jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean" /> <jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean" />
......
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