|
|
|
|
@ -3,7 +3,6 @@ package seng302.Data;
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
|
import seng302.Exceptions.InvalidRegattaDataException;
|
|
|
|
|
import seng302.Mock.Regatta;
|
|
|
|
|
import seng302.Mock.RegattaDataSource;
|
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
|
@ -23,7 +22,8 @@ public class RegattaData {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RegattaDataSource regattaDataSource;
|
|
|
|
|
|
|
|
|
|
private Document doc;
|
|
|
|
|
private Element rootElement;
|
|
|
|
|
|
|
|
|
|
public RegattaData(RegattaDataSource regattaDataSource) {
|
|
|
|
|
this.regattaDataSource = regattaDataSource;
|
|
|
|
|
@ -31,57 +31,16 @@ public class RegattaData {
|
|
|
|
|
|
|
|
|
|
public String createXML() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Regatta regatta = regattaDataSource.getRegatta();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
|
|
|
|
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
|
|
|
|
|
|
|
|
|
//root element
|
|
|
|
|
Document doc = docBuilder.newDocument();
|
|
|
|
|
Element rootElement = doc.createElement("RegattaConfig");
|
|
|
|
|
doc = docBuilder.newDocument();
|
|
|
|
|
rootElement = doc.createElement("RegattaConfig");
|
|
|
|
|
doc.appendChild(rootElement);
|
|
|
|
|
|
|
|
|
|
//regattaID element
|
|
|
|
|
Element regattaID = doc.createElement("RegattaID");
|
|
|
|
|
regattaID.appendChild(doc.createTextNode(Integer.toString(regatta.getRegattaID())));
|
|
|
|
|
rootElement.appendChild(regattaID);
|
|
|
|
|
|
|
|
|
|
//regattaName element
|
|
|
|
|
Element regattaName = doc.createElement("RegattaName");
|
|
|
|
|
regattaName.appendChild(doc.createTextNode(regatta.getRegattaName()));
|
|
|
|
|
rootElement.appendChild(regattaName);
|
|
|
|
|
|
|
|
|
|
//courseName element
|
|
|
|
|
Element courseName = doc.createElement("CourseName");
|
|
|
|
|
courseName.appendChild(doc.createTextNode(regatta.getCourseName()));
|
|
|
|
|
rootElement.appendChild(courseName);
|
|
|
|
|
|
|
|
|
|
//centralLatitude element
|
|
|
|
|
Element centralLat = doc.createElement("CentralLatitude");
|
|
|
|
|
centralLat.appendChild(doc.createTextNode(Double.toString(regatta.getCentralLatitude())));
|
|
|
|
|
rootElement.appendChild(centralLat);
|
|
|
|
|
|
|
|
|
|
//centralLongitude element
|
|
|
|
|
Element centralLong = doc.createElement("CentralLongitude");
|
|
|
|
|
centralLong.appendChild(doc.createTextNode(Double.toString(regatta.getCentralLongitude())));
|
|
|
|
|
rootElement.appendChild(centralLong);
|
|
|
|
|
|
|
|
|
|
//centralAltitude element
|
|
|
|
|
Element centralAlt = doc.createElement("CentralAltitude");
|
|
|
|
|
centralAlt.appendChild(doc.createTextNode(Double.toString(regatta.getCentralAltitude())));
|
|
|
|
|
rootElement.appendChild(centralAlt);
|
|
|
|
|
|
|
|
|
|
//utcOffset element
|
|
|
|
|
Element utcOffset = doc.createElement("UtcOffset");
|
|
|
|
|
utcOffset.appendChild(doc.createTextNode(Double.toString(regatta.getUtcOffset())));
|
|
|
|
|
rootElement.appendChild(utcOffset);
|
|
|
|
|
|
|
|
|
|
//magneticVariation element
|
|
|
|
|
Element magneticVariation = doc.createElement("MagneticVariation");
|
|
|
|
|
magneticVariation.appendChild(doc.createTextNode(Double.toString(regatta.getMagneticVariation())));
|
|
|
|
|
rootElement.appendChild(magneticVariation);
|
|
|
|
|
appendChildElements();
|
|
|
|
|
|
|
|
|
|
// write the content into xml file
|
|
|
|
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
|
|
|
|
@ -103,4 +62,74 @@ public class RegattaData {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void appendRegattaID() {
|
|
|
|
|
//regattaID element
|
|
|
|
|
Element regattaID = doc.createElement("RegattaID");
|
|
|
|
|
regattaID.appendChild(doc.createTextNode(Integer.toString(regattaDataSource.getRegatta().getRegattaID())));
|
|
|
|
|
rootElement.appendChild(regattaID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendRegattaName() {
|
|
|
|
|
//regattaName element
|
|
|
|
|
Element regattaName = doc.createElement("RegattaName");
|
|
|
|
|
regattaName.appendChild(doc.createTextNode(regattaDataSource.getRegatta().getRegattaName()));
|
|
|
|
|
rootElement.appendChild(regattaName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendCourseName() {
|
|
|
|
|
//courseName element
|
|
|
|
|
Element courseName = doc.createElement("CourseName");
|
|
|
|
|
courseName.appendChild(doc.createTextNode(regattaDataSource.getRegatta().getCourseName()));
|
|
|
|
|
rootElement.appendChild(courseName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendCentralLatitude() {
|
|
|
|
|
//centralLatitude element
|
|
|
|
|
Element centralLat = doc.createElement("CentralLatitude");
|
|
|
|
|
centralLat.appendChild(doc.createTextNode(Double.toString(regattaDataSource.getRegatta().getCentralLatitude())));
|
|
|
|
|
rootElement.appendChild(centralLat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendCentralLongitude() {
|
|
|
|
|
//centralLongitude element
|
|
|
|
|
Element centralLong = doc.createElement("CentralLongitude");
|
|
|
|
|
centralLong.appendChild(doc.createTextNode(Double.toString(regattaDataSource.getRegatta().getCentralLongitude())));
|
|
|
|
|
rootElement.appendChild(centralLong);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendCentralAltitude() {
|
|
|
|
|
//centralAltitude element
|
|
|
|
|
Element centralAlt = doc.createElement("CentralAltitude");
|
|
|
|
|
centralAlt.appendChild(doc.createTextNode(Double.toString(regattaDataSource.getRegatta().getCentralAltitude())));
|
|
|
|
|
rootElement.appendChild(centralAlt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appedUtcOffset() {
|
|
|
|
|
//utcOffset element
|
|
|
|
|
Element utcOffset = doc.createElement("UtcOffset");
|
|
|
|
|
utcOffset.appendChild(doc.createTextNode(Double.toString(regattaDataSource.getRegatta().getUtcOffset())));
|
|
|
|
|
rootElement.appendChild(utcOffset);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendMagneticVariation() {
|
|
|
|
|
//magneticVariation element
|
|
|
|
|
Element magneticVariation = doc.createElement("MagneticVariation");
|
|
|
|
|
magneticVariation.appendChild(doc.createTextNode(Double.toString(regattaDataSource.getRegatta().getMagneticVariation())));
|
|
|
|
|
rootElement.appendChild(magneticVariation);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void appendChildElements() {
|
|
|
|
|
appendRegattaID();
|
|
|
|
|
appendRegattaName();
|
|
|
|
|
appendCourseName();
|
|
|
|
|
appendCentralLatitude();
|
|
|
|
|
appendCentralLongitude();
|
|
|
|
|
appendCentralAltitude();
|
|
|
|
|
appedUtcOffset();
|
|
|
|
|
appendMagneticVariation();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|