parent
316c0dda76
commit
c40967f972
@ -0,0 +1,99 @@
|
||||
package seng302.Controllers.Mock;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
*/
|
||||
public class Regatta {
|
||||
int regattaID;
|
||||
String RegattaName;
|
||||
int raceID = 0;
|
||||
String courseName;
|
||||
double centralLatitude;
|
||||
double centralLongitude;
|
||||
double centralAltitude;
|
||||
float utcOffset;
|
||||
float magneticVariation;
|
||||
|
||||
public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) {
|
||||
this.regattaID = regattaID;
|
||||
this.RegattaName = regattaName;
|
||||
this.courseName = courseName;
|
||||
this.centralLatitude = centralLatitude;
|
||||
this.centralLongitude = centralLongitude;
|
||||
this.centralAltitude = centralAltitude;
|
||||
this.utcOffset = utcOffset;
|
||||
this.magneticVariation = magneticVariation;
|
||||
}
|
||||
|
||||
public int getRegattaID() {
|
||||
return regattaID;
|
||||
}
|
||||
|
||||
public void setRegattaID(int ID) {
|
||||
this.regattaID = ID;
|
||||
}
|
||||
|
||||
public String getRegattaName() {
|
||||
return RegattaName;
|
||||
}
|
||||
|
||||
public void setRegattaName(String regattaName) {
|
||||
RegattaName = regattaName;
|
||||
}
|
||||
|
||||
public int getRaceID() {
|
||||
return raceID;
|
||||
}
|
||||
|
||||
public void setRaceID(int raceID) {
|
||||
this.raceID = raceID;
|
||||
}
|
||||
|
||||
public String getCourseName() {
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public void setCourseName(String courseName) {
|
||||
this.courseName = courseName;
|
||||
}
|
||||
|
||||
public double getCentralLatitude() {
|
||||
return centralLatitude;
|
||||
}
|
||||
|
||||
public void setCentralLatitude(double centralLatitude) {
|
||||
this.centralLatitude = centralLatitude;
|
||||
}
|
||||
|
||||
public double getCentralLongitude() {
|
||||
return centralLongitude;
|
||||
}
|
||||
|
||||
public void setCentralLongitude(double centralLongitude) {
|
||||
this.centralLongitude = centralLongitude;
|
||||
}
|
||||
|
||||
public double getCentralAltitude() {
|
||||
return centralAltitude;
|
||||
}
|
||||
|
||||
public void setCentralAltitude(double centralAltitude) {
|
||||
this.centralAltitude = centralAltitude;
|
||||
}
|
||||
|
||||
public float getUtcOffset() {
|
||||
return utcOffset;
|
||||
}
|
||||
|
||||
public void setUtcOffset(float utcOffset) {
|
||||
this.utcOffset = utcOffset;
|
||||
}
|
||||
|
||||
public float getMagneticVariation() {
|
||||
return magneticVariation;
|
||||
}
|
||||
|
||||
public void setMagneticVariation(float magneticVariation) {
|
||||
this.magneticVariation = magneticVariation;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package seng302.Controllers.Mock;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
*/
|
||||
public class RegattaXMLReader extends XMLReader {
|
||||
private Regatta regatta;
|
||||
|
||||
/**
|
||||
* Constructor for Regatta XML
|
||||
* @param filePath path of the file
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public RegattaXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException {
|
||||
this(filePath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Regatta XML
|
||||
* @param filePath file path to read
|
||||
* @param read whether or not to read and store the files straight away.
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public RegattaXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException {
|
||||
super(filePath);
|
||||
if (read) {
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the XML
|
||||
*/
|
||||
private void read() {
|
||||
NodeList attributeConfig = doc.getElementsByTagName("RegattaConfig");
|
||||
Element attributes = (Element) attributeConfig.item(0);
|
||||
makeRegatta(attributes);
|
||||
}
|
||||
|
||||
private void makeRegatta(Element attributes) {
|
||||
int regattaID = Integer.parseInt(getTextValueOfNode(attributes, "RegattaID"));
|
||||
String regattaName = getTextValueOfNode(attributes, "RegattaName");
|
||||
String courseName = getTextValueOfNode(attributes, "CourseName");
|
||||
double centralLatitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralLatitude"));
|
||||
double centralLongitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralLongitude"));
|
||||
double centralAltitude = Double.parseDouble(getTextValueOfNode(attributes, "CentralAltitude"));
|
||||
float utcOffset = Float.parseFloat(getTextValueOfNode(attributes, "UtcOffset"));
|
||||
float magneticVariation = Float.parseFloat(getTextValueOfNode(attributes, "MagneticVariation"));
|
||||
|
||||
regatta = new Regatta(regattaID, regattaName, courseName, centralLatitude, centralLongitude, centralAltitude, utcOffset, magneticVariation);
|
||||
}
|
||||
|
||||
public Regatta getRegatta() {
|
||||
return regatta;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Controllers.Mock.RegattaXMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
*/
|
||||
public class RegattaXMLTest {
|
||||
RegattaXMLReader regattaXMLReader;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RegattaConfig>
|
||||
|
||||
<RegattaID>3</RegattaID>
|
||||
|
||||
<RegattaName>New Zealand Test</RegattaName>
|
||||
|
||||
<CourseName>North Head</CourseName>
|
||||
|
||||
<CentralLatitude>-36.82791529</CentralLatitude>
|
||||
|
||||
<CentralLongitude>174.81218919</CentralLongitude>
|
||||
|
||||
<CentralAltitude>0.00</CentralAltitude>
|
||||
|
||||
<UtcOffset>12</UtcOffset>
|
||||
|
||||
<MagneticVariation>14.1</MagneticVariation>
|
||||
|
||||
</RegattaConfig>
|
||||
Loading…
Reference in new issue