added v1 conversion warnings

This commit is contained in:
bancika
2011-01-23 23:25:20 +00:00
parent fcc001cb98
commit 5806d17e56
2 changed files with 24 additions and 5 deletions
@@ -205,9 +205,21 @@ public class Presenter implements IPlugInPort {
public void loadProjectFromFile(String fileName) { public void loadProjectFromFile(String fileName) {
LOG.info(String.format("loadProjectFromFile(%s)", fileName)); LOG.info(String.format("loadProjectFromFile(%s)", fileName));
try { try {
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName); List<String> warnings = new ArrayList<String>();
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName,
warnings);
loadProject(project, true); loadProject(project, true);
projectFileManager.fireFileStatusChanged(); projectFileManager.fireFileStatusChanged();
if (!warnings.isEmpty()) {
StringBuilder builder = new StringBuilder(
"<html>File was opened, but there were some issues with it:<br><br>");
for (String warning : warnings) {
builder.append(warning);
builder.append("<br>");
}
builder.append("</html");
view.showMessage(builder.toString(), "Warning", IView.WARNING_MESSAGE);
}
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Could not load file", ex); LOG.error("Could not load file", ex);
view.showMessage("Could not open file " + fileName + ". Check the log for details.", view.showMessage("Could not open file " + fileName + ". Check the log for details.",
@@ -6,6 +6,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@@ -71,7 +73,7 @@ public class ProjectFileManager {
fireFileStatusChanged(); fireFileStatusChanged();
} }
public Project deserializeProjectFromFile(String fileName) throws SAXException, IOException, public Project deserializeProjectFromFile(String fileName, List<String> warnings) throws SAXException, IOException,
ParserConfigurationException { ParserConfigurationException {
LOG.info(String.format("loadProjectFromFile(%s)", fileName)); LOG.info(String.format("loadProjectFromFile(%s)", fileName));
Project project; Project project;
@@ -90,7 +92,7 @@ public class ProjectFileManager {
String formatVersion = doc.getDocumentElement().getAttribute("formatVersion"); String formatVersion = doc.getDocumentElement().getAttribute("formatVersion");
if (formatVersion == null || formatVersion.trim().isEmpty()) { if (formatVersion == null || formatVersion.trim().isEmpty()) {
LOG.debug("Detected v1 file."); LOG.debug("Detected v1 file.");
project = parseV1File(doc.getDocumentElement()); project = parseV1File(doc.getDocumentElement(), warnings);
} else if (formatVersion.equals("2.0")) { } else if (formatVersion.equals("2.0")) {
LOG.debug("Detected v2 file."); LOG.debug("Detected v2 file.");
project = parseV2File(doc.getDocumentElement()); project = parseV2File(doc.getDocumentElement());
@@ -98,6 +100,7 @@ public class ProjectFileManager {
throw new IllegalArgumentException("Unknown file format version: " + formatVersion); throw new IllegalArgumentException("Unknown file format version: " + formatVersion);
} }
} }
Collections.sort(warnings);
this.currentFileName = fileName; this.currentFileName = fileName;
this.modified = false; this.modified = false;
return project; return project;
@@ -121,7 +124,7 @@ public class ProjectFileManager {
isModified()); isModified());
} }
private Project parseV1File(Element root) { private Project parseV1File(Element root, List<String> warnings) {
Project project = new Project(); Project project = new Project();
project.setTitle(root.getAttribute("Project")); project.setTitle(root.getAttribute("Project"));
project.setAuthor(root.getAttribute("Credits")); project.setAuthor(root.getAttribute("Credits"));
@@ -254,7 +257,11 @@ public class ProjectFileManager {
ic.setValue(valueAttr); ic.setValue(valueAttr);
component = ic; component = ic;
} else { } else {
LOG.debug("Could not recognize component type " + nodeName); String message = "Could not recognize component type " + nodeName;
LOG.debug(message);
if (!warnings.contains(message)) {
warnings.add(message);
}
} }
if (component != null) { if (component != null) {
project.getComponents().add(component); project.getComponents().add(component);