Refactored RegattaData
#story[778]
This commit is contained in:
@@ -6,7 +6,6 @@ import javafx.stage.Stage;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Mock.RaceDataSource;
|
||||
import seng302.Mock.RegattaDataSource;
|
||||
import seng302.Mock.RegattaXMLReader;
|
||||
import seng302.Model.Event;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import seng302.Model.Regatta;
|
||||
|
||||
/**
|
||||
* Created by zwu18 on 25/04/17.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package seng302.Mock;
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
package seng302.Mock;
|
||||
package seng302;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Mock.RegattaDataSource;
|
||||
import seng302.Model.Regatta;
|
||||
import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
Reference in New Issue
Block a user