implemented personGetVersion in TheMovieDb and parsePersonGetVersion in DOMParser

master
Mohammed Le Doze 15 years ago
parent 4b0bd10156
commit 3c14c62226

@ -31,6 +31,7 @@ import com.moviejukebox.themoviedb.tools.DOMHelper;
import com.moviejukebox.themoviedb.tools.DOMParser; import com.moviejukebox.themoviedb.tools.DOMParser;
import com.moviejukebox.themoviedb.tools.LogFormatter; import com.moviejukebox.themoviedb.tools.LogFormatter;
import com.moviejukebox.themoviedb.tools.WebBrowser; import com.moviejukebox.themoviedb.tools.WebBrowser;
import java.util.Arrays;
/** /**
* This is the main class for the API to connect to TheMovieDb.org The implementation is for v2.1 * This is the main class for the API to connect to TheMovieDb.org The implementation is for v2.1
@ -375,27 +376,50 @@ public class TheMovieDb {
* the current version number of the called object(s). This is useful if you've already * the current version number of the called object(s). This is useful if you've already
* called the object sometime in the past and simply want to do a quick check for updates. * called the object sometime in the past and simply want to do a quick check for updates.
* *
* @param personID * @param personID a Person TMDb id
* @param language * @param language the two digit language code. E.g. en=English
* @return * @return
*/ */
public Person personGetVersion(String personID, String language) { public Person personGetVersion(String personID, String language) {
Person person = new Person();
if (!isValidString(personID)) { if (!isValidString(personID)) {
return person; return new Person();
}
List<Person> people = new ArrayList<Person>();
people = this.personGetVersion(Arrays.asList(personID), language);
return people.get(0);
}
/**
* Retrieve the last modified time along with the current version of a Person.
* @param personIDs one or multiple Person TMDb ids
* @param language the two digit language code. E.g. en=English
* @return
*/
public List<Person> personGetVersion(List<String> personIDs, String language) {
List<Person> people = new ArrayList<Person>();
String ids = "";
for (int i = 0; i < personIDs.size(); i++) {
if (i == 0) {
ids += personIDs.get(i);
continue;
}
ids += "," + personIDs.get(i);
} }
Document doc = null; Document doc = null;
try { try {
String searchUrl = buildSearchUrl(PERSON_GET_VERSION, personID, language); String searchUrl = buildSearchUrl(PERSON_GET_VERSION, ids, language);
doc = DOMHelper.getEventDocFromUrl(searchUrl); doc = DOMHelper.getEventDocFromUrl(searchUrl);
person = DOMParser.parsePersonGetVersion(doc); people = DOMParser.parsePersonGetVersion(doc);
} catch (Exception error) { } catch (Exception error) {
logger.severe("PersonGetVersion error: " + error.getMessage()); logger.severe("PersonGetVersion error: " + error.getMessage());
} }
return person; return people;
} }
/** /**

@ -20,10 +20,12 @@ package com.moviejukebox.themoviedb.model;
*/ */
public class Category { public class Category {
private String type; private static final String UNKNOWN = MovieDB.UNKNOWN;
private String name;
private String url; private String type = UNKNOWN;
private String id; private String name = UNKNOWN;
private String url = UNKNOWN;
private String id = UNKNOWN;
public String getId() { public String getId() {
return id; return id;

@ -20,9 +20,11 @@ package com.moviejukebox.themoviedb.model;
*/ */
public class Country { public class Country {
private String url; private static final String UNKNOWN = MovieDB.UNKNOWN;
private String name;
private String code; private String url = UNKNOWN;
private String name = UNKNOWN;
private String code = UNKNOWN;
public String getUrl() { public String getUrl() {
return url; return url;

@ -14,12 +14,15 @@
package com.moviejukebox.themoviedb.model; package com.moviejukebox.themoviedb.model;
public class Filmography { public class Filmography {
private String url;
private String name; private static final String UNKNOWN = MovieDB.UNKNOWN;
private String department;
private String character; private String url = UNKNOWN;
private String job; private String name = UNKNOWN;
private String id; private String department = UNKNOWN;
private String character = UNKNOWN;
private String job = UNKNOWN;
private String id = UNKNOWN;
public String getUrl() { public String getUrl() {
return url; return url;

@ -20,9 +20,11 @@ package com.moviejukebox.themoviedb.model;
*/ */
public class Studio { public class Studio {
private String name; private static final String UNKNOWN = MovieDB.UNKNOWN;
private String url;
private String id; private String name = UNKNOWN;
private String url = UNKNOWN;
private String id = UNKNOWN;
public String getId() { public String getId() {
return id; return id;

@ -151,11 +151,6 @@ public class DOMParser {
return person; return person;
} }
public static Person parsePersonGetVersion(Document doc) {
// TODO Auto-generated method stub
return null;
}
private static MovieDB parseMovieInfo(Element movieElement) { private static MovieDB parseMovieInfo(Element movieElement) {
// Inspired by // Inspired by
// http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html // http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
@ -375,6 +370,34 @@ public class DOMParser {
return movie; return movie;
} }
/**
* Parse a DOM document and returns a list of Person
* @param doc a DOM document
* @return
*/
public static List<Person> parsePersonGetVersion(Document doc) {
List<Person> people = new ArrayList<Person>();
NodeList movies = doc.getElementsByTagName("movie");
if( (movies == null) || movies.getLength() == 0) {
return people;
}
for (int i= 0; i < movies.getLength(); i++) {
Node node = movies.item(i);
if(node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
Person person = new Person();
person.setName(DOMHelper.getValueFromElement(element, "name"));
person.setId(DOMHelper.getValueFromElement(element, "id"));
person.setVersion(Integer.valueOf(DOMHelper.getValueFromElement(element, "version")));
person.setLastModifiedAt(DOMHelper.getValueFromElement(element, "last_modified_at"));
people.add(person);
}
}
return people;
}
/** /**
* Retrieve a list of valid genres within TMDb. * Retrieve a list of valid genres within TMDb.
* @param doc a DOM document * @param doc a DOM document

Loading…
Cancel
Save