@ -26,6 +26,7 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator ;
import javax.xml.validation.Validator ;
import java.io.File ;
import java.io.File ;
import java.io.IOException ;
import java.io.IOException ;
import java.io.InputStream ;
import java.io.StringWriter ;
import java.io.StringWriter ;
import java.math.BigInteger ;
import java.math.BigInteger ;
import java.net.URL ;
import java.net.URL ;
@ -64,21 +65,21 @@ public class RaceXMLCreator {
/ * *
/ * *
* Rotates the race in a specified direction .
* Rotates the race in a specified direction .
* @param s xml file name
* @param s xml file name or contents .
* @param fileType Whether s is a file name or contents .
* @param degrees degrees to rotate
* @param degrees degrees to rotate
* @return the new xml file as a string
* @return the new xml file as a string
* @throws XMLReaderException if the xml is not readable
* @throws XMLReaderException if the xml is not readable
* @throws InvalidRaceDataException if the race is invalid
* @throws InvalidRaceDataException if the race is invalid
* @throws JAXBException if the Race class cannot be parsed into a xml .
* @throws IOException if the schema file cannot be found
* @throws SAXException error in schema file
* @throws ParserConfigurationException error in parsing the schema file
* /
* /
public static String alterRaceToWind ( String s , double degrees ) throws XMLReaderException , InvalidRaceDataException , JAXBException , IOException , SAXException , ParserConfigurationException {
public static String alterRaceToWind ( String s , XMLFileType fileType , double degrees ) throws XMLReaderException , InvalidRaceDataException {
RaceXMLReader reader = new RaceXMLReader ( s , XMLFileType . ResourcePath ) ;
RaceXMLReader reader = new RaceXMLReader ( s , fileType ) ;
try {
XMLRace race = XMLUtilities . xmlToClass (
XMLRace race = XMLUtilities . xmlToClass (
RaceXMLCreator . class . getClassLoader ( ) . getResourceAsStream ( s ) ,
s,
RaceXMLCreator . class . getClassLoader ( ) . getResource ( "mock/mockXML/schema/raceSchema.xsd" ) ,
RaceXMLCreator . class . getClassLoader ( ) . getResource ( "mock/mockXML/schema/raceSchema.xsd" ) ,
XMLRace . class ) ;
XMLRace . class ) ;
@ -91,6 +92,10 @@ public class RaceXMLCreator {
alterRaceRotation ( race , degreesToRotate ) ;
alterRaceRotation ( race , degreesToRotate ) ;
return XMLUtilities . classToXML ( race ) ;
return XMLUtilities . classToXML ( race ) ;
} catch ( ParserConfigurationException | IOException | SAXException | JAXBException e ) {
throw new InvalidRaceDataException ( "Could not parse or marshall race data file." , e ) ;
}
}
}
/ * *
/ * *