MovieJukeboxXMLReader { public boolean parsePersonXML(File xmlFile, Person person) { Document xmlDoc; try { xmlDoc = DOMHelper.getDocFromFile(xmlFile); } catch (MalformedURLException error) { LOG.error(ERROR_FIXIT, xmlFile.getName(), "person"); LOG.error(SystemTools.getStackTrace(error)); return Boolean.FALSE; } catch (IOException error) { LOG.error(ERROR_FIXIT, xmlFile.getName(), "person"); LOG.error(SystemTools.getStackTrace(error)); return Boolean.FALSE; } catch (ParserConfigurationException | SAXException error) { LOG.error(ERROR_FIXIT, xmlFile.getName(), "person"); LOG.error(SystemTools.getStackTrace(error)); return Boolean.FALSE; } Node nPeople, nTemp; NodeList nlPeople = xmlDoc.getElementsByTagName("person"); String sTemp; Element eTemp; NodeList nlTemp; for (int looper = 0; looper < nlPeople.getLength(); looper++) { nPeople = nlPeople.item(looper); if (nPeople.getNodeType() == Node.ELEMENT_NODE) { Element ePerson = (Element) nPeople; nlTemp = ePerson.getElementsByTagName("id"); for (int idLoop = 0; idLoop < nlTemp.getLength(); idLoop++) { nTemp = nlTemp.item(idLoop); if (nTemp.getNodeType() == Node.ELEMENT_NODE) { Element eId = (Element) nTemp; String personDatabase = eId.getAttribute("persondb"); if (StringTools.isNotValidString(personDatabase)) { personDatabase = ImdbPlugin.IMDB_PLUGIN_ID; } person.setId(personDatabase, eId.getTextContent()); } } eTemp = DOMHelper.getElementByName(ePerson, "name"); if (eTemp != null) { sTemp = eTemp.getTextContent(); if (StringTools.isNotValidString(person.getName())) { person.setName(sTemp); } else { person.addAka(sTemp); } } person.setTitle(DOMHelper.getValueFromElement(ePerson, "title")); person.setFilename(DOMHelper.getValueFromElement(ePerson, "baseFilename")); person.setBiography(DOMHelper.getValueFromElement(ePerson, "biography")); person.setYear(DOMHelper.getValueFromElement(ePerson, "birthday")); person.setBirthPlace(DOMHelper.getValueFromElement(ePerson, "birthplace")); person.setBirthName(DOMHelper.getValueFromElement(ePerson, "birthname")); person.setUrl(DOMHelper.getValueFromElement(ePerson, "url")); person.setPhotoFilename(DOMHelper.getValueFromElement(ePerson, "photoFile")); person.setPhotoURL(DOMHelper.getValueFromElement(ePerson, "photoURL")); person.setBackdropFilename(DOMHelper.getValueFromElement(ePerson, "backdropFile")); person.setBackdropURL(DOMHelper.getValueFromElement(ePerson, "backdropURL")); person.setKnownMovies(Integer.parseInt(DOMHelper.getValueFromElement(ePerson, "knownMovies"))); person.setVersion(Integer.parseInt(DOMHelper.getValueFromElement(ePerson, "version"))); person.setLastModifiedAt(DOMHelper.getValueFromElement(ePerson, "lastModifiedAt")); nlTemp = ePerson.getElementsByTagName("movie"); for (int movieLoop = 0; movieLoop < nlTemp.getLength(); movieLoop++) { nTemp = nlTemp.item(movieLoop); if (nTemp.getNodeType() == Node.ELEMENT_NODE) { Filmography film = new Filmography(); Element eMovie = (Element) nTemp; film.setId(eMovie.getAttribute("id")); NamedNodeMap nnmAttr = eMovie.getAttributes(); for (int i = 0; i < nnmAttr.getLength(); i++) { Node nAttr = nnmAttr.item(i); String ns = nAttr.getNodeName(); if ("id".equalsIgnoreCase(ns)) { film.setId(nAttr.getTextContent()); continue; } if (ns.toLowerCase().contains(ID)) { person.setId(ns.substring(3), nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(NAME)) { film.setName(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(TITLE)) { film.setTitle(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(ORIGINAL_TITLE)) { film.setOriginalTitle(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(YEAR)) { film.setYear(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(RATING)) { film.setRating(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(CHARACTER)) { film.setCharacter(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(JOB)) { film.setJob(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(DEPARTMENT)) { film.setDepartment(nAttr.getTextContent()); continue; } if (ns.equalsIgnoreCase(URL)) { film.setUrl(nAttr.getTextContent()); } } film.setFilename(eMovie.getTextContent()); film.setDirty(Boolean.FALSE); person.addFilm(film); } } person.setFilename(); person.setDirty(Boolean.FALSE); return Boolean.TRUE; } } return Boolean.FALSE; }  boolean parseMovieXML(File xmlFile, Movie movie); boolean parseSetXML(File xmlSetFile, Movie setMaster, List<Movie> moviesList); boolean parsePersonXML(File xmlFile, Person person);  }
@Test public void testParsePersonXML() { LOG.info("parsePersonXML"); File xmlFile = getTestFile("ParsePersonTest.xml"); Person person = new Person(); MovieJukeboxXMLReader instance = new MovieJukeboxXMLReader(); boolean expResult = true; boolean result = instance.parsePersonXML(xmlFile, person); LOG.info("Person: " + person.toString()); assertEquals(expResult, result); }