Search in sources :

Example 1 with GlobalBibtexKeyPattern

use of org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern in project jabref by JabRef.

the class BibtexKeyPatternPanel method getKeyPatternAsGlobalBibtexKeyPattern.

protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() {
    GlobalBibtexKeyPattern res = GlobalBibtexKeyPattern.fromPattern(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN));
    fillPatternUsingPanelData(res);
    return res;
}
Also used : GlobalBibtexKeyPattern(org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern)

Example 2 with GlobalBibtexKeyPattern

use of org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern in project jabref by JabRef.

the class BibtexKeyPatternPrefTab method storeSettings.

/**
     * Store changes to table preferences. This method is called when the user clicks Ok.
     *
     */
@Override
public void storeSettings() {
    // Set the default value:
    Globals.prefs.put(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, defaultPat.getText());
    Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, warnBeforeOverwriting.isSelected());
    Globals.prefs.putBoolean(JabRefPreferences.AVOID_OVERWRITING_KEY, dontOverwrite.isSelected());
    Globals.prefs.put(JabRefPreferences.KEY_PATTERN_REGEX, keyPatternRegex.getText());
    Globals.prefs.put(JabRefPreferences.KEY_PATTERN_REPLACEMENT, keyPatternReplacement.getText());
    Globals.prefs.putBoolean(JabRefPreferences.GENERATE_KEYS_AFTER_INSPECTION, autoGenerateOnImport.isSelected());
    Globals.prefs.putBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING, generateOnSave.isSelected());
    if (alwaysAddLetter.isSelected()) {
        Globals.prefs.putBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER, true);
    } else if (letterStartA.isSelected()) {
        Globals.prefs.putBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A, true);
        Globals.prefs.putBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER, false);
    } else {
        Globals.prefs.putBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A, false);
        Globals.prefs.putBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER, false);
    }
    // fetch entries from GUI
    GlobalBibtexKeyPattern keypatterns = getKeyPatternAsGlobalBibtexKeyPattern();
    // store new patterns globally
    prefs.putKeyPattern(keypatterns);
}
Also used : GlobalBibtexKeyPattern(org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern)

Example 3 with GlobalBibtexKeyPattern

use of org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern in project jabref by JabRef.

the class MetaDataSerializer method getSerializedStringMap.

/**
     * Writes all data in the format <key, serialized data>.
     */
public static Map<String, String> getSerializedStringMap(MetaData metaData, GlobalBibtexKeyPattern globalCiteKeyPattern) {
    // First write all meta data except groups
    Map<String, List<String>> stringyMetaData = new HashMap<>();
    metaData.getSaveOrderConfig().ifPresent(saveOrderConfig -> stringyMetaData.put(MetaData.SAVE_ORDER_CONFIG, saveOrderConfig.getAsStringList()));
    metaData.getSaveActions().ifPresent(saveActions -> stringyMetaData.put(MetaData.SAVE_ACTIONS, saveActions.getAsStringList(OS.NEWLINE)));
    if (metaData.isProtected()) {
        stringyMetaData.put(MetaData.PROTECTED_FLAG_META, Collections.singletonList("true"));
    }
    stringyMetaData.putAll(serializeCiteKeyPattern(metaData, globalCiteKeyPattern));
    metaData.getMode().ifPresent(mode -> stringyMetaData.put(MetaData.DATABASE_TYPE, Collections.singletonList(mode.getAsString())));
    metaData.getDefaultFileDirectory().ifPresent(path -> stringyMetaData.put(MetaData.FILE_DIRECTORY, Collections.singletonList(path.trim())));
    metaData.getUserFileDirectories().forEach((user, path) -> stringyMetaData.put(MetaData.FILE_DIRECTORY + '-' + user, Collections.singletonList(path.trim())));
    for (ContentSelector selector : metaData.getContentSelectorList()) {
        stringyMetaData.put(MetaData.SELECTOR_META_PREFIX + selector.getFieldName(), selector.getValues());
    }
    Map<String, String> serializedMetaData = serializeMetaData(stringyMetaData);
    // Write groups if present.
    // Skip this if only the root node exists (which is always the AllEntriesGroup).
    metaData.getGroups().filter(root -> root.getNumberOfChildren() > 0).ifPresent(root -> serializedMetaData.put(MetaData.GROUPSTREE, serializeGroups(root)));
    // finally add all unknown meta data items to the serialization map
    Map<String, List<String>> unknownMetaData = metaData.getUnknownMetaData();
    for (Map.Entry<String, List<String>> entry : unknownMetaData.entrySet()) {
        StringBuilder value = new StringBuilder();
        value.append(OS.NEWLINE);
        for (String line : entry.getValue()) {
            value.append(line.replaceAll(";", "\\\\;") + MetaData.SEPARATOR_STRING + OS.NEWLINE);
        }
        serializedMetaData.put(entry.getKey(), value.toString());
    }
    return serializedMetaData;
}
Also used : GlobalBibtexKeyPattern(org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern) StringUtil(org.jabref.model.strings.StringUtil) AbstractBibtexKeyPattern(org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern) ContentSelector(org.jabref.model.metadata.ContentSelector) HashMap(java.util.HashMap) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) OS(org.jabref.logic.util.OS) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) Map(java.util.Map) MetaData(org.jabref.model.metadata.MetaData) Collections(java.util.Collections) HashMap(java.util.HashMap) ContentSelector(org.jabref.model.metadata.ContentSelector) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 4 with GlobalBibtexKeyPattern

