Search in sources :

Example 1 with Defaults

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;
    }
}
Also used : SaveException(org.jabref.logic.exporter.SaveException) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) ParserResult(org.jabref.logic.importer.ParserResult) Defaults(org.jabref.model.Defaults) SavePreferences(org.jabref.logic.exporter.SavePreferences) BibDatabase(org.jabref.model.database.BibDatabase) SaveSession(org.jabref.logic.exporter.SaveSession) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 2 with Defaults

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();
}
Also used : Defaults(org.jabref.model.Defaults) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) MetaData(org.jabref.model.metadata.MetaData) SavePreferences(org.jabref.logic.exporter.SavePreferences) StringSaveSession(org.jabref.logic.exporter.StringSaveSession) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 3 with Defaults

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);
    }
}
Also used : WrappedTargetException(com.sun.star.lang.WrappedTargetException) IOException(java.io.IOException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) Defaults(org.jabref.model.Defaults) BibDatabase(org.jabref.model.database.BibDatabase) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) NoSuchElementException(com.sun.star.container.NoSuchElementException)

Example 4 with Defaults

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);
}
Also used : JabRefFrame(org.jabref.gui.JabRefFrame) Defaults(org.jabref.model.Defaults) BibDatabaseMode(org.jabref.model.database.BibDatabaseMode) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 5 with Defaults

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);
        }
    });
}
Also used : SaveException(org.jabref.logic.exporter.SaveException) Defaults(org.jabref.model.Defaults) BibtexDatabaseWriter(org.jabref.logic.exporter.BibtexDatabaseWriter) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) SavePreferences(org.jabref.logic.exporter.SavePreferences) SaveSession(org.jabref.logic.exporter.SaveSession) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Aggregations

Defaults (org.jabref.model.Defaults)24 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)24 BibDatabase (org.jabref.model.database.BibDatabase)9 ParserResult (org.jabref.logic.importer.ParserResult)8 BibEntry (org.jabref.model.entry.BibEntry)7 Test (org.junit.Test)7 Charset (java.nio.charset.Charset)6 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)6 MetaData (org.jabref.model.metadata.MetaData)6 Path (java.nio.file.Path)5 Scanner (java.util.Scanner)5 BibtexDatabaseWriter (org.jabref.logic.exporter.BibtexDatabaseWriter)5 SavePreferences (org.jabref.logic.exporter.SavePreferences)5 Before (org.junit.Before)5 FileSaveSession (org.jabref.logic.exporter.FileSaveSession)3 SaveException (org.jabref.logic.exporter.SaveException)3 SaveSession (org.jabref.logic.exporter.SaveSession)3 FileDirectoryPreferences (org.jabref.model.metadata.FileDirectoryPreferences)3 IOException (java.io.IOException)2 JabRefFrame (org.jabref.gui.JabRefFrame)2