use of org.jabref.model.Defaults 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.Defaults in project jabref by JabRef.
the class Benchmarks method write.
@Benchmark
public String write() throws Exception {
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
StringSaveSession saveSession = databaseWriter.savePartOfDatabase(new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences());
return saveSession.getStringValue();
}
use of org.jabref.model.Defaults in project jabref by JabRef.
the class OpenOfficePanel method exportEntries.
private void exportEntries() {
try {
if (style == null) {
style = loader.getUsedStyle();
} else {
style.ensureUpToDate();
}
ooBase.updateSortedReferenceMarks();
List<BibDatabase> databases = getBaseList();
List<String> unresolvedKeys = ooBase.refreshCiteMarkers(databases, style);
BibDatabase newDatabase = ooBase.generateDatabase(databases);
if (!unresolvedKeys.isEmpty()) {
JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", unresolvedKeys.get(0)), Localization.lang("Unable to generate new library"), JOptionPane.ERROR_MESSAGE);
}
Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
BibDatabaseContext databaseContext = new BibDatabaseContext(newDatabase, defaults);
this.frame.addTab(databaseContext, true);
} catch (BibEntryNotFoundException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current library.", ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"), JOptionPane.ERROR_MESSAGE);
LOGGER.debug("BibEntry not found", ex);
} catch (com.sun.star.lang.IllegalArgumentException | UnknownPropertyException | PropertyVetoException | UndefinedCharacterFormatException | NoSuchElementException | WrappedTargetException | IOException | CreationException e) {
LOGGER.warn("Problem generating new database.", e);
}
}
use of org.jabref.model.Defaults in project jabref by JabRef.
the class SharedDatabaseUIManager method openNewSharedDatabaseTab.
/**
* Opens a new shared database tab with the given {@link DBMSConnectionProperties}.
*
* @param dbmsConnectionProperties Connection data
* @param raiseTab If <code>true</code> the new tab gets selected.
* @return BasePanel which also used by {@link SaveDatabaseAction}
*/
public BasePanel openNewSharedDatabaseTab(DBMSConnectionProperties dbmsConnectionProperties) throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {
JabRefFrame frame = JabRefGUI.getMainFrame();
BibDatabaseMode selectedMode = Globals.prefs.getDefaultBibDatabaseMode();
BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new Defaults(selectedMode), DatabaseLocation.SHARED, Globals.prefs.getKeywordDelimiter(), Globals.prefs.getKeyPattern());
dbmsSynchronizer = bibDatabaseContext.getDBMSSynchronizer();
dbmsSynchronizer.openSharedDatabase(dbmsConnectionProperties);
dbmsSynchronizer.registerListener(this);
frame.output(Localization.lang("Connection_to_%0_server_established.", dbmsConnectionProperties.getType().toString()));
return frame.addTab(bibDatabaseContext, true);
}
use of org.jabref.model.Defaults in project jabref by JabRef.
the class ChangeScanner method storeTempDatabase.
private void storeTempDatabase() {
JabRefExecutorService.INSTANCE.execute(() -> {
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withMakeBackup(false).withEncoding(panel.getBibDatabaseContext().getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()));
Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
BibDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(databaseInTemp, metadataInTemp, defaults), prefs);
ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle()));
} catch (SaveException ex) {
LOGGER.warn("Problem updating tmp file after accepting external changes", ex);
}
});
}
Aggregations