use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class BibDatabaseWriter method applySaveActions.
private static List<FieldChange> applySaveActions(List<BibEntry> toChange, MetaData metaData) {
List<FieldChange> changes = new ArrayList<>();
Optional<FieldFormatterCleanups> saveActions = metaData.getSaveActions();
saveActions.ifPresent(actions -> {
for (BibEntry entry : toChange) {
changes.addAll(actions.applySaveActions(entry));
}
});
return changes;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class IsbnViaChimboriFetcher method performSearchById.
@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
if (StringUtil.isBlank(identifier)) {
return Optional.empty();
}
this.ensureThatIsbnIsValid(identifier);
HttpResponse<String> postResponse;
try {
postResponse = Unirest.post("https://bibtex.chimbori.com/isbn-bibtex").field("isbn", identifier).asString();
} catch (UnirestException e) {
throw new FetcherException("Could not retrieve data from chimbori.com", e);
}
if (postResponse.getStatus() != 200) {
throw new FetcherException("Error while retrieving data from chimbori.com: " + postResponse.getBody());
}
List<BibEntry> fetchedEntries;
try {
fetchedEntries = getParser().parseEntries(postResponse.getRawBody());
} catch (ParseException e) {
throw new FetcherException("An internal parser error occurred", e);
}
if (fetchedEntries.isEmpty()) {
return Optional.empty();
} else if (fetchedEntries.size() > 1) {
LOGGER.info("Fetcher " + getName() + "found more than one result for identifier " + identifier + ". We will use the first entry.");
}
BibEntry entry = fetchedEntries.get(0);
// chimbori does not return an ISBN. Thus, we add the one searched for
entry.setField("isbn", identifier);
doPostCleanup(entry);
return Optional.of(entry);
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class GoogleScholar method downloadEntry.
private BibEntry downloadEntry(String link) throws IOException, FetcherException {
String downloadedContent = new URLDownload(link).asString();
BibtexParser parser = new BibtexParser(importFormatPreferences);
ParserResult result = parser.parse(new StringReader(downloadedContent));
if ((result == null) || (result.getDatabase() == null)) {
throw new FetcherException("Parsing entries from Google Scholar bib file failed.");
} else {
Collection<BibEntry> entries = result.getDatabase().getEntries();
if (entries.size() != 1) {
LOGGER.debug(entries.size() + " entries found! (" + link + ")");
throw new FetcherException("Parsing entries from Google Scholar bib file failed.");
} else {
BibEntry entry = entries.iterator().next();
return entry;
}
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class GoogleScholar method addHitsFromQuery.
private void addHitsFromQuery(List<BibEntry> entryList, String queryURL) throws IOException, FetcherException {
String content = new URLDownload(queryURL).asString();
Matcher matcher = LINK_TO_BIB_PATTERN.matcher(content);
while (matcher.find()) {
String citationsPageURL = matcher.group().replace("&", "&");
BibEntry newEntry = downloadEntry(citationsPageURL);
entryList.add(newEntry);
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class IdParserFetcher method findIdentifier.
@Override
default default Optional<T> findIdentifier(BibEntry entry) throws FetcherException {
Objects.requireNonNull(entry);
try (InputStream stream = new BufferedInputStream(getURLForEntry(entry).openStream())) {
List<BibEntry> fetchedEntries = getParser().parseEntries(stream);
if (fetchedEntries.isEmpty()) {
return Optional.empty();
}
// Post-cleanup
fetchedEntries.forEach(this::doPostCleanup);
return extractIdentifier(entry, fetchedEntries);
} catch (URISyntaxException e) {
throw new FetcherException("Search URI is malformed", e);
} catch (FileNotFoundException e) {
LOGGER.debug("Id not found");
return Optional.empty();
} catch (IOException e) {
// TODO catch 503 service unavailable and alert user
throw new FetcherException("An I/O exception occurred", e);
} catch (ParseException e) {
throw new FetcherException("An internal parser error occurred", e);
}
}
Aggregations