Search in sources :

Example 6 with SavePreferences

use of org.jabref.logic.exporter.SavePreferences in project jabref by JabRef.

the class PreferencesDialog method updateAfterPreferenceChanges.

private void updateAfterPreferenceChanges() {
    setValues();
    Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
    LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
    SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
    ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
    Globals.prefs.updateEntryEditorTabList();
}
Also used : LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) SavePreferences(org.jabref.logic.exporter.SavePreferences) ExportFormat(org.jabref.logic.exporter.ExportFormat)

Example 7 with SavePreferences

use of org.jabref.logic.exporter.SavePreferences in project jabref by JabRef.

the class CustomExportList method readPrefs.

private void readPrefs(JabRefPreferences prefs, JournalAbbreviationLoader loader) {
    Objects.requireNonNull(prefs);
    Objects.requireNonNull(loader);
    formats.clear();
    list.clear();
    int i = 0;
    List<String> s;
    LayoutFormatterPreferences layoutPreferences = prefs.getLayoutFormatterPreferences(loader);
    SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(prefs);
    while (!((s = prefs.getStringList(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i)).isEmpty())) {
        Optional<ExportFormat> format = createFormat(s, layoutPreferences, savePreferences);
        if (format.isPresent()) {
            formats.put(format.get().getConsoleName(), format.get());
            list.add(s);
        } else {
            String customExportFormat = prefs.get(JabRefPreferences.CUSTOM_EXPORT_FORMAT + i);
            LOGGER.error("Error initializing custom export format from string " + customExportFormat);
        }
        i++;
    }
}
Also used : LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) SavePreferences(org.jabref.logic.exporter.SavePreferences) ExportFormat(org.jabref.logic.exporter.ExportFormat)

Example 8 with SavePreferences

use of org.jabref.logic.exporter.SavePreferences in project jabref by JabRef.

the class JabRefMain method start.

private static void start(String[] args) {
    FallbackExceptionHandler.installExceptionHandler();
    JabRefPreferences preferences = JabRefPreferences.getInstance();
    ProxyPreferences proxyPreferences = preferences.getProxyPreferences();
    ProxyRegisterer.register(proxyPreferences);
    if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) {
        Authenticator.setDefault(new ProxyAuthenticator());
    }
    Globals.prefs = preferences;
    Globals.startBackgroundTasks();
    Localization.setLanguage(preferences.get(JabRefPreferences.LANGUAGE));
    Globals.prefs.setLanguageDependentDefaultValues();
    // Perform Migrations
    // Perform checks and changes for users with a preference set from an older JabRef version.
    PreferencesMigrations.upgradePrefsToOrgJabRef();
    PreferencesMigrations.upgradeSortOrder();
    PreferencesMigrations.upgradeFaultyEncodingStrings();
    PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern();
    PreferencesMigrations.upgradeStoredCustomEntryTypes();
    // Update handling of special fields based on preferences
    InternalBibtexFields.updateSpecialFields(Globals.prefs.getBoolean(JabRefPreferences.SERIALIZESPECIALFIELDS));
    // Update name of the time stamp field based on preferences
    InternalBibtexFields.updateTimeStampField(Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD));
    // Update which fields should be treated as numeric, based on preferences:
    InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));
    // Read list(s) of journal names and abbreviations
    Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();
    /* Build list of Import and Export formats */
    Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(), Globals.prefs.getXMPPreferences());
    EntryTypes.loadCustomEntryTypes(preferences.loadCustomEntryTypes(BibDatabaseMode.BIBTEX), preferences.loadCustomEntryTypes(BibDatabaseMode.BIBLATEX));
    Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs, Globals.journalAbbreviationLoader);
    LayoutFormatterPreferences layoutPreferences = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
    SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
    ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
    // Initialize protected terms loader
    Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences());
    ProtectTermsFormatter.setProtectedTermsLoader(Globals.protectedTermsLoader);
    // Check for running JabRef
    RemotePreferences remotePreferences = Globals.prefs.getRemotePreferences();
    if (remotePreferences.useRemoteServer()) {
        Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort());
        if (!Globals.REMOTE_LISTENER.isOpen()) {
            // we are not alone, there is already a server out there, try to contact already running JabRef:
            if (RemoteListenerClient.sendToActiveJabRefInstance(args, remotePreferences.getPort())) {
                // We have successfully sent our command line options through the socket to another JabRef instance.
                // So we assume it's all taken care of, and quit.
                LOGGER.info(Localization.lang("Arguments passed on to running JabRef instance. Shutting down."));
                Globals.shutdownThreadPools();
                // needed to tell JavaFx to stop
                Platform.exit();
                return;
            }
        }
        // we are alone, we start the server
        Globals.REMOTE_LISTENER.start();
    }
    // override used newline character with the one stored in the preferences
    // The preferences return the system newline character sequence as default
    OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE);
    // Process arguments
    ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START);
    // See if we should shut down now
    if (argumentProcessor.shouldShutDown()) {
        Globals.shutdownThreadPools();
        return;
    }
    // If not, start GUI
    SwingUtilities.invokeLater(() -> new JabRefGUI(argumentProcessor.getParserResults(), argumentProcessor.isBlank()));
}
Also used : ProtectedTermsLoader(org.jabref.logic.protectedterms.ProtectedTermsLoader) JournalAbbreviationLoader(org.jabref.logic.journals.JournalAbbreviationLoader) ExportFormat(org.jabref.logic.exporter.ExportFormat) ArgumentProcessor(org.jabref.cli.ArgumentProcessor) ProxyPreferences(org.jabref.logic.net.ProxyPreferences) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) JabRefMessageHandler(org.jabref.gui.remote.JabRefMessageHandler) ProxyAuthenticator(org.jabref.logic.net.ProxyAuthenticator) RemotePreferences(org.jabref.logic.remote.RemotePreferences) JabRefPreferences(org.jabref.preferences.JabRefPreferences) SavePreferences(org.jabref.logic.exporter.SavePreferences)

