diff --git a/MoviesWebApp/src/main/java/at/technikumwien/movies/XmlHelper.java b/MoviesWebApp/src/main/java/at/technikumwien/movies/XmlHelper.java index 0ccf11f..9f5cc9c 100644 --- a/MoviesWebApp/src/main/java/at/technikumwien/movies/XmlHelper.java +++ b/MoviesWebApp/src/main/java/at/technikumwien/movies/XmlHelper.java @@ -1,12 +1,12 @@ package at.technikumwien.movies; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; +import javax.xml.bind.*; +import javax.xml.transform.stream.StreamSource; import java.io.File; import java.util.List; public class XmlHelper { - public static void moviesToXml(MovieList movies,String filename) throws Exception { + public static void moviesToXml(MovieList movies, String filename) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(MovieList.class); Marshaller marshaller = jaxbContext.createMarshaller(); @@ -17,4 +17,18 @@ public class XmlHelper { marshaller.marshal(movies, System.out); marshaller.marshal(movies, new File(filename)); } + + public static List xmlToMovies(String filename) throws JAXBException { + JAXBContext jaxbContext = JAXBContext.newInstance(MovieList.class); + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + StreamSource streamSource = new StreamSource(new File(filename)); + JAXBElement jaxElement = unmarshaller.unmarshal(streamSource, MovieList.class); + + // TODO: Cast here shouldn't be necessary? + MovieList movieList = (MovieList) jaxElement.getValue(); + + return movieList.movies; + } } \ No newline at end of file