use of org.ambraproject.rhino.view.article.author.AuthorView in project rhino by PLOS.
the class AuthorsXmlExtractor method buildAuthors.
private List<AuthorView> buildAuthors() throws XPathException {
List<AuthorView> list = new ArrayList<>();
//Get all the authors
NodeList authorList = xpath.selectNodes(doc, "//contrib-group/contrib[@contrib-type='author']");
for (int i = 0; i < authorList.getLength(); i++) {
Node authorNode = authorList.item(i);
//Create temp author document fragment to search out of
DocumentFragment authorDoc = doc.createDocumentFragment();
//I thought this strange, appendChild actually moves the node in the case of document fragment
//hence below I clone to keep the original DOM intact.
//re: http://docs.oracle.com/javase/1.4.2/docs/api/org/w3c/dom/Node.html#appendChild%28org.w3c.dom.Node%29
authorDoc.appendChild(authorNode.cloneNode(true));
Node surNameNode = xpath.selectNode(authorDoc, "./contrib/name/surname");
Node givenNameNode = xpath.selectNode(authorDoc, "./contrib/name/given-names");
Node collabNameNode = xpath.selectNode(authorDoc, "//collab");
Node behalfOfNode = xpath.selectNode(authorDoc, "//on-behalf-of");
NodeList otherFootnotesNodeList = xpath.selectNodes(authorDoc, "//xref[@ref-type='fn']");
//Note:10.1371/journal.pone.0032315
if (surNameNode == null && givenNameNode == null) {
if (collabNameNode != null) {
//Previous authors "on behalf of" node
if (list.size() > 0) {
if (list.get(list.size() - 1).getOnBehalfOf() != null) {
//footnotes from this contrib to that author!
for (int a = 0; a < otherFootnotesNodeList.getLength(); a++) {
Node node = otherFootnotesNodeList.item(a);
if (node.getAttributes().getNamedItem("rid") != null) {
String id = node.getAttributes().getNamedItem("rid").getTextContent();
String value = otherFootnotesMap.get(id);
if (value != null) {
AuthorView av = list.get(list.size() - 1);
//This may look a bit odd, but because the AuthorView is immutable
//I have to create a new copy to change any values
List<String> footnotes = new ArrayList<>();
footnotes.addAll(av.getCustomFootnotes());
value = fixPilcrow(value, false);
footnotes.add(value);
list.set(list.size() - 1, AuthorView.builder(av).setCustomFootnotes(footnotes).build());
}
}
}
break;
}
}
}
givenNameNode = collabNameNode;
}
// If both of these are null then don't bother to add
if (surNameNode == null && givenNameNode == null) {
continue;
}
AuthorView author = getAuthorView(authorDoc, surNameNode, givenNameNode, behalfOfNode, otherFootnotesNodeList);
list.add(author);
}
return list;
}
use of org.ambraproject.rhino.view.article.author.AuthorView in project rhino by PLOS.
the class AuthorsXmlExtractorTest method testGetAuthors.
@Test(dataProvider = "authorTestData")
public void testGetAuthors(String filename, AuthorView[] expected) throws Exception {
Document doc = parseTestFile(filename);
List<AuthorView> actual = AuthorsXmlExtractor.getAuthors(doc, xpathReader);
assertEquals(actual, Arrays.asList(expected));
}
Aggregations