Example 9 with SavePreferences

use of org.jabref.logic.exporter.SavePreferences in project jabref by JabRef.

the class ArgumentProcessor method exportFile.

private void exportFile(List<ParserResult> loaded, String[] data) {
    if (data.length == 1) {
        // format to the given file.
        if (!loaded.isEmpty()) {
            ParserResult pr = loaded.get(loaded.size() - 1);
            if (!pr.isInvalid()) {
                try {
                    System.out.println(Localization.lang("Saving") + ": " + data[0]);
                    SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs);
                    Defaults defaults = new Defaults(Globals.prefs.getDefaultBibDatabaseMode());
                    BibDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
                    SaveSession session = databaseWriter.saveDatabase(new BibDatabaseContext(pr.getDatabase(), pr.getMetaData(), 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(data[0]);
                } catch (SaveException ex) {
                    System.err.println(Localization.lang("Could not save file.") + "\n" + ex.getLocalizedMessage());
                }
            }
        } else {
            System.err.println(Localization.lang("The output option depends on a valid import option."));
        }
    } else if (data.length == 2) {
        // This signals that the latest import should be stored in the given
        // format to the given file.
        ParserResult pr = loaded.get(loaded.size() - 1);
        // Set the global variable for this database's file directory before exporting,
        // so formatters can resolve linked files correctly.
        // (This is an ugly hack!)
        File theFile = pr.getFile().get();
        if (!theFile.isAbsolute()) {
            theFile = theFile.getAbsoluteFile();
        }
        BibDatabaseContext databaseContext = pr.getDatabaseContext();
        databaseContext.setDatabaseFile(theFile);
        Globals.prefs.fileDirForDatabase = databaseContext.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());
        System.out.println(Localization.lang("Exporting") + ": " + data[0]);
        IExportFormat format = ExportFormats.getExportFormat(data[1]);
        if (format == null) {
            System.err.println(Localization.lang("Unknown export format") + ": " + data[1]);
        } else {
            // We have an ExportFormat instance:
            try {
                format.performExport(pr.getDatabaseContext(), data[0], pr.getDatabaseContext().getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), pr.getDatabaseContext().getDatabase().getEntries());
            } catch (Exception ex) {
                System.err.println(Localization.lang("Could not export file") + " '" + data[0] + "': " + ExceptionUtils.getStackTrace(ex));
            }
        }
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) 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) IExportFormat(org.jabref.logic.exporter.IExportFormat) SaveSession(org.jabref.logic.exporter.SaveSession) FileSaveSession(org.jabref.logic.exporter.FileSaveSession) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) File(java.io.File) JabRefException(org.jabref.JabRefException) BackingStoreException(java.util.prefs.BackingStoreException) SaveException(org.jabref.logic.exporter.SaveException) IOException(java.io.IOException) ImportException(org.jabref.logic.importer.ImportException)

Example 10 with SavePreferences

use of org.jabref.logic.exporter.SavePreferences in project jabref by JabRef.

the class Benchmarks method init.

@Setup
public void init() throws Exception {
    Globals.prefs = JabRefPreferences.getInstance();
    Random randomizer = new Random();
    for (int i = 0; i < 1000; i++) {
        BibEntry entry = new BibEntry();
        entry.setCiteKey("id" + i);
        entry.setField("title", "This is my title " + i);
        entry.setField("author", "Firstname Lastname and FirstnameA LastnameA and FirstnameB LastnameB" + i);
        entry.setField("journal", "Journal Title " + i);
        entry.setField("keyword", "testkeyword");
        entry.setField("year", "1" + i);
        entry.setField("rnd", "2" + randomizer.nextInt());
        database.insertEntry(entry);
    }
    BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
    StringSaveSession saveSession = databaseWriter.savePartOfDatabase(new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), new SavePreferences());
    bibtexString = saveSession.getStringValue();
    latexConversionString = "{A} \\textbf{bold} approach {\\it to} ${{\\Sigma}}{\\Delta}$ modulator \\textsuperscript{2} \\$";
    htmlConversionString = "<b>&Ouml;sterreich</b> &#8211; &amp; characters &#x2aa2; <i>italic</i>";
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Defaults(org.jabref.model.Defaults) Random(java.util.Random) 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) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

SavePreferences (org.jabref.logic.exporter.SavePreferences)13 BibtexDatabaseWriter (org.jabref.logic.exporter.BibtexDatabaseWriter)8 FileSaveSession (org.jabref.logic.exporter.FileSaveSession)6 SaveException (org.jabref.logic.exporter.SaveException)6 ExportFormat (org.jabref.logic.exporter.ExportFormat)5 SaveSession (org.jabref.logic.exporter.SaveSession)5 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)5 Defaults (org.jabref.model.Defaults)5 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)5 Charset (java.nio.charset.Charset)3 IExportFormat (org.jabref.logic.exporter.IExportFormat)3 BibEntry (org.jabref.model.entry.BibEntry)3 FormBuilder (com.jgoodies.forms.builder.FormBuilder)2 FormLayout (com.jgoodies.forms.layout.FormLayout)2 File (java.io.File)2 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)2 JTextArea (javax.swing.JTextArea)2 JabRefException (org.jabref.JabRefException)2 StringSaveSession (org.jabref.logic.exporter.StringSaveSession)2 ParserResult (org.jabref.logic.importer.ParserResult)2