use of org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern in project jabref by JabRef.

the class SavePreferences method loadForExportFromPreferences.

public static SavePreferences loadForExportFromPreferences(JabRefPreferences preferences) {
    Boolean saveInOriginalOrder = preferences.getBoolean(JabRefPreferences.EXPORT_IN_ORIGINAL_ORDER);
    SaveOrderConfig saveOrder = null;
    if (!saveInOriginalOrder) {
        if (preferences.getBoolean(JabRefPreferences.EXPORT_IN_SPECIFIED_ORDER)) {
            saveOrder = preferences.loadExportSaveOrder();
        } else {
            saveOrder = preferences.loadTableSaveOrder();
        }
    }
    Charset encoding = preferences.getDefaultEncoding();
    Boolean makeBackup = preferences.getBoolean(JabRefPreferences.BACKUP);
    DatabaseSaveType saveType = DatabaseSaveType.ALL;
    Boolean takeMetadataSaveOrderInAccount = false;
    Boolean reformatFile = preferences.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT);
    LatexFieldFormatterPreferences latexFieldFormatterPreferences = preferences.getLatexFieldFormatterPreferences();
    GlobalBibtexKeyPattern globalCiteKeyPattern = preferences.getKeyPattern();
    return new SavePreferences(saveInOriginalOrder, saveOrder, encoding, makeBackup, saveType, takeMetadataSaveOrderInAccount, reformatFile, latexFieldFormatterPreferences, globalCiteKeyPattern);
}
Also used : GlobalBibtexKeyPattern(org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern) Charset(java.nio.charset.Charset) LatexFieldFormatterPreferences(org.jabref.logic.bibtex.LatexFieldFormatterPreferences) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig)

Example 5 with GlobalBibtexKeyPattern

use of org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern in project jabref by JabRef.

the class SavePreferences method loadForSaveFromPreferences.

public static SavePreferences loadForSaveFromPreferences(JabRefPreferences preferences) {
    Boolean saveInOriginalOrder = false;
    SaveOrderConfig saveOrder = null;
    Charset encoding = preferences.getDefaultEncoding();
    Boolean makeBackup = preferences.getBoolean(JabRefPreferences.BACKUP);
    DatabaseSaveType saveType = DatabaseSaveType.ALL;
    Boolean takeMetadataSaveOrderInAccount = true;
    Boolean reformatFile = preferences.getBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT);
    LatexFieldFormatterPreferences latexFieldFormatterPreferences = preferences.getLatexFieldFormatterPreferences();
    GlobalBibtexKeyPattern globalCiteKeyPattern = preferences.getKeyPattern();
    return new SavePreferences(saveInOriginalOrder, saveOrder, encoding, makeBackup, saveType, takeMetadataSaveOrderInAccount, reformatFile, latexFieldFormatterPreferences, globalCiteKeyPattern);
}
Also used : GlobalBibtexKeyPattern(org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern) Charset(java.nio.charset.Charset) LatexFieldFormatterPreferences(org.jabref.logic.bibtex.LatexFieldFormatterPreferences) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig)

Aggregations

GlobalBibtexKeyPattern (org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern)8 Charset (java.nio.charset.Charset)2 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)2 AbstractBibtexKeyPattern (org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern)2 SaveOrderConfig (org.jabref.model.metadata.SaveOrderConfig)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ParserResult (org.jabref.logic.importer.ParserResult)1 OS (org.jabref.logic.util.OS)1 Defaults (org.jabref.model.Defaults)1 DatabaseBibtexKeyPattern (org.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern)1 FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)1 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)1 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)1 ContentSelector (org.jabref.model.metadata.ContentSelector)1