Skip to content

Commit

Permalink
It is now possible to open GZip packed files #37
Browse files Browse the repository at this point in the history
In this commit Issue #37 was solved, this was done by creating a new method which gets the file extension, and with that a seperation between .gz and .xml files is possible.
Howeve im not sure what the "command-line options for direct opening of files" meant, so this could be taken care of later.

Also a new test file was added, the Recon 3D model.
  • Loading branch information
JuliWanner committed Jul 7, 2018
1 parent c78abbe commit 921bfb5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
63 changes: 48 additions & 15 deletions src/main/java/de/sbtab/controller/SBTabController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package de.sbtab.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Objects;
import java.util.Properties;
import java.util.zip.GZIPInputStream;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.sbml.jsbml.SBMLDocument;
Expand All @@ -13,6 +17,7 @@

import javafx.concurrent.Task;


public class SBTabController {

private static final transient Logger LOGGER = LogManager.getLogger(SBTabController.class);
Expand All @@ -22,13 +27,13 @@ public class SBTabController {
public static String getFilePath() {
return filePath;
}

public static SBMLDocument getDoc() {
return doc;
}

/**
* Set Properties for the programm, at the moment only the file path is saved.
* Set Properties for the programm, at the moment only the file path is saved.
*/
public static void setProperties(){
Writer writer = null;
Expand Down Expand Up @@ -84,17 +89,23 @@ public Void call() {
/**
* Read SBML document from a {@link File}.
*
* @param path
* absolute path to {@link SBMLDocument}
* @return
* @param absolute path to {@link SBMLDocument}
* @return {@link SBMLDocument}
*/
public static SBMLDocument read(String filePath) {
Task<Void> task = new Task<Void>() {
@Override
public Void call() {
try {
SBTabController.filePath = filePath;
doc = SBMLReader.read(new File(filePath));
File theSBMLFile = new File(filePath);
System.out.println(getFileExtension(theSBMLFile));
if(Objects.equals(getFileExtension(theSBMLFile), ".xml")){
doc = SBMLReader.read(theSBMLFile);
}
if(Objects.equals(getFileExtension(theSBMLFile), ".gz")){
doc = SBMLReader.read(new GZIPInputStream(new FileInputStream(filePath)));
}
setProperties();
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -118,12 +129,12 @@ public Void call() {
* @return boolean true for valid Document else false plus Logger errors
*/
public static boolean validate(SBMLDocument doc) {
// the number of Errors of a SBMLFile
int numErrors = doc.checkConsistencyOffline();
// the number of Errors of a SBMLFile
int numErrors = doc.checkConsistencyOffline();
if(numErrors == 0) {
return true;
}else {
//get each error and show it
//get each error and show it
for(int i = 0; i < numErrors; i++) {
LOGGER.error(doc.getError(i));
}
Expand All @@ -136,17 +147,39 @@ public static boolean validate(SBMLDocument doc) {
* @return Number of Errors
*/
public static int numErrors(SBMLDocument doc) {
return doc.checkConsistencyOffline();
return doc.checkConsistencyOffline();
}
/**
* Testmethod to get a String-Type Error Code
* @param doc
* @return String-Error
*/
public static String errorToString(SBMLDocument doc) {
int numErrors = doc.checkConsistencyOffline();
String StringError = null;
StringError = doc.getError(0).toString();
return StringError;
int numErrors = doc.checkConsistencyOffline();
String StringError = null;
StringError = doc.getError(0).toString();
return StringError;
}



/**
* @author Julian Wanner
* @param File
* @return File Extension
*/
private static String getFileExtension(File file) {
String theFileExtension = "";
try {
if (file != null && file.exists()) {
String theFileName = file.getName();
theFileExtension = theFileName.substring(theFileName.lastIndexOf("."));
}
} catch (Exception e) {
theFileExtension = "";
}

return theFileExtension;

}
}
2 changes: 1 addition & 1 deletion src/main/java/de/sbtab/view/SBTabMenuController.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private static String chooseFile(){
String filePath = "";
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("XML Files", "*.xml"),
new ExtensionFilter("SBML Files", "*.SBML"));
new ExtensionFilter("GZip Files", "*.gz"));
fileChooser.setTitle("Choose SBML or XML File.");
fileChooser.setInitialDirectory(new File(theProperties.getProperty("FilePath"))) ;
File file = fileChooser.showOpenDialog(null);
Expand Down
Binary file added src/test/resources/Recon3D.xml.gz
Binary file not shown.

0 comments on commit 921bfb5

Please sign in to comment.