You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.5 KiB
75 lines
2.5 KiB
package mock.app;
|
|
|
|
|
|
import javafx.application.Application;
|
|
import javafx.stage.Stage;
|
|
import mock.dataInput.PolarParser;
|
|
import mock.model.Polars;
|
|
import org.w3c.dom.Document;
|
|
import org.xml.sax.InputSource;
|
|
import org.xml.sax.SAXException;
|
|
import shared.dataInput.XMLReader;
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
import javax.xml.transform.TransformerException;
|
|
import java.io.IOException;
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
public class App extends Application {
|
|
|
|
/**
|
|
* Entry point for running the programme
|
|
*
|
|
* @param args for starting the programme
|
|
*/
|
|
public static void main(String[] args) {
|
|
launch(args);
|
|
}
|
|
|
|
@Override
|
|
public void start(Stage primaryStage) {
|
|
try {
|
|
Polars boatPolars = PolarParser.parse("polars/acc_polars.csv");
|
|
|
|
String regattaXML = readFile("mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
|
String raceXML = readFile("mockXML/raceTest.xml", StandardCharsets.UTF_8);
|
|
String boatXML = readFile("mockXML/boatTest.xml", StandardCharsets.UTF_8);
|
|
|
|
Event raceEvent = new Event(raceXML, regattaXML, boatXML, boatPolars);
|
|
raceEvent.start();
|
|
|
|
} catch (Exception e) {
|
|
//Catch all exceptions, print, and exit.
|
|
e.printStackTrace();
|
|
System.exit(1);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reads the Initial Race XML files that are necessary to run the mock.
|
|
* @param path path of the XML
|
|
* @param encoding encoding of the xml
|
|
* @return A string containing the contents of the specified file.
|
|
* @throws IOException No file etc
|
|
* @throws ParserConfigurationException Issue with the XML formatting
|
|
* @throws SAXException Issue with XML formatting
|
|
* @throws TransformerException Issue with the XML format
|
|
*/
|
|
private String readFile(String path, Charset encoding) throws IOException, ParserConfigurationException, SAXException, TransformerException {
|
|
|
|
InputSource fXmlFile = new InputSource(getClass().getClassLoader().getResourceAsStream(path));
|
|
|
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
|
Document doc = dBuilder.parse(fXmlFile);
|
|
doc.getDocumentElement().normalize();
|
|
|
|
return XMLReader.getContents(doc);
|
|
|
|
}
|
|
|
|
}
|