Switch to side-by-side view

--- a/src/main/java/net/timbusproject/dpes/alternative/kb/VirtualPackageAlternativeIdentifier.java
+++ b/src/main/java/net/timbusproject/dpes/alternative/kb/VirtualPackageAlternativeIdentifier.java
@@ -33,7 +33,6 @@
 import java.util.Map.Entry;
 import java.util.Scanner;
 import java.util.Set;
-import java.util.zip.GZIPOutputStream;
 
 import org.apache.commons.cli.BasicParser;
 import org.apache.commons.cli.CommandLine;
@@ -62,10 +61,12 @@
 
 import uk.ac.manchester.cs.owl.owlapi.OWLOntologyImpl;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
+/**
+ * @author Rudolf Mayer
+ */
 public class VirtualPackageAlternativeIdentifier {
+    public static final String PATH_KNOWDLEDGE_BASE = "knowledgeBases:softwareAlternatives:".replace(':', File.separatorChar);
+
     public static final IRI IRI_CUDF = IRI.create("http://timbus.teco.edu/ontologies/DSOs/CUDF.owl");
 
     public static final IRI IRI_CUDF_PACKAGE = IRI.create(IRI_CUDF.toString() + "#Package");
@@ -83,10 +84,6 @@
 
     public static final OWLObjectProperty OBJECTPROPERTY_CUDF_PROVIDES = OWLManager.getOWLDataFactory().getOWLObjectProperty(
             IRI.create(IRI_CUDF.toString() + "#", "provides"));
-
-    private static final XStream xStream = new XStream(new DomDriver());
-
-    private static final String PATH = "knowledgeBases:softwareAlternatives:".replace(':', File.separatorChar);
 
     private static final String completeOntologyKey = "complete";
 
@@ -217,7 +214,7 @@
         String osName = OSIdentifier.getEscapedOSString();
 
         // convert to all subsets to one single XML
-        writeAsXML(packagesProviders, "providers-" + osName, false);
+        SerialisationUtils.writeAsXML(packagesProviders, PATH_KNOWDLEDGE_BASE, "providers-" + osName, false);
 
         // One Excel sheet that will contain all sub-sections
         Workbook wb = new XSSFWorkbook();
@@ -227,26 +224,12 @@
             storeSectionResult(providers, "providers-" + osName + "-" + key);
         }
         try {
-            FileOutputStream fos = new FileOutputStream(PATH + "providers-" + osName + ".xlsx");
+            FileOutputStream fos = new FileOutputStream(PATH_KNOWDLEDGE_BASE + "providers-" + osName + ".xlsx");
             wb.write(fos);
             fos.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
-    }
-
-    public static File writeAsXML(Object data, String fileName, boolean gzip) throws IOException {
-        String xml = xStream.toXML(data);
-        final File file = new File(PATH + fileName + ".xml");
-        PrintWriter pw;
-        if (gzip) {
-            pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(file)));
-        } else {
-            pw = new PrintWriter(file);
-        }
-        pw.println(xml);
-        pw.close();
-        return file;
     }
 
     public void storeSectionResult(final Map<String, Set<String>> providers, String sheetName, Workbook wb)
@@ -271,7 +254,7 @@
         PrintWriter xmlOutput = new PrintWriter(fileName + ".xml");
 
         // convert to XML
-        String xml = xStream.toXML(providers);
+        String xml = SerialisationUtils.convertToXML(providers);
         xmlOutput.println(xml);
 
         System.out.println("\nResults:\n");
@@ -401,8 +384,7 @@
                 // initialise the member variable
                 String providersFileName = cmd.getOptionValue("providers");
                 System.out.println("Trying to load package providers from XML " + providersFileName);
-                packagesProviders = (HashMap<String, HashMap<String, Set<String>>>) xStream.fromXML(new File(
-                        providersFileName));
+                packagesProviders = (HashMap<String, HashMap<String, Set<String>>>) SerialisationUtils.readFromXMLFile(providersFileName);
                 System.out.println("\tDone!");
             }
         } catch (ParseException e) {
@@ -425,7 +407,7 @@
         for (Entry<String, OWLOntologyImpl> entry : ontologies.entrySet()) {
             OWLOntologyImpl ontology = entry.getValue();
             String subPath = entry.getKey().equals(completeOntologyKey) ? "" : "subSections" + File.separatorChar;
-            File file = new File(PATH + subPath + "providers-" + operatingSystemName + "-" + entry.getKey() + ".owl");
+            File file = new File(PATH_KNOWDLEDGE_BASE + subPath + "providers-" + operatingSystemName + "-" + entry.getKey() + ".owl");
             FileDocumentTarget fileDocumentTarget = new FileDocumentTarget(file);
             try {
                 OWLManager.createOWLOntologyManager().saveOntology(ontology, new OWLXMLOntologyFormat(),