use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class LinkedFilesEditorViewModel method findAssociatedNotLinkedFiles.
/**
* Find files that are probably associated to the given entry but not yet linked.
*/
private List<LinkedFileViewModel> findAssociatedNotLinkedFiles(BibEntry entry) {
final List<Path> dirs = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
final List<String> extensions = ExternalFileTypes.getInstance().getExternalFileTypeSelection().stream().map(ExternalFileType::getExtension).collect(Collectors.toList());
// Run the search operation:
FileFinder fileFinder = FileFinders.constructFromConfiguration(Globals.prefs.getAutoLinkPreferences());
List<Path> newFiles = fileFinder.findAssociatedFiles(entry, dirs, extensions);
List<LinkedFileViewModel> result = new ArrayList<>();
for (Path newFile : newFiles) {
boolean alreadyLinked = files.get().stream().map(file -> file.findIn(dirs)).anyMatch(file -> file.isPresent() && file.get().equals(newFile));
if (!alreadyLinked) {
LinkedFileViewModel newLinkedFile = new LinkedFileViewModel(fromFile(newFile, dirs));
newLinkedFile.markAsAutomaticallyFound();
result.add(newLinkedFile);
}
}
return result;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class GroupTreeNodeViewModel method changeEntriesTo.
public void changeEntriesTo(List<BibEntry> entries, UndoManager undoManager) {
AbstractGroup group = node.getGroup();
List<FieldChange> changesRemove = new ArrayList<>();
List<FieldChange> changesAdd = new ArrayList<>();
// Sort entries into current members and non-members of the group
// Current members will be removed
// Current non-members will be added
List<BibEntry> toRemove = new ArrayList<>(entries.size());
List<BibEntry> toAdd = new ArrayList<>(entries.size());
for (BibEntry entry : entries) {
// Sort according to current state of the entries
if (group.contains(entry)) {
toRemove.add(entry);
} else {
toAdd.add(entry);
}
}
// If there are entries to remove
if (!toRemove.isEmpty()) {
changesRemove = removeEntriesFromGroup(toRemove);
}
// If there are entries to add
if (!toAdd.isEmpty()) {
changesAdd = addEntriesToGroup(toAdd);
}
// Remember undo information
if (!changesRemove.isEmpty()) {
AbstractUndoableEdit undoRemove = UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesRemove);
if (!changesAdd.isEmpty() && (undoRemove != null)) {
// we removed and added entries
undoRemove.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesAdd));
}
undoManager.addEdit(undoRemove);
} else if (!changesAdd.isEmpty()) {
undoManager.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesAdd));
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class CiteSeerXFetcher method getSingleCitation.
private static BibEntry getSingleCitation(String urlString) throws IOException {
String cont = new URLDownload(urlString).asString();
// Find title, and create entry if we do. Otherwise assume we did not get an entry:
Matcher m = CiteSeerXFetcher.TITLE_PATTERN.matcher(cont);
if (m.find()) {
BibEntry entry = new BibEntry();
entry.setField(FieldName.TITLE, m.group(1));
// Find authors:
m = CiteSeerXFetcher.AUTHOR_PATTERN.matcher(cont);
if (m.find()) {
String authors = m.group(1);
entry.setField(FieldName.AUTHOR, new NormalizeNamesFormatter().format(authors));
}
// Find year:
m = CiteSeerXFetcher.YEAR_PATTERN.matcher(cont);
if (m.find()) {
entry.setField(FieldName.YEAR, m.group(1));
}
// Find abstract:
m = CiteSeerXFetcher.ABSTRACT_PATTERN.matcher(cont);
if (m.find()) {
entry.setField(FieldName.ABSTRACT, m.group(1));
}
return entry;
} else {
return null;
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class DOAJFetcher method processQuery.
@Override
public boolean processQuery(String query, ImportInspector inspector, OutputPrinter status) {
shouldContinue = true;
try {
status.setStatus(Localization.lang("Searching..."));
HttpResponse<JsonNode> jsonResponse;
jsonResponse = Unirest.get(SEARCH_URL + query + "?pageSize=1").header("accept", "application/json").asJson();
JSONObject jo = jsonResponse.getBody().getObject();
int numberToFetch = jo.getInt("total");
if (numberToFetch > 0) {
if (numberToFetch > MAX_PER_PAGE) {
boolean numberEntered = false;
do {
String strCount = JOptionPane.showInputDialog(Localization.lang("%0 references found. Number of references to fetch?", String.valueOf(numberToFetch)));
if (strCount == null) {
status.setStatus(Localization.lang("%0 import canceled", getTitle()));
return false;
}
try {
numberToFetch = Integer.parseInt(strCount.trim());
numberEntered = true;
} catch (NumberFormatException ex) {
status.showMessage(Localization.lang("Please enter a valid number"));
}
} while (!numberEntered);
}
// Keep track of number of items fetched for the progress bar
int fetched = 0;
for (int page = 1; ((page - 1) * MAX_PER_PAGE) <= numberToFetch; page++) {
if (!shouldContinue) {
break;
}
int noToFetch = Math.min(MAX_PER_PAGE, numberToFetch - ((page - 1) * MAX_PER_PAGE));
jsonResponse = Unirest.get(SEARCH_URL + query + "?page=" + page + "&pageSize=" + noToFetch).header("accept", "application/json").asJson();
jo = jsonResponse.getBody().getObject();
if (jo.has("results")) {
JSONArray results = jo.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject bibJsonEntry = results.getJSONObject(i).getJSONObject("bibjson");
BibEntry entry = jsonConverter.parseBibJSONtoBibtex(bibJsonEntry, Globals.prefs.getKeywordDelimiter());
inspector.addEntry(entry);
fetched++;
inspector.setProgress(fetched, numberToFetch);
}
}
}
return true;
} else {
status.showMessage(Localization.lang("No entries found for the search string '%0'", query), Localization.lang("Search %0", getTitle()), JOptionPane.INFORMATION_MESSAGE);
return false;
}
} catch (UnirestException e) {
LOGGER.error("Error while fetching from " + getTitle(), e);
((ImportInspectionDialog) inspector).showErrorMessage(this.getTitle(), e.getLocalizedMessage());
return false;
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class AbbreviateAction method run.
@Override
public void run() {
List<BibEntry> entries = panel.getSelectedEntries();
if (entries == null) {
return;
}
UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()), iso);
NamedCompound ce = new NamedCompound(Localization.lang("Abbreviate journal names"));
int count = 0;
for (BibEntry entry : entries) {
for (String journalField : InternalBibtexFields.getJournalNameFields()) {
if (undoableAbbreviator.abbreviate(panel.getDatabase(), entry, journalField, ce)) {
count++;
}
}
}
if (count > 0) {
ce.end();
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
message = Localization.lang("Abbreviated %0 journal names.", String.valueOf(count));
} else {
message = Localization.lang("No journal names could be abbreviated.");
}
}
Aggregations