|
|
|
@ -10,9 +10,10 @@
|
|
|
|
* For any reuse or distribution, you must make clear to others the
|
|
|
|
* For any reuse or distribution, you must make clear to others the
|
|
|
|
* license terms of this work.
|
|
|
|
* license terms of this work.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package com.moviejukebox.themoviedb.tools;
|
|
|
|
package com.moviejukebox.themoviedb.tools;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
@ -30,10 +31,134 @@ import com.moviejukebox.themoviedb.model.Person;
|
|
|
|
import com.moviejukebox.themoviedb.model.Studio;
|
|
|
|
import com.moviejukebox.themoviedb.model.Studio;
|
|
|
|
|
|
|
|
|
|
|
|
public class DOMParser {
|
|
|
|
public class DOMParser {
|
|
|
|
|
|
|
|
|
|
|
|
static Logger logger = TheMovieDb.getLogger();
|
|
|
|
static Logger logger = TheMovieDb.getLogger();
|
|
|
|
|
|
|
|
|
|
|
|
public static MovieDB parseMovieInfo(Element movieElement) {
|
|
|
|
/**
|
|
|
|
// Inspired by http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
|
|
|
|
* Returns a list of MovieDB object parsed from the DOM Document
|
|
|
|
|
|
|
|
* even if there is only one movie
|
|
|
|
|
|
|
|
* @param doc DOM Document
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static List<MovieDB> parseMovies(Document doc) {
|
|
|
|
|
|
|
|
List<MovieDB> movies = new ArrayList<MovieDB>();
|
|
|
|
|
|
|
|
NodeList nlMovies = doc.getElementsByTagName("movie");
|
|
|
|
|
|
|
|
if ((nlMovies == null) || nlMovies.getLength() == 0) {
|
|
|
|
|
|
|
|
return movies;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MovieDB movie = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nlMovies.getLength(); i++) {
|
|
|
|
|
|
|
|
Node movieNode = nlMovies.item(i);
|
|
|
|
|
|
|
|
if (movieNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element movieElement = (Element) movieNode;
|
|
|
|
|
|
|
|
movie = DOMParser.parseMovieInfo(movieElement);
|
|
|
|
|
|
|
|
if (movie != null) {
|
|
|
|
|
|
|
|
movies.add(movie);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return movies;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the first MovieDB from the DOM Document.
|
|
|
|
|
|
|
|
* @param doc a DOM Document
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static MovieDB parseMovie(Document doc) {
|
|
|
|
|
|
|
|
MovieDB movie = new MovieDB();
|
|
|
|
|
|
|
|
NodeList nlMovies = doc.getElementsByTagName("movie");
|
|
|
|
|
|
|
|
if ((nlMovies == null) || nlMovies.getLength() == 0) {
|
|
|
|
|
|
|
|
return movie;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Node nMovie = nlMovies.item(0);
|
|
|
|
|
|
|
|
if (nMovie.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element eMovie = (Element) nMovie;
|
|
|
|
|
|
|
|
movie = DOMParser.parseMovieInfo(eMovie);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return movie;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Person parsePersonInfo(Document doc) {
|
|
|
|
|
|
|
|
Person person = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
person = new Person();
|
|
|
|
|
|
|
|
NodeList personNodeList = doc.getElementsByTagName("person");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only get the first movie from the list
|
|
|
|
|
|
|
|
Node personNode = personNodeList.item(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (personNode == null) {
|
|
|
|
|
|
|
|
logger.finest("Person not found");
|
|
|
|
|
|
|
|
return person;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (personNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element personElement = (Element) personNode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
person.setName(DOMHelper.getValueFromElement(personElement, "name"));
|
|
|
|
|
|
|
|
person.setId(DOMHelper.getValueFromElement(personElement, "id"));
|
|
|
|
|
|
|
|
person.setBiography(DOMHelper.getValueFromElement(personElement, "biography"));
|
|
|
|
|
|
|
|
person.setKnownMovies(Integer.parseInt(DOMHelper.getValueFromElement(personElement, "known_movies")));
|
|
|
|
|
|
|
|
person.setBirthday(DOMHelper.getValueFromElement(personElement, "birthday"));
|
|
|
|
|
|
|
|
person.setBirthPlace(DOMHelper.getValueFromElement(personElement, "birthplace"));
|
|
|
|
|
|
|
|
person.setUrl(DOMHelper.getValueFromElement(personElement, "url"));
|
|
|
|
|
|
|
|
person.setVersion(Integer.parseInt(DOMHelper.getValueFromElement(personElement, "version")));
|
|
|
|
|
|
|
|
person.setLastModifiedAt(DOMHelper.getValueFromElement(personElement, "last_modified_at"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NodeList artworkNodeList = doc.getElementsByTagName("image");
|
|
|
|
|
|
|
|
for (int nodeLoop = 0; nodeLoop < artworkNodeList.getLength(); nodeLoop++) {
|
|
|
|
|
|
|
|
Node artworkNode = artworkNodeList.item(nodeLoop);
|
|
|
|
|
|
|
|
if (artworkNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element artworkElement = (Element) artworkNode;
|
|
|
|
|
|
|
|
Artwork artwork = new Artwork();
|
|
|
|
|
|
|
|
artwork.setType(artworkElement.getAttribute("type"));
|
|
|
|
|
|
|
|
artwork.setUrl(artworkElement.getAttribute("url"));
|
|
|
|
|
|
|
|
artwork.setSize(artworkElement.getAttribute("size"));
|
|
|
|
|
|
|
|
artwork.setId(artworkElement.getAttribute("id"));
|
|
|
|
|
|
|
|
person.addArtwork(artwork);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NodeList filmNodeList = doc.getElementsByTagName("movie");
|
|
|
|
|
|
|
|
for (int nodeLoop = 0; nodeLoop < filmNodeList.getLength(); nodeLoop++) {
|
|
|
|
|
|
|
|
Node filmNode = filmNodeList.item(nodeLoop);
|
|
|
|
|
|
|
|
if (filmNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element filmElement = (Element) filmNode;
|
|
|
|
|
|
|
|
Filmography film = new Filmography();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
film.setCharacter(filmElement.getAttribute("character"));
|
|
|
|
|
|
|
|
film.setDepartment(filmElement.getAttribute("department"));
|
|
|
|
|
|
|
|
film.setId(filmElement.getAttribute("id"));
|
|
|
|
|
|
|
|
film.setJob(filmElement.getAttribute("job"));
|
|
|
|
|
|
|
|
film.setName(filmElement.getAttribute("name"));
|
|
|
|
|
|
|
|
film.setUrl(filmElement.getAttribute("url"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
person.addFilm(film);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception error) {
|
|
|
|
|
|
|
|
logger.severe("ERROR: " + error.getMessage());
|
|
|
|
|
|
|
|
error.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return person;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Person parsePersonGetVersion(Document doc) {
|
|
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static MovieDB parseMovieInfo(Element movieElement) {
|
|
|
|
|
|
|
|
// Inspired by
|
|
|
|
|
|
|
|
// http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
|
|
|
|
MovieDB movie = new MovieDB();
|
|
|
|
MovieDB movie = new MovieDB();
|
|
|
|
NodeList subNodeList;
|
|
|
|
NodeList subNodeList;
|
|
|
|
Node subNode;
|
|
|
|
Node subNode;
|
|
|
|
@ -215,8 +340,8 @@ public class DOMParser {
|
|
|
|
artwork.setUrl(subElement.getAttribute("url"));
|
|
|
|
artwork.setUrl(subElement.getAttribute("url"));
|
|
|
|
artwork.setId(subElement.getAttribute("id"));
|
|
|
|
artwork.setId(subElement.getAttribute("id"));
|
|
|
|
movie.addArtwork(artwork);
|
|
|
|
movie.addArtwork(artwork);
|
|
|
|
} else if (subElement.getNodeName().equalsIgnoreCase("backdrop") ||
|
|
|
|
} else if (subElement.getNodeName().equalsIgnoreCase("backdrop")
|
|
|
|
subElement.getNodeName().equalsIgnoreCase("poster")) {
|
|
|
|
|| subElement.getNodeName().equalsIgnoreCase("poster")) {
|
|
|
|
// This is the format used in Movie.getImages
|
|
|
|
// This is the format used in Movie.getImages
|
|
|
|
String artworkId = subElement.getAttribute("id");
|
|
|
|
String artworkId = subElement.getAttribute("id");
|
|
|
|
String artworkType = subElement.getNodeName();
|
|
|
|
String artworkType = subElement.getNodeName();
|
|
|
|
@ -249,77 +374,4 @@ public class DOMParser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return movie;
|
|
|
|
return movie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Person parsePersonInfo(Document doc) {
|
|
|
|
|
|
|
|
Person person = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
person = new Person();
|
|
|
|
|
|
|
|
NodeList personNodeList = doc.getElementsByTagName("person");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only get the first movie from the list
|
|
|
|
|
|
|
|
Node personNode = personNodeList.item(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (personNode == null) {
|
|
|
|
|
|
|
|
logger.finest("Person not found");
|
|
|
|
|
|
|
|
return person;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (personNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element personElement = (Element) personNode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
person.setName(DOMHelper.getValueFromElement(personElement, "name"));
|
|
|
|
|
|
|
|
person.setId(DOMHelper.getValueFromElement(personElement, "id"));
|
|
|
|
|
|
|
|
person.setBiography(DOMHelper.getValueFromElement(personElement, "biography"));
|
|
|
|
|
|
|
|
person.setKnownMovies(Integer.parseInt(DOMHelper.getValueFromElement(personElement, "known_movies")));
|
|
|
|
|
|
|
|
person.setBirthday(DOMHelper.getValueFromElement(personElement, "birthday"));
|
|
|
|
|
|
|
|
person.setBirthPlace(DOMHelper.getValueFromElement(personElement, "birthplace"));
|
|
|
|
|
|
|
|
person.setUrl(DOMHelper.getValueFromElement(personElement, "url"));
|
|
|
|
|
|
|
|
person.setVersion(Integer.parseInt(DOMHelper.getValueFromElement(personElement, "version")));
|
|
|
|
|
|
|
|
person.setLastModifiedAt(DOMHelper.getValueFromElement(personElement, "last_modified_at"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NodeList artworkNodeList = doc.getElementsByTagName("image");
|
|
|
|
|
|
|
|
for (int nodeLoop = 0; nodeLoop < artworkNodeList.getLength(); nodeLoop++) {
|
|
|
|
|
|
|
|
Node artworkNode = artworkNodeList.item(nodeLoop);
|
|
|
|
|
|
|
|
if (artworkNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element artworkElement = (Element) artworkNode;
|
|
|
|
|
|
|
|
Artwork artwork = new Artwork();
|
|
|
|
|
|
|
|
artwork.setType(artworkElement.getAttribute("type"));
|
|
|
|
|
|
|
|
artwork.setUrl(artworkElement.getAttribute("url"));
|
|
|
|
|
|
|
|
artwork.setSize(artworkElement.getAttribute("size"));
|
|
|
|
|
|
|
|
artwork.setId(artworkElement.getAttribute("id"));
|
|
|
|
|
|
|
|
person.addArtwork(artwork);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NodeList filmNodeList = doc.getElementsByTagName("movie");
|
|
|
|
|
|
|
|
for (int nodeLoop = 0; nodeLoop < filmNodeList.getLength(); nodeLoop++) {
|
|
|
|
|
|
|
|
Node filmNode = filmNodeList.item(nodeLoop);
|
|
|
|
|
|
|
|
if (filmNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
|
|
|
|
|
Element filmElement = (Element) filmNode;
|
|
|
|
|
|
|
|
Filmography film = new Filmography();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
film.setCharacter(filmElement.getAttribute("character"));
|
|
|
|
|
|
|
|
film.setDepartment(filmElement.getAttribute("department"));
|
|
|
|
|
|
|
|
film.setId(filmElement.getAttribute("id"));
|
|
|
|
|
|
|
|
film.setJob(filmElement.getAttribute("job"));
|
|
|
|
|
|
|
|
film.setName(filmElement.getAttribute("name"));
|
|
|
|
|
|
|
|
film.setUrl(filmElement.getAttribute("url"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
person.addFilm(film);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception error) {
|
|
|
|
|
|
|
|
logger.severe("ERROR: " + error.getMessage());
|
|
|
|
|
|
|
|
error.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return person;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Person parsePersonGetVersion(Document doc) {
|
|
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|