use of org.jabref.logic.importer.fileformat.medline.PubmedArticleSet in project jabref by JabRef.
the class MedlineImporter method importDatabase.
@Override
public ParserResult importDatabase(BufferedReader reader) throws IOException {
Objects.requireNonNull(reader);
List<BibEntry> bibItems = new ArrayList<>();
try {
JAXBContext context = JAXBContext.newInstance("org.jabref.logic.importer.fileformat.medline");
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader);
//go to the root element
while (!xmlStreamReader.isStartElement()) {
xmlStreamReader.next();
}
Unmarshaller unmarshaller = context.createUnmarshaller();
Object unmarshalledObject = unmarshaller.unmarshal(xmlStreamReader);
//check whether we have an article set, an article, a book article or a book article set
if (unmarshalledObject instanceof PubmedArticleSet) {
PubmedArticleSet articleSet = (PubmedArticleSet) unmarshalledObject;
for (Object article : articleSet.getPubmedArticleOrPubmedBookArticle()) {
if (article instanceof PubmedArticle) {
PubmedArticle currentArticle = (PubmedArticle) article;
parseArticle(currentArticle, bibItems);
}
if (article instanceof PubmedBookArticle) {
PubmedBookArticle currentArticle = (PubmedBookArticle) article;
parseBookArticle(currentArticle, bibItems);
}
}
} else if (unmarshalledObject instanceof PubmedArticle) {
PubmedArticle article = (PubmedArticle) unmarshalledObject;
parseArticle(article, bibItems);
} else if (unmarshalledObject instanceof PubmedBookArticle) {
PubmedBookArticle currentArticle = (PubmedBookArticle) unmarshalledObject;
parseBookArticle(currentArticle, bibItems);
} else {
PubmedBookArticleSet bookArticleSet = (PubmedBookArticleSet) unmarshalledObject;
for (PubmedBookArticle bookArticle : bookArticleSet.getPubmedBookArticle()) {
parseBookArticle(bookArticle, bibItems);
}
}
} catch (JAXBException | XMLStreamException e) {
LOGGER.debug("could not parse document", e);
return ParserResult.fromError(e);
}
return new ParserResult(bibItems);
}
Aggregations