use of org.jabref.preferences.JabRefPreferences 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()));
}
use of org.jabref.preferences.JabRefPreferences in project jabref by JabRef.
the class PreferencesMigrations method upgradeSortOrder.
/**
* Upgrade the sort order preferences for the current version
* The old preference is kept in case an old version of JabRef is used with
* these preferences, but it is only used when the new preference does not
* exist
*/
public static void upgradeSortOrder() {
JabRefPreferences prefs = Globals.prefs;
if (prefs.get(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER, null) == null) {
if (prefs.getBoolean("exportInStandardOrder", false)) {
prefs.putBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER, true);
prefs.put(JabRefPreferences.EXPORT_PRIMARY_SORT_FIELD, FieldName.AUTHOR);
prefs.put(JabRefPreferences.EXPORT_SECONDARY_SORT_FIELD, FieldName.EDITOR);
prefs.put(JabRefPreferences.EXPORT_TERTIARY_SORT_FIELD, FieldName.YEAR);
prefs.putBoolean(JabRefPreferences.EXPORT_PRIMARY_SORT_DESCENDING, false);
prefs.putBoolean(JabRefPreferences.EXPORT_SECONDARY_SORT_DESCENDING, false);
prefs.putBoolean(JabRefPreferences.EXPORT_TERTIARY_SORT_DESCENDING, false);
} else if (prefs.getBoolean("exportInTitleOrder", false)) {
// exportInTitleOrder => title, author, editor
prefs.putBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER, true);
prefs.put(JabRefPreferences.EXPORT_PRIMARY_SORT_FIELD, FieldName.TITLE);
prefs.put(JabRefPreferences.EXPORT_SECONDARY_SORT_FIELD, FieldName.AUTHOR);
prefs.put(JabRefPreferences.EXPORT_TERTIARY_SORT_FIELD, FieldName.EDITOR);
prefs.putBoolean(JabRefPreferences.EXPORT_PRIMARY_SORT_DESCENDING, false);
prefs.putBoolean(JabRefPreferences.EXPORT_SECONDARY_SORT_DESCENDING, false);
prefs.putBoolean(JabRefPreferences.EXPORT_TERTIARY_SORT_DESCENDING, false);
}
}
}
use of org.jabref.preferences.JabRefPreferences in project jabref by JabRef.
the class PreferencesMigrations method upgradeStoredCustomEntryTypes.
/**
* Migrate all customized entry types from versions <=3.7
*/
public static void upgradeStoredCustomEntryTypes() {
JabRefPreferences prefs = Globals.prefs;
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
try {
if (mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBTEX_TYPES) || mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES)) {
// skip further processing as prefs already have been migrated
} else {
LOGGER.info("Migrating old custom entry types.");
CustomEntryTypePreferenceMigration.upgradeStoredCustomEntryTypes(prefs.getDefaultBibDatabaseMode());
}
} catch (BackingStoreException ex) {
LOGGER.error("Migrating old custom entry types failed.", ex);
}
}
use of org.jabref.preferences.JabRefPreferences in project jabref by JabRef.
the class PreferencesMigrations method upgradeLabelPatternToBibtexKeyPattern.
/**
* Migrate LabelPattern configuration from versions <=3.5 to new BibtexKeyPatterns
*/
public static void upgradeLabelPatternToBibtexKeyPattern() {
JabRefPreferences prefs = Globals.prefs;
try {
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
// Migrate default pattern
if (mainPrefsNode.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, null) == null) {
// Check whether old defaultLabelPattern is set
String oldDefault = mainPrefsNode.get("defaultLabelPattern", null);
if (oldDefault != null) {
prefs.put(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, oldDefault);
LOGGER.info("Upgraded old default key generator pattern '" + oldDefault + "' to new version.");
}
}
//Pref node already exists do not migrate from previous version
if (mainPrefsNode.nodeExists(JabRefPreferences.BIBTEX_KEY_PATTERNS_NODE)) {
return;
}
// Check for prefs node for Version 3.3-3.5
if (mainPrefsNode.nodeExists("logic/labelpattern")) {
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("logic/labelpattern"));
} else if (mainPrefsNode.nodeExists("logic/labelPattern")) {
// node used for version 3.0-3.2
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("logic/labelPattern"));
} else if (mainPrefsNode.nodeExists("labelPattern")) {
// node used for version <3.0
migrateTypedKeyPrefs(prefs, mainPrefsNode.node("labelPattern"));
}
} catch (BackingStoreException e) {
LOGGER.error("Migrating old bibtexKeyPatterns failed.", e);
}
}
use of org.jabref.preferences.JabRefPreferences in project jabref by JabRef.
the class PreferencesMigrations method upgradePrefsToOrgJabRef.
/**
* Migrate all preferences from net/sf/jabref to org/jabref
*/
public static void upgradePrefsToOrgJabRef() {
JabRefPreferences prefs = Globals.prefs;
Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class);
try {
if (mainPrefsNode.childrenNames().length != 0) {
// skip further processing as prefs already have been migrated
LOGGER.debug("New prefs node already exists with content - skipping migration");
} else {
if (mainPrefsNode.parent().parent().nodeExists("net/sf/jabref")) {
LOGGER.info("Migrating old preferences.");
Preferences oldNode = mainPrefsNode.parent().parent().node("net/sf/jabref");
copyPrefsRecursively(oldNode, mainPrefsNode);
}
}
} catch (BackingStoreException ex) {
LOGGER.error("Migrating old preferences failed.", ex);
}
}
Aggregations