use of org.jabref.model.database.BibDatabase in project jabref by JabRef.
the class ArgumentProcessor method generateAux.
private boolean generateAux(List<ParserResult> loaded, String[] data) {
if (data.length == 2) {
ParserResult pr = loaded.get(0);
AuxCommandLine acl = new AuxCommandLine(data[0], pr.getDatabase());
BibDatabase newBase = acl.perform();
boolean notSavedMsg = false;
// write an output, if something could be resolved
if ((newBase != null) && newBase.hasEntries()) {
String subName = StringUtil.getCorrectFileName(data[1], "bib");
try {
System.out.println(Localization.lang("Saving") + ": " + subName);
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs);
BibDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
SaveSession session = databaseWriter.saveDatabase(new BibDatabaseContext(newBase, defaults), prefs);
// Show just a warning message if encoding did not work for all characters:
if (!session.getWriter().couldEncodeAll()) {
System.err.println(Localization.lang("Warning") + ": " + Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName()) + " " + session.getWriter().getProblemCharacters());
}
session.commit(subName);
} catch (SaveException ex) {
System.err.println(Localization.lang("Could not save file.") + "\n" + ex.getLocalizedMessage());
}
notSavedMsg = true;
}
if (!notSavedMsg) {
System.out.println(Localization.lang("no library generated"));
}
return false;
} else {
return true;
}
}
use of org.jabref.model.database.BibDatabase in project jabref by JabRef.
the class ClipBoardManager method extractBibEntriesFromClipboard.
public List<BibEntry> extractBibEntriesFromClipboard() {
// Get clipboard contents, and see if TransferableBibtexEntry is among the content flavors offered
Transferable content = CLIPBOARD.getContents(null);
List<BibEntry> result = new ArrayList<>();
if (content.isDataFlavorSupported(TransferableBibtexEntry.entryFlavor)) {
// We have determined that the clipboard data is a set of entries.
try {
@SuppressWarnings("unchecked") List<BibEntry> contents = (List<BibEntry>) content.getTransferData(TransferableBibtexEntry.entryFlavor);
result = contents;
} catch (UnsupportedFlavorException | ClassCastException ex) {
LOGGER.warn("Could not paste this type", ex);
} catch (IOException ex) {
LOGGER.warn("Could not paste", ex);
}
} else if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String data = (String) content.getTransferData(DataFlavor.stringFlavor);
// fetch from doi
if (DOI.parse(data).isPresent()) {
LOGGER.info("Found DOI in clipboard");
Optional<BibEntry> entry = new DoiFetcher(Globals.prefs.getImportFormatPreferences()).performSearchById(new DOI(data).getDOI());
entry.ifPresent(result::add);
} else {
// parse bibtex string
BibtexParser bp = new BibtexParser(Globals.prefs.getImportFormatPreferences());
BibDatabase db = bp.parse(new StringReader(data)).getDatabase();
LOGGER.info("Parsed " + db.getEntryCount() + " entries from clipboard text");
if (db.hasEntries()) {
result = db.getEntries();
}
}
} catch (UnsupportedFlavorException ex) {
LOGGER.warn("Could not parse this type", ex);
} catch (IOException ex) {
LOGGER.warn("Data is no longer available in the requested flavor", ex);
} catch (FetcherException ex) {
LOGGER.error("Error while fetching", ex);
}
}
return result;
}
use of org.jabref.model.database.BibDatabase in project jabref by JabRef.
the class SearchFixDuplicateLabels method run.
@Override
public void run() {
// Find all multiple occurrences of BibTeX keys.
dupes = new HashMap<>();
Map<String, BibEntry> foundKeys = new HashMap<>();
BibDatabase db = panel.getDatabase();
for (BibEntry entry : db.getEntries()) {
entry.getCiteKeyOptional().filter(key -> !key.isEmpty()).ifPresent(key -> {
if (foundKeys.containsKey(key)) {
if (dupes.containsKey(key)) {
dupes.get(key).add(entry);
} else {
List<BibEntry> al = new ArrayList<>();
al.add(foundKeys.get(key));
al.add(entry);
dupes.put(key, al);
}
} else {
foundKeys.put(key, entry);
}
});
}
}
use of org.jabref.model.database.BibDatabase in project jabref by JabRef.
the class INSPIREFetcher method processQuery.
/*
* @see java.lang.Runnable
*/
@Override
public boolean processQuery(String query, ImportInspector dialog, OutputPrinter status) {
try {
status.setStatus(Localization.lang("Fetching entries from Inspire"));
/* query the archive and load the results into the BibEntry */
BibDatabase bd = importInspireEntries(query);
status.setStatus(Localization.lang("Adding fetched entries"));
/* add the entry to the inspection dialog */
bd.getEntries().forEach(dialog::addEntry);
return true;
} catch (Exception e) {
LOGGER.error("Error while fetching from " + getTitle(), e);
((ImportInspectionDialog) dialog).showErrorMessage(this.getTitle(), e.getLocalizedMessage());
}
return false;
}
use of org.jabref.model.database.BibDatabase in project jabref by JabRef.
the class OpenOfficePanel method pushEntries.
private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addPageInfo) {
if (!ooBase.isConnectedToDocument()) {
JOptionPane.showMessageDialog(frame, Localization.lang("Not connected to any Writer document. Please" + " make sure a document is open, and use the 'Select Writer document' button to connect to it."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
return;
}
Boolean inParenthesis = inParenthesisIn;
String pageInfo = null;
if (addPageInfo) {
AdvancedCiteDialog citeDialog = new AdvancedCiteDialog(frame);
citeDialog.showDialog();
if (citeDialog.canceled()) {
return;
}
if (!citeDialog.getPageInfo().isEmpty()) {
pageInfo = citeDialog.getPageInfo();
}
inParenthesis = citeDialog.isInParenthesisCite();
}
BasePanel panel = frame.getCurrentBasePanel();
if (panel != null) {
final BibDatabase database = panel.getDatabase();
List<BibEntry> entries = panel.getSelectedEntries();
if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) {
try {
if (style == null) {
style = loader.getUsedStyle();
}
ooBase.insertEntry(entries, database, getBaseList(), style, inParenthesis, withText, pageInfo, preferences.syncWhenCiting());
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("You must select either a valid style file, or use one of the default styles."), Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
LOGGER.warn("Problem with style file", ex);
} catch (ConnectionLostException ex) {
showConnectionLostErrorMessage();
} catch (UndefinedCharacterFormatException ex) {
reportUndefinedCharacterFormat(ex);
} catch (UndefinedParagraphFormatException ex) {
reportUndefinedParagraphFormat(ex);
} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | CreationException | NoSuchElementException | WrappedTargetException | IOException | BibEntryNotFoundException | IllegalTypeException | PropertyExistException | NotRemoveableException ex) {
LOGGER.warn("Could not insert entry", ex);
}
}
}
}
Aggregations