Transferring files from my laptop to desktop to work on, may be broken.
This commit is contained in:
@@ -5,6 +5,7 @@ import mock.model.MockRace;
|
||||
import mock.model.Polars;
|
||||
import mock.xml.RaceXMLCreator;
|
||||
import network.Messages.LatestMessages;
|
||||
import org.xml.sax.SAXException;
|
||||
import shared.dataInput.*;
|
||||
import shared.enums.XMLFileType;
|
||||
import shared.exceptions.InvalidBoatDataException;
|
||||
@@ -14,6 +15,7 @@ import shared.exceptions.XMLReaderException;
|
||||
import shared.model.Constants;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import java.io.*;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -44,7 +46,13 @@ public class Event {
|
||||
*/
|
||||
private Event() {
|
||||
try {
|
||||
this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90));
|
||||
try {
|
||||
this.raceXML = getRaceXMLAtCurrentTime(RaceXMLCreator.alterRaceToWind("mock/mockXML/raceSchemaTest.xml", 90));
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(this.raceXML);
|
||||
this.boatXML = XMLReader.readXMLFileToString("mock/mockXML/boatsSinglePlayer.xml", StandardCharsets.UTF_8);
|
||||
this.regattaXML = XMLReader.readXMLFileToString("mock/mockXML/regattaTest.xml", StandardCharsets.UTF_8);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mock.xml;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
import shared.dataInput.RaceXMLReader;
|
||||
import shared.enums.XMLFileType;
|
||||
import shared.exceptions.InvalidRaceDataException;
|
||||
@@ -9,10 +11,24 @@ import shared.model.Corner;
|
||||
import shared.model.GPSCoordinate;
|
||||
import shared.model.Mark;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.util.JAXBSource;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Helper Class for creating a Race XML
|
||||
@@ -138,10 +154,10 @@ public class RaceXMLCreator {
|
||||
* @throws InvalidRaceDataException if the race is invalid
|
||||
* @throws JAXBException if the Race class cannot be parsed into a xml.
|
||||
*/
|
||||
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException {
|
||||
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException, IOException, SAXException, ParserConfigurationException {
|
||||
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
|
||||
|
||||
Race race = copyRace(reader);
|
||||
Race race = readRace(RaceXMLCreator.class.getClassLoader().getResource(s).getFile());
|
||||
|
||||
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
|
||||
|
||||
@@ -246,4 +262,33 @@ public class RaceXMLCreator {
|
||||
return Math.atan2(dy, dx)/Math.PI * 180;
|
||||
}
|
||||
|
||||
public static Race readRace(String file) throws IOException, SAXException, JAXBException, ParserConfigurationException {
|
||||
//validateRace(file);
|
||||
|
||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = parser.parse(new File(file));
|
||||
|
||||
JAXBContext jc = JAXBContext.newInstance(Race.class);
|
||||
Unmarshaller unmarshaller = jc.createUnmarshaller();
|
||||
|
||||
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema;
|
||||
Schema schema = sf.newSchema(schemaURL);
|
||||
unmarshaller.setSchema(schema);
|
||||
|
||||
return (Race) unmarshaller.unmarshal(new DOMSource(document));
|
||||
}
|
||||
|
||||
public static boolean validateRace(String file) throws SAXException, IOException, ParserConfigurationException {
|
||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = parser.parse(new File(file));
|
||||
|
||||
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
URL schemaURL = RaceXMLCreator.class.getClassLoader().getResource("mock/mockXML/schema/raceSchema.xsd");// The URL to your XML Schema;
|
||||
Schema schema = sf.newSchema(schemaURL);
|
||||
Validator validator = schema.newValidator();
|
||||
validator.validate(new DOMSource(document));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user