From 7f3351917556336cf4280fe7f5e6981beaab2e25 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Tue, 9 Aug 2016 20:34:52 +0200 Subject: [PATCH 1/9] rename labelpattern to bibtexkeypattern --- src/main/java/net/sf/jabref/MetaData.java | 12 +- .../net/sf/jabref/cli/ArgumentProcessor.java | 8 +- .../sf/jabref/external/RegExpFileSearch.java | 6 +- .../java/net/sf/jabref/gui/BasePanel.java | 14 +- .../sf/jabref/gui/BibtexKeyPatternDialog.java | 16 +- .../java/net/sf/jabref/gui/EntryTypeList.java | 4 +- .../net/sf/jabref/gui/FieldSetComponent.java | 4 +- .../sf/jabref/gui/GenFieldsCustomizer.java | 4 +- .../sf/jabref/gui/ImportInspectionDialog.java | 12 +- .../BibtexKeyPatternPanel.java} | 29 +- .../ResolveDuplicateLabelDialog.java | 2 +- .../SearchFixDuplicateLabels.java | 10 +- .../jabref/gui/entryeditor/EntryEditor.java | 10 +- .../gui/openoffice/OpenOfficePanel.java | 9 +- ...fTab.java => BibtexKeyPatternPrefTab.java} | 10 +- .../gui/preftabs/PreferencesDialog.java | 2 +- .../importer/fileformat/EndnoteImporter.java | 4 +- .../importer/fileformat/FreeCiteImporter.java | 8 +- .../BibtexKeyPatternPreferences.java} | 10 +- .../BibtexKeyPatternUtil.java} | 18 +- .../AbstractBibtexKeyPattern.java} | 12 +- .../DatabaseBibtexKeyPattern.java} | 6 +- .../GlobalBibtexKeyPattern.java} | 6 +- .../net/sf/jabref/pdfimport/PdfImporter.java | 8 +- .../jabref/preferences/JabRefPreferences.java | 20 +- .../importer/fileformat/BibtexParserTest.java | 8 +- .../BibtexKeyPatternUtilTest.java} | 338 +++++++++--------- .../exporter/BibtexDatabaseWriterTest.java | 10 +- 28 files changed, 302 insertions(+), 298 deletions(-) rename src/main/java/net/sf/jabref/gui/{labelpattern/LabelPatternPanel.java => bibtexkeypattern/BibtexKeyPatternPanel.java} (89%) rename src/main/java/net/sf/jabref/gui/{labelpattern => bibtexkeypattern}/ResolveDuplicateLabelDialog.java (99%) rename src/main/java/net/sf/jabref/gui/{labelpattern => bibtexkeypattern}/SearchFixDuplicateLabels.java (92%) rename src/main/java/net/sf/jabref/gui/preftabs/{LabelPatternPrefTab.java => BibtexKeyPatternPrefTab.java} (95%) rename src/main/java/net/sf/jabref/logic/{labelpattern/LabelPatternPreferences.java => bibtexkeypattern/BibtexKeyPatternPreferences.java} (79%) rename src/main/java/net/sf/jabref/logic/{labelpattern/LabelPatternUtil.java => bibtexkeypattern/BibtexKeyPatternUtil.java} (98%) rename src/main/java/net/sf/jabref/model/{labelpattern/AbstractLabelPattern.java => bibtexkeypattern/AbstractBibtexKeyPattern.java} (92%) rename src/main/java/net/sf/jabref/model/{labelpattern/DatabaseLabelPattern.java => bibtexkeypattern/DatabaseBibtexKeyPattern.java} (85%) rename src/main/java/net/sf/jabref/model/{labelpattern/GlobalLabelPattern.java => bibtexkeypattern/GlobalBibtexKeyPattern.java} (85%) rename src/test/java/net/sf/jabref/logic/{labelpattern/LabelPatternUtilTest.java => bibtexkeypattern/BibtexKeyPatternUtilTest.java} (52%) diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index 42e4fcae19e..1bdfecc2d65 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -41,10 +41,10 @@ import net.sf.jabref.logic.layout.format.FileLinkPreferences; import net.sf.jabref.logic.util.OS; import net.sf.jabref.logic.util.strings.StringUtil; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.model.labelpattern.AbstractLabelPattern; -import net.sf.jabref.model.labelpattern.DatabaseLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import com.google.common.eventbus.EventBus; import org.apache.commons.logging.Log; @@ -70,7 +70,7 @@ public class MetaData implements Iterable { private GroupTreeNode groupsRoot; private final EventBus eventBus = new EventBus(); - private AbstractLabelPattern labelPattern; + private AbstractBibtexKeyPattern labelPattern; private Charset encoding = Globals.prefs.getDefaultEncoding(); @@ -239,12 +239,12 @@ private static Optional getNextUnit(Reader reader) throws IOException { /** * @return the stored label patterns */ - public AbstractLabelPattern getLabelPattern() { + public AbstractBibtexKeyPattern getLabelPattern() { if (labelPattern != null) { return labelPattern; } - labelPattern = new DatabaseLabelPattern(Globals.prefs); + labelPattern = new DatabaseBibtexKeyPattern(Globals.prefs); // read the data from the metadata and store it into the labelPattern for (String key : this) { @@ -268,7 +268,7 @@ public AbstractLabelPattern getLabelPattern() { * @param labelPattern the key patterns to update to.
* A reference to this object is stored internally and is returned at getLabelPattern(); */ - public void setLabelPattern(AbstractLabelPattern labelPattern) { + public void setLabelPattern(AbstractBibtexKeyPattern labelPattern) { // remove all keypatterns from metadata Iterator iterator = this.iterator(); while (iterator.hasNext()) { diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index 9549565476a..c972f88bcf4 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -35,8 +35,8 @@ import net.sf.jabref.logic.exporter.SavePreferences; import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.logging.JabRefLogger; import net.sf.jabref.logic.search.DatabaseSearcher; import net.sf.jabref.logic.search.SearchQuery; @@ -434,8 +434,8 @@ private void regenerateBibtexKeys(List loaded) { LOGGER.info(Localization.lang("Regenerating BibTeX keys according to metadata")); for (BibEntry entry : database.getEntries()) { // try to make a new label - LabelPatternUtil.makeLabel(metaData, database, entry, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(metaData, database, entry, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); } } else { LOGGER.info(Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys")); diff --git a/src/main/java/net/sf/jabref/external/RegExpFileSearch.java b/src/main/java/net/sf/jabref/external/RegExpFileSearch.java index 2cdfc35a36c..280479f98eb 100644 --- a/src/main/java/net/sf/jabref/external/RegExpFileSearch.java +++ b/src/main/java/net/sf/jabref/external/RegExpFileSearch.java @@ -27,7 +27,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; @@ -331,7 +331,7 @@ public static String getFieldAndFormat(String fieldAndFormat, BibEntry entry, Bi // If no field value was found, try to interpret it as a key generator field marker: String fieldValue = BibDatabase.getResolvedField(beforeColon, entry, database) - .orElse(LabelPatternUtil.makeLabel(entry, beforeColon)); + .orElse(BibtexKeyPatternUtil.makeLabel(entry, beforeColon)); if (fieldValue == null) { return ""; @@ -342,7 +342,7 @@ public static String getFieldAndFormat(String fieldAndFormat, BibEntry entry, Bi } String[] parts = afterColon.split(":"); - fieldValue = LabelPatternUtil.applyModifiers(fieldValue, parts, 0); + fieldValue = BibtexKeyPatternUtil.applyModifiers(fieldValue, parts, 0); return fieldValue; } diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index aa18e8ffa25..537c15b9bf8 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -82,7 +82,7 @@ import net.sf.jabref.gui.groups.GroupTreeNodeViewModel; import net.sf.jabref.gui.journals.AbbreviateAction; import net.sf.jabref.gui.journals.UnabbreviateAction; -import net.sf.jabref.gui.labelpattern.SearchFixDuplicateLabels; +import net.sf.jabref.gui.bibtexkeypattern.SearchFixDuplicateLabels; import net.sf.jabref.gui.maintable.MainTable; import net.sf.jabref.gui.maintable.MainTableDataModel; import net.sf.jabref.gui.maintable.MainTableFormat; @@ -117,8 +117,8 @@ import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Encodings; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; @@ -493,8 +493,8 @@ public void run() { // Finally, set the new keys: for (BibEntry entry : entries) { bes = entry; - LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); ce.addEdit(new UndoableKeyChange(database, bes, (String) oldvals.get(bes), bes.getCiteKeyOptional().orElse(null))); } @@ -1930,8 +1930,8 @@ public void autoGenerateKeysBeforeSaving() { for (BibEntry bes : database.getEntries()) { Optional oldKey = bes.getCiteKeyOptional(); if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) { - LabelPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), database, bes, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); ce.addEdit(new UndoableKeyChange(database, bes, null, bes.getCiteKeyOptional().get())); // Cite key is set here any = true; } diff --git a/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java b/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java index d3ee15777b1..84a1986ee28 100644 --- a/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java +++ b/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java @@ -29,10 +29,10 @@ import javax.swing.WindowConstants; import net.sf.jabref.MetaData; +import net.sf.jabref.gui.bibtexkeypattern.BibtexKeyPatternPanel; import net.sf.jabref.gui.keyboard.KeyBinder; -import net.sf.jabref.gui.labelpattern.LabelPatternPanel; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.labelpattern.AbstractLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import com.jgoodies.forms.builder.ButtonBarBuilder; @@ -40,12 +40,12 @@ public class BibtexKeyPatternDialog extends JDialog { private MetaData metaData; private BasePanel panel; - private final LabelPatternPanel labelPatternPanel; + private final BibtexKeyPatternPanel bibtexKeyPatternPanel; public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) { super(parent, Localization.lang("BibTeX key patterns"), true); - this.labelPatternPanel = new LabelPatternPanel(panel); + this.bibtexKeyPatternPanel = new BibtexKeyPatternPanel(panel); setPanel(panel); init(); } @@ -58,13 +58,13 @@ public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) { public void setPanel(BasePanel panel) { this.panel = panel; this.metaData = panel.getBibDatabaseContext().getMetaData(); - AbstractLabelPattern keypatterns = metaData.getLabelPattern(); - labelPatternPanel.setValues(keypatterns); + AbstractBibtexKeyPattern keypatterns = metaData.getLabelPattern(); + bibtexKeyPatternPanel.setValues(keypatterns); } private void init() { getContentPane().setLayout(new BorderLayout()); - getContentPane().add(labelPatternPanel, BorderLayout.CENTER); + getContentPane().add(bibtexKeyPatternPanel, BorderLayout.CENTER); JButton ok = new JButton(Localization.lang("OK")); JButton cancel = new JButton(); // label of "cancel" is set later as the label is overwritten by assigning an action to the button @@ -84,7 +84,7 @@ private void init() { pack(); ok.addActionListener(e -> { - metaData.setLabelPattern(labelPatternPanel.getLabelPatternAsDatabaseLabelPattern()); + metaData.setLabelPattern(bibtexKeyPatternPanel.getLabelPatternAsDatabaseLabelPattern()); panel.markNonUndoableBaseChanged(); dispose(); }); diff --git a/src/main/java/net/sf/jabref/gui/EntryTypeList.java b/src/main/java/net/sf/jabref/gui/EntryTypeList.java index 02fa3687f0b..8ea36b49292 100644 --- a/src/main/java/net/sf/jabref/gui/EntryTypeList.java +++ b/src/main/java/net/sf/jabref/gui/EntryTypeList.java @@ -28,7 +28,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.model.EntryTypes; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.CustomEntryType; @@ -72,7 +72,7 @@ protected void addField(String str) { return; } - String testString = LabelPatternUtil.checkLegalKey(s, + String testString = BibtexKeyPatternUtil.checkLegalKey(s, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if (!testString.equals(s) || (s.indexOf('&') >= 0)) { // Report error and exit. diff --git a/src/main/java/net/sf/jabref/gui/FieldSetComponent.java b/src/main/java/net/sf/jabref/gui/FieldSetComponent.java index 1586d19dd65..f4f9f2a8493 100644 --- a/src/main/java/net/sf/jabref/gui/FieldSetComponent.java +++ b/src/main/java/net/sf/jabref/gui/FieldSetComponent.java @@ -48,7 +48,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.preferences.JabRefPreferences; /** @@ -247,7 +247,7 @@ protected void addField(String str) { return; } - String testString = LabelPatternUtil.checkLegalKey(s, + String testString = BibtexKeyPatternUtil.checkLegalKey(s, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if (!testString.equals(s) || (s.indexOf('&') >= 0)) { // Report error and exit. diff --git a/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java b/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java index 80781abf51d..2e1ef763165 100644 --- a/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java @@ -41,7 +41,7 @@ import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; @@ -136,7 +136,7 @@ private void okActionPerformed() { Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); return; } - String testString = LabelPatternUtil.checkLegalKey(parts[1], + String testString = BibtexKeyPatternUtil.checkLegalKey(parts[1], Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if (!testString.equals(parts[1]) || (parts[1].indexOf('&') >= 0)) { // Report error and exit. diff --git a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java index 4790b5fdfc8..f466a07b212 100644 --- a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java +++ b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java @@ -91,8 +91,8 @@ import net.sf.jabref.logic.groups.GroupTreeNode; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.model.DuplicateCheck; import net.sf.jabref.model.database.BibDatabase; @@ -463,8 +463,8 @@ private void generateKeySelectedEntry() { database.insertEntry(entry); // Generate a unique key: - LabelPatternUtil.makeLabel(localMetaData, database, entry, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(localMetaData, database, entry, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); // Remove the entry from the database again, since we only added it in // order to // make sure the key was unique: @@ -505,8 +505,8 @@ private void generateKeys() { entry.setId(IdGenerator.next()); database.insertEntry(entry); - LabelPatternUtil.makeLabel(localMetaData, database, entry, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(localMetaData, database, entry, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); // Add the generated key to our list: -- TODO: Why?? keys.add(entry.getCiteKeyOptional()); } diff --git a/src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java similarity index 89% rename from src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java rename to src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index 4b292aa8986..9fb74d4ae32 100644 --- a/src/main/java/net/sf/jabref/gui/labelpattern/LabelPatternPanel.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.gui.labelpattern; +package net.sf.jabref.gui.bibtexkeypattern; import java.awt.Container; import java.awt.Dimension; @@ -40,14 +40,14 @@ import net.sf.jabref.model.EntryTypes; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.EntryType; -import net.sf.jabref.model.labelpattern.AbstractLabelPattern; -import net.sf.jabref.model.labelpattern.DatabaseLabelPattern; -import net.sf.jabref.model.labelpattern.GlobalLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import net.sf.jabref.preferences.JabRefPreferences; -public class LabelPatternPanel extends JPanel { +public class BibtexKeyPatternPanel extends JPanel { - // used by both LabelPatternPanel and TabLabelPAttern + // used by both BibtexKeyPatternPanel and TabLabelPAttern protected final GridBagLayout gbl = new GridBagLayout(); protected final GridBagConstraints con = new GridBagConstraints(); @@ -61,7 +61,7 @@ public class LabelPatternPanel extends JPanel { private final BasePanel panel; - public LabelPatternPanel(BasePanel panel) { + public BibtexKeyPatternPanel(BasePanel panel) { this.panel = panel; help = new HelpAction(Localization.lang("Help on key patterns"), HelpFile.LABEL_PATTERN); buildGUI(); @@ -222,7 +222,7 @@ private JTextField addEntryType(Container c, EntryType type, int y) { /** * fill the given LabelPattern by values generated from the text fields */ - private void fillPatternUsingPanelData(AbstractLabelPattern keypatterns) { + private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) { // each entry type for (Map.Entry entry : textFields.entrySet()) { String text = entry.getValue().getText(); @@ -238,14 +238,15 @@ private void fillPatternUsingPanelData(AbstractLabelPattern keypatterns) { } } - protected GlobalLabelPattern getLabelPatternAsGlobalLabelPattern() { - GlobalLabelPattern res = new GlobalLabelPattern(AbstractLabelPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); + protected GlobalBibtexKeyPattern getLabelPatternAsGlobalLabelPattern() { + GlobalBibtexKeyPattern res = new GlobalBibtexKeyPattern( + AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); fillPatternUsingPanelData(res); return res; } - public DatabaseLabelPattern getLabelPatternAsDatabaseLabelPattern() { - DatabaseLabelPattern res = new DatabaseLabelPattern(Globals.prefs); + public DatabaseBibtexKeyPattern getLabelPatternAsDatabaseLabelPattern() { + DatabaseBibtexKeyPattern res = new DatabaseBibtexKeyPattern(Globals.prefs); fillPatternUsingPanelData(res); return res; } @@ -255,7 +256,7 @@ public DatabaseLabelPattern getLabelPatternAsDatabaseLabelPattern() { * * @param keypatterns the LabelPattern to use as initial value */ - public void setValues(AbstractLabelPattern keypatterns) { + public void setValues(AbstractBibtexKeyPattern keypatterns) { for (Map.Entry entry : textFields.entrySet()) { setValue(entry.getValue(), entry.getKey(), keypatterns); } @@ -267,7 +268,7 @@ public void setValues(AbstractLabelPattern keypatterns) { } } - private static void setValue(JTextField tf, String fieldName, AbstractLabelPattern keypatterns) { + private static void setValue(JTextField tf, String fieldName, AbstractBibtexKeyPattern keypatterns) { if (keypatterns.isDefaultValue(fieldName)) { tf.setText(""); } else { diff --git a/src/main/java/net/sf/jabref/gui/labelpattern/ResolveDuplicateLabelDialog.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java similarity index 99% rename from src/main/java/net/sf/jabref/gui/labelpattern/ResolveDuplicateLabelDialog.java rename to src/main/java/net/sf/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java index 7712be898b6..a8c0a3c01b2 100644 --- a/src/main/java/net/sf/jabref/gui/labelpattern/ResolveDuplicateLabelDialog.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/ResolveDuplicateLabelDialog.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.gui.labelpattern; +package net.sf.jabref.gui.bibtexkeypattern; import java.awt.BorderLayout; import java.awt.Dimension; diff --git a/src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java similarity index 92% rename from src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java rename to src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java index 515b89f173f..8274098ccda 100644 --- a/src/main/java/net/sf/jabref/gui/labelpattern/SearchFixDuplicateLabels.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.gui.labelpattern; +package net.sf.jabref.gui.bibtexkeypattern; import java.util.ArrayList; import java.util.HashMap; @@ -28,8 +28,8 @@ import net.sf.jabref.gui.undo.UndoableKeyChange; import net.sf.jabref.gui.worker.AbstractWorker; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; @@ -111,8 +111,8 @@ public void update() { NamedCompound ce = new NamedCompound(Localization.lang("Resolve duplicate BibTeX keys")); for (BibEntry entry : toGenerateFor) { String oldKey = entry.getCiteKey(); - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); ce.addEdit(new UndoableKeyChange(panel.getDatabase(), entry, oldKey, entry.getCiteKey())); } ce.end(); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 553af4289dc..6015a4157c8 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -99,8 +99,8 @@ import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.search.SearchQueryHighlightListener; import net.sf.jabref.logic.util.date.TimeStamp; import net.sf.jabref.model.EntryTypes; @@ -1114,7 +1114,7 @@ public void actionPerformed(ActionEvent event) { } // Make sure the key is legal: - String cleaned = LabelPatternUtil.checkLegalKey(newValue, + String cleaned = BibtexKeyPatternUtil.checkLegalKey(newValue, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); if ((cleaned == null) || cleaned.equals(newValue)) { textField.setValidBackgroundColor(); @@ -1381,8 +1381,8 @@ public void actionPerformed(ActionEvent e) { } } - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); // Store undo information: panel.getUndoManager().addEdit( diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java index e7bb8691461..6ddd8786e84 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -62,8 +62,8 @@ import net.sf.jabref.gui.worker.AbstractWorker; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.openoffice.OOBibStyle; import net.sf.jabref.logic.openoffice.OpenOfficePreferences; @@ -706,12 +706,13 @@ private boolean checkThatEntriesHaveKeys(List entries) { BasePanel panel = frame.getCurrentBasePanel(); if ((answer == JOptionPane.OK_OPTION) && (panel != null)) { // Generate keys - LabelPatternPreferences prefs = LabelPatternPreferences.fromPreferences(Globals.prefs); + BibtexKeyPatternPreferences prefs = BibtexKeyPatternPreferences.fromPreferences(Globals.prefs); NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite")); for (BibEntry entry : entries) { if (entry.getCiteKey() == null) { // Generate key - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + BibtexKeyPatternUtil + .makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, prefs); // Add undo change undoCompound.addEdit(new UndoableKeyChange(panel.getDatabase(), entry, null, entry.getCiteKey())); diff --git a/src/main/java/net/sf/jabref/gui/preftabs/LabelPatternPrefTab.java b/src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java similarity index 95% rename from src/main/java/net/sf/jabref/gui/preftabs/LabelPatternPrefTab.java rename to src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java index 327f77339e9..a57e35c98b8 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/LabelPatternPrefTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java @@ -26,9 +26,9 @@ import net.sf.jabref.Globals; import net.sf.jabref.gui.BasePanel; -import net.sf.jabref.gui.labelpattern.LabelPatternPanel; +import net.sf.jabref.gui.bibtexkeypattern.BibtexKeyPatternPanel; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.labelpattern.GlobalLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import net.sf.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.DefaultFormBuilder; @@ -37,7 +37,7 @@ /** * The Preferences panel for key generation. */ -class LabelPatternPrefTab extends LabelPatternPanel implements PrefsTab { +class BibtexKeyPatternPrefTab extends BibtexKeyPatternPanel implements PrefsTab { private final JabRefPreferences prefs; @@ -54,7 +54,7 @@ class LabelPatternPrefTab extends LabelPatternPanel implements PrefsTab { private final JTextField keyPatternReplacement = new JTextField(20); - public LabelPatternPrefTab(JabRefPreferences prefs, BasePanel panel) { + public BibtexKeyPatternPrefTab(JabRefPreferences prefs, BasePanel panel) { super(panel); this.prefs = prefs; appendKeyGeneratorSettings(); @@ -90,7 +90,7 @@ public void storeSettings() { } // fetch entries from GUI - GlobalLabelPattern keypatterns = getLabelPatternAsGlobalLabelPattern(); + GlobalBibtexKeyPattern keypatterns = getLabelPatternAsGlobalLabelPattern(); // store new patterns globally prefs.putKeyPattern(keypatterns); } diff --git a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java index 3c0caf18e11..81b47dbc89b 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/PreferencesDialog.java @@ -103,7 +103,7 @@ public PreferencesDialog(JabRefFrame parent) { tabs.add(new ExternalTab(frame, this, prefs)); tabs.add(new TablePrefsTab(prefs)); tabs.add(new TableColumnsTab(prefs, parent)); - tabs.add(new LabelPatternPrefTab(prefs, parent.getCurrentBasePanel())); + tabs.add(new BibtexKeyPatternPrefTab(prefs, parent.getCurrentBasePanel())); tabs.add(new PreviewPrefsTab(prefs)); tabs.add(new NameFormatterTab(prefs)); tabs.add(new ImportSettingsTab(prefs)); diff --git a/src/main/java/net/sf/jabref/importer/fileformat/EndnoteImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/EndnoteImporter.java index 916b2a4013c..4bda12068b2 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/EndnoteImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/EndnoteImporter.java @@ -26,7 +26,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.importer.ParserResult; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.model.entry.AuthorList; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.FieldName; @@ -238,7 +238,7 @@ else if ("P".equals(prefix)) { type = "mastersthesis"; } } else if ("F".equals(prefix)) { - hm.put(BibEntry.KEY_FIELD, LabelPatternUtil.checkLegalKey(val, + hm.put(BibEntry.KEY_FIELD, BibtexKeyPatternUtil.checkLegalKey(val, Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY))); } } diff --git a/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java index 5bd6d96dc6e..d4ceeafa0fb 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java @@ -39,8 +39,8 @@ import net.sf.jabref.JabRefGUI; import net.sf.jabref.importer.ParserResult; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.BibtexEntryTypes; @@ -216,10 +216,10 @@ public ParserResult importEntries(String text) { e.setType(type); // autogenerate label (BibTeX key) - LabelPatternUtil.makeLabel( + BibtexKeyPatternUtil.makeLabel( JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext().getMetaData(), JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabase(), e, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); res.add(e); } diff --git a/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternPreferences.java b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java similarity index 79% rename from src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternPreferences.java rename to src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java index fadb6eb9bfc..e6f49381b0a 100644 --- a/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternPreferences.java +++ b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java @@ -1,8 +1,8 @@ -package net.sf.jabref.logic.labelpattern; +package net.sf.jabref.logic.bibtexkeypattern; import net.sf.jabref.preferences.JabRefPreferences; -public class LabelPatternPreferences { +public class BibtexKeyPatternPreferences { private final String defaultLabelPattern; private final String keyPatternRegex; @@ -11,7 +11,7 @@ public class LabelPatternPreferences { private final boolean firstLetterA; private final boolean enforceLegalKey; - public LabelPatternPreferences(String defaultLabelPattern, String keyPatternRegex, String keyPatternReplacement, + public BibtexKeyPatternPreferences(String defaultLabelPattern, String keyPatternRegex, String keyPatternReplacement, boolean alwaysAddLetter, boolean firstLetterA, boolean enforceLegalKey) { this.defaultLabelPattern = defaultLabelPattern; this.keyPatternRegex = keyPatternRegex; @@ -21,8 +21,8 @@ public LabelPatternPreferences(String defaultLabelPattern, String keyPatternRege this.enforceLegalKey = enforceLegalKey; } - public static LabelPatternPreferences fromPreferences(JabRefPreferences jabRefPreferences) { - return new LabelPatternPreferences(jabRefPreferences.get(JabRefPreferences.DEFAULT_LABEL_PATTERN), + public static BibtexKeyPatternPreferences fromPreferences(JabRefPreferences jabRefPreferences) { + return new BibtexKeyPatternPreferences(jabRefPreferences.get(JabRefPreferences.DEFAULT_LABEL_PATTERN), jabRefPreferences.get(JabRefPreferences.KEY_PATTERN_REGEX), jabRefPreferences.get(JabRefPreferences.KEY_PATTERN_REPLACEMENT), jabRefPreferences.getBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER), diff --git a/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java similarity index 98% rename from src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java rename to src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java index c61bd5ceaed..e81d0de97ac 100644 --- a/src/main/java/net/sf/jabref/logic/labelpattern/LabelPatternUtil.java +++ b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java @@ -15,7 +15,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.logic.labelpattern; +package net.sf.jabref.logic.bibtexkeypattern; import java.util.ArrayList; import java.util.Arrays; @@ -41,14 +41,14 @@ /** * This is the utility class of the LabelPattern package. */ -public class LabelPatternUtil { +public class BibtexKeyPatternUtil { private static final String STARTING_CAPITAL_PATTERN = "[^A-Z]"; // All single characters that we can use for extending a key to make it unique: private static final String CHARS = "abcdefghijklmnopqrstuvwxyz"; - private static final Log LOGGER = LogFactory.getLog(LabelPatternUtil.class); + private static final Log LOGGER = LogFactory.getLog(BibtexKeyPatternUtil.class); private static final Pattern REGEX_PATTERN = Pattern.compile(".*\\(\\{([A-Z]+)\\}\\).*"); @@ -390,7 +390,7 @@ private static String generateInstitutionKey(String content) { * @return modified BibEntry */ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entry, - LabelPatternPreferences labelPatternPreferences) { + BibtexKeyPatternPreferences bibtexKeyPatternPreferences) { database = dBase; String key; StringBuilder stringBuilder = new StringBuilder(); @@ -434,12 +434,12 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr } // Remove all illegal characters from the key. - key = checkLegalKey(stringBuilder.toString(), labelPatternPreferences.isEnforceLegalKey()); + key = checkLegalKey(stringBuilder.toString(), bibtexKeyPatternPreferences.isEnforceLegalKey()); // Remove Regular Expressions while generating Keys - String regex = labelPatternPreferences.getKeyPatternRegex(); + String regex = bibtexKeyPatternPreferences.getKeyPatternRegex(); if ((regex != null) && !regex.trim().isEmpty()) { - String replacement = labelPatternPreferences.getKeyPatternReplacement(); + String replacement = bibtexKeyPatternPreferences.getKeyPatternReplacement(); key = key.replaceAll(regex, replacement); } @@ -457,8 +457,8 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr occurrences--; // No change, so we can accept one dupe. } - boolean alwaysAddLetter = labelPatternPreferences.isAlwaysAddLetter(); - boolean firstLetterA = labelPatternPreferences.isFirstLetterA(); + boolean alwaysAddLetter = bibtexKeyPatternPreferences.isAlwaysAddLetter(); + boolean firstLetterA = bibtexKeyPatternPreferences.isFirstLetterA(); if (!alwaysAddLetter && (occurrences == 0)) { // No dupes found, so we can just go ahead. diff --git a/src/main/java/net/sf/jabref/model/labelpattern/AbstractLabelPattern.java b/src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java similarity index 92% rename from src/main/java/net/sf/jabref/model/labelpattern/AbstractLabelPattern.java rename to src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java index ad8bc5d448b..04643176ebc 100644 --- a/src/main/java/net/sf/jabref/model/labelpattern/AbstractLabelPattern.java +++ b/src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java @@ -15,7 +15,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.model.labelpattern; +package net.sf.jabref.model.bibtexkeypattern; import java.util.ArrayList; import java.util.HashMap; @@ -29,19 +29,19 @@ * A small table, where an entry type is associated with a label pattern (an * ArrayList). A parent LabelPattern can be set. */ -public abstract class AbstractLabelPattern { +public abstract class AbstractBibtexKeyPattern { protected List defaultPattern; protected Map> data = new HashMap<>(); public void addLabelPattern(String type, String pattern) { - data.put(type, AbstractLabelPattern.split(pattern)); + data.put(type, AbstractBibtexKeyPattern.split(pattern)); } @Override public String toString() { - final StringBuilder sb = new StringBuilder("AbstractLabelPattern{"); + final StringBuilder sb = new StringBuilder("AbstractBibtexKeyPattern{"); sb.append("defaultPattern=").append(defaultPattern); sb.append(", data=").append(data); sb.append('}'); @@ -56,7 +56,7 @@ public boolean equals(Object o) { if ((o == null) || (getClass() != o.getClass())) { return false; } - AbstractLabelPattern that = (AbstractLabelPattern) o; + AbstractBibtexKeyPattern that = (AbstractBibtexKeyPattern) o; return Objects.equals(defaultPattern, that.defaultPattern) && Objects.equals(data, that.data); } @@ -148,7 +148,7 @@ public List getDefaultValue() { * @param labelPattern the pattern to store */ public void setDefaultValue(String labelPattern) { - this.defaultPattern = AbstractLabelPattern.split(labelPattern); + this.defaultPattern = AbstractBibtexKeyPattern.split(labelPattern); } public Set getAllKeys() { diff --git a/src/main/java/net/sf/jabref/model/labelpattern/DatabaseLabelPattern.java b/src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java similarity index 85% rename from src/main/java/net/sf/jabref/model/labelpattern/DatabaseLabelPattern.java rename to src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java index bf8f453f1aa..197650713a8 100644 --- a/src/main/java/net/sf/jabref/model/labelpattern/DatabaseLabelPattern.java +++ b/src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java @@ -13,18 +13,18 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.model.labelpattern; +package net.sf.jabref.model.bibtexkeypattern; import java.util.List; import net.sf.jabref.preferences.JabRefPreferences; -public class DatabaseLabelPattern extends AbstractLabelPattern { +public class DatabaseBibtexKeyPattern extends AbstractBibtexKeyPattern { private final JabRefPreferences prefs; - public DatabaseLabelPattern(JabRefPreferences prefs) { + public DatabaseBibtexKeyPattern(JabRefPreferences prefs) { this.prefs = prefs; } diff --git a/src/main/java/net/sf/jabref/model/labelpattern/GlobalLabelPattern.java b/src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java similarity index 85% rename from src/main/java/net/sf/jabref/model/labelpattern/GlobalLabelPattern.java rename to src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java index 0462acb6461..dc3d4c70dc6 100644 --- a/src/main/java/net/sf/jabref/model/labelpattern/GlobalLabelPattern.java +++ b/src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java @@ -13,15 +13,15 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.model.labelpattern; +package net.sf.jabref.model.bibtexkeypattern; import java.util.List; -public class GlobalLabelPattern extends AbstractLabelPattern { +public class GlobalBibtexKeyPattern extends AbstractBibtexKeyPattern { private List defaultLabelPattern; - public GlobalLabelPattern(List labelPattern) { + public GlobalBibtexKeyPattern(List labelPattern) { defaultLabelPattern = labelPattern; } diff --git a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java index 23b51031bac..5fff98a9a6d 100644 --- a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java @@ -40,8 +40,8 @@ import net.sf.jabref.importer.fileformat.PdfContentImporter; import net.sf.jabref.importer.fileformat.PdfXmpImporter; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; -import net.sf.jabref.logic.labelpattern.LabelPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.logic.xmp.XMPPreferences; @@ -252,8 +252,8 @@ private void doContentImport(String fileName, List res) { // insert entry to database and link file panel.getDatabase().insertEntry(entry); panel.markBaseChanged(); - LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, - LabelPatternPreferences.fromPreferences(Globals.prefs)); + BibtexKeyPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + BibtexKeyPatternPreferences.fromPreferences(Globals.prefs)); DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entry); panel.highlightEntry(entry); diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 92311f21579..3516621a7b0 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -79,8 +79,8 @@ import net.sf.jabref.model.entry.CustomEntryType; import net.sf.jabref.model.entry.EntryUtil; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.model.labelpattern.AbstractLabelPattern; -import net.sf.jabref.model.labelpattern.GlobalLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import net.sf.jabref.specialfields.SpecialFieldsUtils; import org.apache.commons.logging.Log; @@ -292,7 +292,7 @@ public class JabRefPreferences { public static final String USE_DEFAULT_CONSOLE_APPLICATION = "useDefaultConsoleApplication"; // Currently, it is not possible to specify defaults for specific entry types - // When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.LabelPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getLabelPattern(); etc + // When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getLabelPattern(); etc public static final String DEFAULT_LABEL_PATTERN = "defaultLabelPattern"; public static final String SEARCH_MODE_FLOAT = "floatSearch"; @@ -420,7 +420,7 @@ public class JabRefPreferences { private final Preferences prefs; private final Set nonWrappableFields = new HashSet<>(5); - private GlobalLabelPattern keyPattern; + private GlobalBibtexKeyPattern keyPattern; // Object containing custom export formats: public final CustomExportList customExports; @@ -1138,9 +1138,9 @@ public void flush() { * * @return LabelPattern containing all keys. Returned LabelPattern has no parent */ - public GlobalLabelPattern getKeyPattern() { - keyPattern = new GlobalLabelPattern(AbstractLabelPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); - Preferences pre = Preferences.userNodeForPackage(GlobalLabelPattern.class); + public GlobalBibtexKeyPattern getKeyPattern() { + keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); + Preferences pre = Preferences.userNodeForPackage(GlobalBibtexKeyPattern.class); try { String[] keys = pre.keys(); if (keys.length > 0) { @@ -1159,11 +1159,11 @@ public GlobalLabelPattern getKeyPattern() { * * @param pattern the pattern to store */ - public void putKeyPattern(GlobalLabelPattern pattern) { + public void putKeyPattern(GlobalBibtexKeyPattern pattern) { keyPattern = pattern; // Store overridden definitions to Preferences. - Preferences pre = Preferences.userNodeForPackage(GlobalLabelPattern.class); + Preferences pre = Preferences.userNodeForPackage(GlobalBibtexKeyPattern.class); try { pre.clear(); // We remove all old entries. } catch (BackingStoreException ex) { @@ -1175,7 +1175,7 @@ public void putKeyPattern(GlobalLabelPattern pattern) { if (!pattern.isDefaultValue(key)) { // no default value // the first entry in the array is the full pattern - // see net.sf.jabref.logic.labelPattern.LabelPatternUtil.split(String) + // see net.sf.jabref.logic.labelPattern.BibtexKeyPatternUtil.split(String) pre.put(key, pattern.getValue(key).get(0)); } } diff --git a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java index 905ee4966f7..7b157d014ab 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java @@ -25,12 +25,12 @@ import net.sf.jabref.logic.groups.GroupTreeNode; import net.sf.jabref.logic.groups.KeywordGroup; import net.sf.jabref.logic.util.OS; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.BibtexString; import net.sf.jabref.model.entry.EntryType; -import net.sf.jabref.model.labelpattern.AbstractLabelPattern; -import net.sf.jabref.model.labelpattern.DatabaseLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.BeforeClass; @@ -1393,9 +1393,9 @@ public void integrationTestCustomKeyPattern() throws IOException { + OS.NEWLINE + "@comment{jabref-meta: keypatterndefault:test;}")); - AbstractLabelPattern labelPattern = result.getMetaData().getLabelPattern(); + AbstractBibtexKeyPattern labelPattern = result.getMetaData().getLabelPattern(); - AbstractLabelPattern expectedPattern = new DatabaseLabelPattern(Globals.prefs); + AbstractBibtexKeyPattern expectedPattern = new DatabaseBibtexKeyPattern(Globals.prefs); expectedPattern.setDefaultValue("test"); expectedPattern.addLabelPattern("article", "articleTest"); diff --git a/src/test/java/net/sf/jabref/logic/labelpattern/LabelPatternUtilTest.java b/src/test/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java similarity index 52% rename from src/test/java/net/sf/jabref/logic/labelpattern/LabelPatternUtilTest.java rename to src/test/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java index 84c74104b85..a0f13a8198f 100644 --- a/src/test/java/net/sf/jabref/logic/labelpattern/LabelPatternUtilTest.java +++ b/src/test/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtilTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.logic.labelpattern; +package net.sf.jabref.logic.bibtexkeypattern; import net.sf.jabref.Globals; import net.sf.jabref.importer.fileformat.BibtexParser; @@ -13,7 +13,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -public class LabelPatternUtilTest { +public class BibtexKeyPatternUtilTest { private static final String AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1 = "Isaac Newton"; private static final String AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2 = "Isaac Newton and James Maxwell"; @@ -45,13 +45,13 @@ public static void setUpGlobalsPrefs() { @Before public void setUp() { - LabelPatternUtil.setDataBase(new BibDatabase()); + BibtexKeyPatternUtil.setDataBase(new BibDatabase()); } @Test public void testAndInAuthorName() { BibEntry entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Simon Holland}}"); - assertEquals("Holland", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth"), true)); + assertEquals("Holland", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth"), true)); } @Test @@ -59,13 +59,14 @@ public void testAndAuthorNames() { String bibtexString = "@ARTICLE{whatevery, author={Mari D. Herland and Mona-Iren Hauge and Ingeborg M. Helgeland}}"; BibEntry entry = BibtexParser.singleFromString(bibtexString); assertEquals("HerlandHaugeHelgeland", - LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry, "authors3"), true)); + BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry, "authors3"), true)); } @Test public void testSpecialLatexCharacterInAuthorName() { BibEntry entry = BibtexParser.singleFromString("@ARTICLE{kohn, author={Simon Popovi\\v{c}ov\\'{a}}}"); - assertEquals("Popovicova", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry, "auth"), true)); + assertEquals("Popovicova", BibtexKeyPatternUtil + .checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry, "auth"), true)); } /** @@ -75,40 +76,40 @@ public void testSpecialLatexCharacterInAuthorName() { @Test public void testMakeLabelAndCheckLegalKeys() { BibEntry entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Köning}, year={2000}}"); - assertEquals("Koen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Koen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Áöning}, year={2000}}"); - assertEquals("Aoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Aoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Éöning}, year={2000}}"); - assertEquals("Eoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Eoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Íöning}, year={2000}}"); - assertEquals("Ioen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Ioen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ĺöning}, year={2000}}"); - assertEquals("Loen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Loen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ńöning}, year={2000}}"); - assertEquals("Noen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Noen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Óöning}, year={2000}}"); - assertEquals("Ooen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Ooen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ŕöning}, year={2000}}"); - assertEquals("Roen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Roen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Śöning}, year={2000}}"); - assertEquals("Soen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Soen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Úöning}, year={2000}}"); - assertEquals("Uoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Uoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ýöning}, year={2000}}"); - assertEquals("Yoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Yoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Źöning}, year={2000}}"); - assertEquals("Zoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Zoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); } /** @@ -117,26 +118,26 @@ public void testMakeLabelAndCheckLegalKeys() { @Test public void testMakeLabelAndCheckLegalKeysAccentGrave() { BibEntry entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Àöning}, year={2000}}"); - assertEquals("Aoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Aoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Èöning}, year={2000}}"); - assertEquals("Eoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Eoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ìöning}, year={2000}}"); - assertEquals("Ioen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Ioen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Òöning}, year={2000}}"); - assertEquals("Ooen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Ooen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); entry0 = BibtexParser.singleFromString("@ARTICLE{kohn, author={Andreas Ùöning}, year={2000}}"); - assertEquals("Uoen", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry0, "auth3"), true)); + assertEquals("Uoen", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry0, "auth3"), true)); } /** * Tests if checkLegalKey replaces Non-ASCII chars. * There are quite a few chars that should be replaced. Perhaps there is a better method than the current. * - * @see LabelPatternUtil#checkLegalKey(String) + * @see BibtexKeyPatternUtil#checkLegalKey(String) */ @Test public void testCheckLegalKey() { @@ -147,43 +148,43 @@ public void testCheckLegalKey() { //"Ł ł Ő ő Ű ű Ŀ ŀ Ħ ħ Ð ð Þ þ Œ œ Æ æ Ø ø Å å Ə ə String accents = "ÀàÈèÌìÒòÙù  â Ĉ ĉ Ê ê Ĝ ĝ Ĥ ĥ Î î Ĵ ĵ Ô ô Ŝ ŝ Û û Ŵ ŵ Ŷ ŷ"; String expectedResult = "AaEeIiOoUuAaCcEeGgHhIiJjOoSsUuWwYy"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "ÄäËëÏïÖöÜüŸÿ"; expectedResult = "AeaeEeIiOeoeUeueYy"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ç ç Ģ ģ Ķ ķ Ļ ļ Ņ ņ Ŗ ŗ Ş ş Ţ ţ"; expectedResult = "CcGgKkLlNnRrSsTt"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ă ă Ĕ ĕ Ğ ğ Ĭ ĭ Ŏ ŏ Ŭ ŭ"; expectedResult = "AaEeGgIiOoUu"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ċ ċ Ė ė Ġ ġ İ ı Ż ż"; expectedResult = "CcEeGgIiZz"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ą ą Ę ę Į į Ǫ ǫ Ų ų"; expectedResult = "AaEeIiOoUu"; // O or Q? o or q? - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ā ā Ē ē Ī ī Ō ō Ū ū Ȳ ȳ"; expectedResult = "AaEeIiOoUuYy"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ǎ ǎ Č č Ď ď Ě ě Ǐ ǐ Ľ ľ Ň ň Ǒ ǒ Ř ř Š š Ť ť Ǔ ǔ Ž ž"; expectedResult = "AaCcDdEeIiLlNnOoRrSsTtUuZz"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); expectedResult = "AaEeIiNnOoUuYy"; accents = "ÃãẼẽĨĩÑñÕõŨũỸỹ"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); accents = "Ḍ ḍ Ḥ ḥ Ḷ ḷ Ḹ ḹ Ṃ ṃ Ṇ ṇ Ṛ ṛ Ṝ ṝ Ṣ ṣ Ṭ ṭ"; expectedResult = "DdHhLlLlMmNnRrRrSsTt"; - assertEquals(expectedResult, LabelPatternUtil.checkLegalKey(accents, true)); + assertEquals(expectedResult, BibtexKeyPatternUtil.checkLegalKey(accents, true)); String totest = "À à È è Ì ì Ò ò Ù ù  â Ĉ ĉ Ê ê Ĝ ĝ Ĥ ĥ Î î Ĵ ĵ Ô ô Ŝ ŝ Û û Ŵ ŵ Ŷ ŷ Ä ä Ë ë Ï ï Ö ö Ü ü Ÿ ÿ " + "à ã Ẽ ẽ Ĩ ĩ Ñ ñ Õ õ Ũ ũ Ỹ ỹ Ç ç Ģ ģ Ķ ķ Ļ ļ Ņ ņ Ŗ ŗ Ş ş Ţ ţ" @@ -197,33 +198,34 @@ public void testCheckLegalKey() { "AaEeGgIiOoUu" + "CcEeGgIiZzAaEeIiOoUu" + "DdHhLlLlMmNnRrRrSsTt"; - assertEquals(expectedResults, LabelPatternUtil.checkLegalKey(totest, true)); + assertEquals(expectedResults, BibtexKeyPatternUtil.checkLegalKey(totest, true)); } @Test public void testFirstAuthor() { assertEquals( "Newton", - LabelPatternUtil + BibtexKeyPatternUtil .firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); - assertEquals("Newton", LabelPatternUtil.firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + assertEquals("Newton", BibtexKeyPatternUtil.firstAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); // https://sourceforge.net/forum/message.php?msg_id=4498555 - assertEquals("K{\\\"o}ning", LabelPatternUtil + assertEquals("K{\\\"o}ning", BibtexKeyPatternUtil .firstAuthor("K{\\\"o}ning")); - assertEquals("", LabelPatternUtil.firstAuthor("")); + assertEquals("", BibtexKeyPatternUtil.firstAuthor("")); } @Test(expected = NullPointerException.class) public void testFirstAuthorNull() { - LabelPatternUtil.firstAuthor(null); + BibtexKeyPatternUtil.firstAuthor(null); } @Test public void testUniversity() { BibEntry entry = BibtexParser.singleFromString("@ARTICLE{kohn, author={{Link{\\\"{o}}ping University}}}"); - assertEquals("UniLinkoeping", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry, "auth"), true)); + assertEquals("UniLinkoeping", BibtexKeyPatternUtil + .checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry, "auth"), true)); } @Test @@ -232,7 +234,7 @@ public void testDepartment() { .singleFromString( "@ARTICLE{kohn, author={{Link{\\\"{o}}ping University, Department of Electrical Engineering}}}"); assertEquals("UniLinkoepingEE", - LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry, "auth"), true)); + BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry, "auth"), true)); } @Test @@ -240,44 +242,44 @@ public void testSchool() { BibEntry entry = BibtexParser.singleFromString( "@ARTICLE{kohn, author={{Link{\\\"{o}}ping University, School of Computer Engineering}}}"); assertEquals("UniLinkoepingCE", - LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry, "auth"), true)); + BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry, "auth"), true)); } @Test public void testInstituteOfTechnology() { BibEntry entry = BibtexParser .singleFromString("@ARTICLE{kohn, author={{Massachusetts Institute of Technology}}}"); - assertEquals("MIT", LabelPatternUtil.checkLegalKey(LabelPatternUtil.makeLabel(entry, "auth"), true)); + assertEquals("MIT", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry, "auth"), true)); } @Test public void testAuthIniN() { assertEquals( "NMEB", - LabelPatternUtil + BibtexKeyPatternUtil .authIniN( AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 4)); - assertEquals("NMEB", LabelPatternUtil.authIniN( + assertEquals("NMEB", BibtexKeyPatternUtil.authIniN( AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 4)); - assertEquals("NeME", LabelPatternUtil.authIniN( + assertEquals("NeME", BibtexKeyPatternUtil.authIniN( AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 4)); - assertEquals("NeMa", LabelPatternUtil.authIniN( + assertEquals("NeMa", BibtexKeyPatternUtil.authIniN( AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 4)); - assertEquals("Newt", LabelPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 4)); + assertEquals("Newt", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 4)); assertEquals("", ""); - assertEquals("N", LabelPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); - assertEquals("", LabelPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 0)); - assertEquals("", LabelPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, -1)); + assertEquals("N", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); + assertEquals("", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 0)); + assertEquals("", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, -1)); - assertEquals("Newton", LabelPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 6)); - assertEquals("Newton", LabelPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 7)); + assertEquals("Newton", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 6)); + assertEquals("Newton", BibtexKeyPatternUtil.authIniN(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 7)); } @Test(expected = NullPointerException.class) public void testAuthIniNNull() { - LabelPatternUtil.authIniN(null, 3); + BibtexKeyPatternUtil.authIniN(null, 3); } /** @@ -285,10 +287,10 @@ public void testAuthIniNNull() { */ @Test public void authAuthEa() { - assertEquals("Newton", LabelPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); - assertEquals("Newton.Maxwell", LabelPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); + assertEquals("Newton", BibtexKeyPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); + assertEquals("Newton.Maxwell", BibtexKeyPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); assertEquals("Newton.Maxwell.ea", - LabelPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.authAuthEa(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3)); } /** @@ -302,17 +304,17 @@ public void testAuthEtAl() { String delim = "."; String append = ".etal"; assertEquals("Newton.etal", - LabelPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); + BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); assertEquals("Newton.Maxwell", - LabelPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); + BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); // [authEtAl] delim = ""; append = "EtAl"; assertEquals("NewtonEtAl", - LabelPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); + BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_3, delim, append)); assertEquals("NewtonMaxwell", - LabelPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); + BibtexKeyPatternUtil.authEtal(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2, delim, append)); } /** @@ -323,16 +325,16 @@ public void testAuthShort() { // tests taken from the comments assertEquals( "NME+", - LabelPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals( "NME", - LabelPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals( "NM", - LabelPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "Newton", - LabelPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.authshort(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); } /** @@ -342,35 +344,35 @@ public void testAuthShort() { public void authNM() { assertEquals( "N", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1, 1)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1, 1)); assertEquals( "Max", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3, 2)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3, 2)); assertEquals( "New", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3, 1)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3, 1)); assertEquals( "Bo", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 2, 4)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 2, 4)); assertEquals( "Bohr", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 6, 4)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5, 6, 4)); assertEquals( "Aal", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1, 3, 1)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1, 3, 1)); assertEquals( "Less", - LabelPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2, 4, 2)); + BibtexKeyPatternUtil.authNofMth(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2, 4, 2)); assertEquals( "", - LabelPatternUtil.authNofMth("", 2, 4)); + BibtexKeyPatternUtil.authNofMth("", 2, 4)); } @Test(expected = NullPointerException.class) public void authNMThrowsNPE() { - LabelPatternUtil.authNofMth(null, 2, 4); + BibtexKeyPatternUtil.authNofMth(null, 2, 4); } /** @@ -380,16 +382,16 @@ public void authNMThrowsNPE() { public void firstAuthorForenameInitials() { assertEquals( "I", - LabelPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals( "I", - LabelPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "I", - LabelPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_1)); assertEquals( "I", - LabelPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.firstAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_COUNT_2)); } /** @@ -399,10 +401,10 @@ public void firstAuthorForenameInitials() { public void firstAuthorVonAndLast() { assertEquals( "vanderAalst", - LabelPatternUtil.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyPatternUtil.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals( "vanderAalst", - LabelPatternUtil.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyPatternUtil.firstAuthorVonAndLast(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -412,13 +414,13 @@ public void firstAuthorVonAndLast() { public void testAllAuthors() { assertEquals( "Newton", - LabelPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals( "NewtonMaxwell", - LabelPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "NewtonMaxwellEinstein", - LabelPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.allAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); } /** @@ -428,26 +430,26 @@ public void testAllAuthors() { public void authorsAlpha() { assertEquals( "New", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals( "NM", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "NME", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals( "NMEB", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals( "NME+", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals( "vdAal", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals( "vdAvL", - LabelPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyPatternUtil.authorsAlpha(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -457,26 +459,26 @@ public void authorsAlpha() { public void lastAuthor() { assertEquals( "Newton", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals( "Maxwell", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "Einstein", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals( "Bohr", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals( "Unknown", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals( "Aalst", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals( "Lessen", - LabelPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyPatternUtil.lastAuthor(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -486,26 +488,26 @@ public void lastAuthor() { public void lastAuthorForenameInitials() { assertEquals( "I", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals( "J", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "A", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals( "N", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals( "H", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals( "W", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals( "T", - LabelPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyPatternUtil.lastAuthorForenameInitials(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -515,26 +517,26 @@ public void lastAuthorForenameInitials() { public void oneAuthorPlusIni() { assertEquals( "Newto", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1)); assertEquals( "NewtoM", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2)); assertEquals( "NewtoME", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3)); assertEquals( "NewtoMEB", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4)); assertEquals( "NewtoMEBU", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_5)); assertEquals( "Aalst", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_1)); assertEquals( "AalstL", - LabelPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); + BibtexKeyPatternUtil.oneAuthorPlusIni(AUTHOR_STRING_FIRSTNAME_FULL_LASTNAME_FULL_WITH_VAN_COUNT_2)); } /** @@ -543,13 +545,13 @@ public void oneAuthorPlusIni() { @Test public void testNAuthors1() { assertEquals("Newton", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 1)); assertEquals("NewtonEtAl", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 1)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 1)); assertEquals("NewtonEtAl", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 1)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 1)); assertEquals("NewtonEtAl", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 1)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 1)); } /** @@ -559,49 +561,49 @@ public void testNAuthors1() { public void testNAuthors3() { assertEquals( "Newton", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 3)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_1, 3)); assertEquals( "NewtonMaxwell", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_2, 3)); assertEquals( "NewtonMaxwellEinstein", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_3, 3)); assertEquals( "NewtonMaxwellEinsteinEtAl", - LabelPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 3)); + BibtexKeyPatternUtil.nAuthors(AUTHOR_STRING_FIRSTNAME_INITIAL_LASTNAME_FULL_COUNT_4, 3)); } @Test public void testFirstPage() { - assertEquals("7", LabelPatternUtil.firstPage("7--27")); - assertEquals("27", LabelPatternUtil.firstPage("--27")); - assertEquals("", LabelPatternUtil.firstPage("")); - assertEquals("42", LabelPatternUtil.firstPage("42--111")); - assertEquals("7", LabelPatternUtil.firstPage("7,41,73--97")); - assertEquals("7", LabelPatternUtil.firstPage("41,7,73--97")); - assertEquals("43", LabelPatternUtil.firstPage("43+")); + assertEquals("7", BibtexKeyPatternUtil.firstPage("7--27")); + assertEquals("27", BibtexKeyPatternUtil.firstPage("--27")); + assertEquals("", BibtexKeyPatternUtil.firstPage("")); + assertEquals("42", BibtexKeyPatternUtil.firstPage("42--111")); + assertEquals("7", BibtexKeyPatternUtil.firstPage("7,41,73--97")); + assertEquals("7", BibtexKeyPatternUtil.firstPage("41,7,73--97")); + assertEquals("43", BibtexKeyPatternUtil.firstPage("43+")); } @Test(expected = NullPointerException.class) public void testFirstPageNull() { - LabelPatternUtil.firstPage(null); + BibtexKeyPatternUtil.firstPage(null); } @Test public void testLastPage() { - assertEquals("27", LabelPatternUtil.lastPage("7--27")); - assertEquals("27", LabelPatternUtil.lastPage("--27")); - assertEquals("", LabelPatternUtil.lastPage("")); - assertEquals("111", LabelPatternUtil.lastPage("42--111")); - assertEquals("97", LabelPatternUtil.lastPage("7,41,73--97")); - assertEquals("97", LabelPatternUtil.lastPage("7,41,97--73")); - assertEquals("43", LabelPatternUtil.lastPage("43+")); + assertEquals("27", BibtexKeyPatternUtil.lastPage("7--27")); + assertEquals("27", BibtexKeyPatternUtil.lastPage("--27")); + assertEquals("", BibtexKeyPatternUtil.lastPage("")); + assertEquals("111", BibtexKeyPatternUtil.lastPage("42--111")); + assertEquals("97", BibtexKeyPatternUtil.lastPage("7,41,73--97")); + assertEquals("97", BibtexKeyPatternUtil.lastPage("7,41,97--73")); + assertEquals("43", BibtexKeyPatternUtil.lastPage("43+")); } @Test(expected = NullPointerException.class) public void testLastPageNull() { - LabelPatternUtil.lastPage(null); + BibtexKeyPatternUtil.lastPage(null); } /** @@ -613,28 +615,28 @@ public void veryShortTitle() { int count = 1; assertEquals( "application", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); assertEquals( "BPEL", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals( "Process", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); assertEquals( "BPMN", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); assertEquals( "Difference", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); assertEquals( "Cloud", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals( "Towards", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); assertEquals( "Measurement", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); } /** @@ -646,28 +648,28 @@ public void shortTitle() { int count = 3; assertEquals( "applicationmigrationeffort", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH)); assertEquals( "BPELconformanceopen", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals( "ProcessViewingPatterns", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED)); assertEquals( "BPMNConformanceOpen", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD)); assertEquals( "DifferenceGraphBased", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING)); assertEquals( "CloudComputingNext", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON)); assertEquals( "TowardsChoreographybased", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD)); assertEquals( "MeasurementDesignTime", - LabelPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); + BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS)); } @Test @@ -675,15 +677,15 @@ public void keywordNKeywordsSeparatedBySpace() { BibEntry entry = new BibEntry(); entry.setField("keywords", "w1, w2a w2b, w3"); - String result = LabelPatternUtil.makeLabel(entry, "keyword1"); + String result = BibtexKeyPatternUtil.makeLabel(entry, "keyword1"); assertEquals("w1", result); // check keywords with space - result = LabelPatternUtil.makeLabel(entry, "keyword2"); + result = BibtexKeyPatternUtil.makeLabel(entry, "keyword2"); assertEquals("w2a w2b", result); // check out of range - result = LabelPatternUtil.makeLabel(entry, "keyword4"); + result = BibtexKeyPatternUtil.makeLabel(entry, "keyword4"); assertEquals("", result); } @@ -693,44 +695,44 @@ public void keywordsNKeywordsSeparatedBySpace() { entry.setField("keywords", "w1, w2a w2b, w3"); // all keywords - String result = LabelPatternUtil.makeLabel(entry, "keywords"); + String result = BibtexKeyPatternUtil.makeLabel(entry, "keywords"); assertEquals("w1w2aw2bw3", result); // check keywords with space - result = LabelPatternUtil.makeLabel(entry, "keywords2"); + result = BibtexKeyPatternUtil.makeLabel(entry, "keywords2"); assertEquals("w1w2aw2b", result); // check out of range - result = LabelPatternUtil.makeLabel(entry, "keywords55"); + result = BibtexKeyPatternUtil.makeLabel(entry, "keywords55"); assertEquals("w1w2aw2bw3", result); } @Test public void testCheckLegalKeyEnforceLegal() { - assertEquals("AAAA", LabelPatternUtil.checkLegalKey("AA AA", true)); - assertEquals("SPECIALCHARS", LabelPatternUtil.checkLegalKey("SPECIAL CHARS#{\\\"}~,^", true)); - assertEquals("", LabelPatternUtil.checkLegalKey("\n\t\r", true)); + assertEquals("AAAA", BibtexKeyPatternUtil.checkLegalKey("AA AA", true)); + assertEquals("SPECIALCHARS", BibtexKeyPatternUtil.checkLegalKey("SPECIAL CHARS#{\\\"}~,^", true)); + assertEquals("", BibtexKeyPatternUtil.checkLegalKey("\n\t\r", true)); } @Test public void testCheckLegalKeyDoNotEnforceLegal() { - assertEquals("AAAA", LabelPatternUtil.checkLegalKey("AA AA", false)); - assertEquals("SPECIALCHARS#~^", LabelPatternUtil.checkLegalKey("SPECIAL CHARS#{\\\"}~,^", false)); - assertEquals("", LabelPatternUtil.checkLegalKey("\n\t\r", false)); + assertEquals("AAAA", BibtexKeyPatternUtil.checkLegalKey("AA AA", false)); + assertEquals("SPECIALCHARS#~^", BibtexKeyPatternUtil.checkLegalKey("SPECIAL CHARS#{\\\"}~,^", false)); + assertEquals("", BibtexKeyPatternUtil.checkLegalKey("\n\t\r", false)); } @Test public void testCheckLegalNullInNullOut() { - assertNull(LabelPatternUtil.checkLegalKey(null, true)); - assertNull(LabelPatternUtil.checkLegalKey(null, false)); + assertNull(BibtexKeyPatternUtil.checkLegalKey(null, true)); + assertNull(BibtexKeyPatternUtil.checkLegalKey(null, false)); } @Test public void testApplyModifiers() { BibEntry entry = new BibEntry(); entry.setField("title", "Green Scheduling of Whatever"); - assertEquals("GSW", LabelPatternUtil.makeLabel(entry, "shorttitleINI")); - assertEquals("GreenSchedulingWhatever", LabelPatternUtil.makeLabel(entry, "shorttitle")); + assertEquals("GSW", BibtexKeyPatternUtil.makeLabel(entry, "shorttitleINI")); + assertEquals("GreenSchedulingWhatever", BibtexKeyPatternUtil.makeLabel(entry, "shorttitle")); } } diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 1627a129008..797299aafde 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -31,8 +31,8 @@ import net.sf.jabref.model.entry.BibtexString; import net.sf.jabref.model.entry.CustomEntryType; import net.sf.jabref.model.entry.IdGenerator; -import net.sf.jabref.model.labelpattern.AbstractLabelPattern; -import net.sf.jabref.model.labelpattern.DatabaseLabelPattern; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.preferences.JabRefPreferences; import com.google.common.base.Charsets; @@ -156,7 +156,7 @@ public void writeEpilogueAndEncoding() throws Exception { @Test public void writeMetadata() throws Exception { - DatabaseLabelPattern labelPattern = new DatabaseLabelPattern(Globals.prefs); + DatabaseBibtexKeyPattern labelPattern = new DatabaseBibtexKeyPattern(Globals.prefs); labelPattern.setDefaultValue("test"); metaData.setLabelPattern(labelPattern); @@ -169,7 +169,7 @@ public void writeMetadata() throws Exception { @Test public void writeMetadataAndEncoding() throws Exception { SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII); - DatabaseLabelPattern labelPattern = new DatabaseLabelPattern(Globals.prefs); + DatabaseBibtexKeyPattern labelPattern = new DatabaseBibtexKeyPattern(Globals.prefs); labelPattern.setDefaultValue("test"); metaData.setLabelPattern(labelPattern); @@ -422,7 +422,7 @@ public void writeSaveOrderConfig() throws Exception { @Test public void writeCustomKeyPattern() throws Exception { - AbstractLabelPattern pattern = new DatabaseLabelPattern(Globals.prefs); + AbstractBibtexKeyPattern pattern = new DatabaseBibtexKeyPattern(Globals.prefs); pattern.setDefaultValue("test"); pattern.addLabelPattern("article", "articleTest"); metaData.setLabelPattern(pattern); From 56cbc41a209ab5d4220c5dd6b4525419e107a53a Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Tue, 9 Aug 2016 20:54:16 +0200 Subject: [PATCH 2/9] fix import order --- src/main/java/net/sf/jabref/MetaData.java | 2 +- src/main/java/net/sf/jabref/cli/ArgumentProcessor.java | 4 ++-- src/main/java/net/sf/jabref/gui/BasePanel.java | 6 +++--- src/main/java/net/sf/jabref/gui/EntryTypeList.java | 2 +- src/main/java/net/sf/jabref/gui/FieldSetComponent.java | 2 +- src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java | 2 +- src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java | 4 ++-- .../jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java | 4 ++-- .../gui/bibtexkeypattern/SearchFixDuplicateLabels.java | 2 +- .../java/net/sf/jabref/gui/entryeditor/EntryEditor.java | 4 ++-- .../java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java | 4 ++-- .../net/sf/jabref/importer/fileformat/FreeCiteImporter.java | 4 ++-- src/main/java/net/sf/jabref/pdfimport/PdfImporter.java | 4 ++-- .../java/net/sf/jabref/preferences/JabRefPreferences.java | 4 ++-- .../net/sf/jabref/importer/fileformat/BibtexParserTest.java | 2 +- .../sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java | 4 ++-- 16 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index 1bdfecc2d65..f972b85f7e4 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -42,9 +42,9 @@ import net.sf.jabref.logic.util.OS; import net.sf.jabref.logic.util.strings.StringUtil; import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import com.google.common.eventbus.EventBus; import org.apache.commons.logging.Log; diff --git a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java index c972f88bcf4..c3bacb5ebf2 100644 --- a/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/net/sf/jabref/cli/ArgumentProcessor.java @@ -26,6 +26,8 @@ import net.sf.jabref.importer.fetcher.EntryFetcher; import net.sf.jabref.importer.fetcher.EntryFetchers; import net.sf.jabref.logic.CustomEntryTypesManager; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.exporter.BibDatabaseWriter; import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; import net.sf.jabref.logic.exporter.ExportFormats; @@ -35,8 +37,6 @@ import net.sf.jabref.logic.exporter.SavePreferences; import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.logging.JabRefLogger; import net.sf.jabref.logic.search.DatabaseSearcher; import net.sf.jabref.logic.search.SearchQuery; diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 537c15b9bf8..4fabd4f7f2a 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -72,6 +72,7 @@ import net.sf.jabref.gui.actions.Actions; import net.sf.jabref.gui.actions.BaseAction; import net.sf.jabref.gui.actions.CleanupAction; +import net.sf.jabref.gui.bibtexkeypattern.SearchFixDuplicateLabels; import net.sf.jabref.gui.desktop.JabRefDesktop; import net.sf.jabref.gui.entryeditor.EntryEditor; import net.sf.jabref.gui.exporter.ExportToClipboardAction; @@ -82,7 +83,6 @@ import net.sf.jabref.gui.groups.GroupTreeNodeViewModel; import net.sf.jabref.gui.journals.AbbreviateAction; import net.sf.jabref.gui.journals.UnabbreviateAction; -import net.sf.jabref.gui.bibtexkeypattern.SearchFixDuplicateLabels; import net.sf.jabref.gui.maintable.MainTable; import net.sf.jabref.gui.maintable.MainTableDataModel; import net.sf.jabref.gui.maintable.MainTableFormat; @@ -110,6 +110,8 @@ import net.sf.jabref.logic.autocompleter.AutoCompleter; import net.sf.jabref.logic.autocompleter.AutoCompleterFactory; import net.sf.jabref.logic.autocompleter.ContentAutoCompleters; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.exporter.BibtexDatabaseWriter; import net.sf.jabref.logic.exporter.FileSaveSession; import net.sf.jabref.logic.exporter.SaveException; @@ -117,8 +119,6 @@ import net.sf.jabref.logic.exporter.SaveSession; import net.sf.jabref.logic.l10n.Encodings; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.layout.Layout; import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.layout.LayoutHelper; diff --git a/src/main/java/net/sf/jabref/gui/EntryTypeList.java b/src/main/java/net/sf/jabref/gui/EntryTypeList.java index 8ea36b49292..262270083e8 100644 --- a/src/main/java/net/sf/jabref/gui/EntryTypeList.java +++ b/src/main/java/net/sf/jabref/gui/EntryTypeList.java @@ -27,8 +27,8 @@ import javax.swing.event.ListSelectionListener; import net.sf.jabref.Globals; -import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.EntryTypes; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.CustomEntryType; diff --git a/src/main/java/net/sf/jabref/gui/FieldSetComponent.java b/src/main/java/net/sf/jabref/gui/FieldSetComponent.java index f4f9f2a8493..e138834fcf5 100644 --- a/src/main/java/net/sf/jabref/gui/FieldSetComponent.java +++ b/src/main/java/net/sf/jabref/gui/FieldSetComponent.java @@ -47,8 +47,8 @@ import javax.swing.event.ListSelectionListener; import net.sf.jabref.Globals; -import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.preferences.JabRefPreferences; /** diff --git a/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java b/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java index 2e1ef763165..69d63a10a76 100644 --- a/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java +++ b/src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java @@ -39,9 +39,9 @@ import net.sf.jabref.gui.entryeditor.EntryEditorTabList; import net.sf.jabref.gui.help.HelpAction; import net.sf.jabref.gui.keyboard.KeyBinding; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.preferences.JabRefPreferences; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java index f466a07b212..f62b242d0cd 100644 --- a/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java +++ b/src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java @@ -86,13 +86,13 @@ import net.sf.jabref.importer.ImportInspector; import net.sf.jabref.importer.OutputPrinter; import net.sf.jabref.logic.bibtex.comparator.FieldComparator; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.groups.AllEntriesGroup; import net.sf.jabref.logic.groups.EntriesGroupChange; import net.sf.jabref.logic.groups.GroupTreeNode; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.model.DuplicateCheck; import net.sf.jabref.model.database.BibDatabase; diff --git a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index 9fb74d4ae32..8d0045373e8 100644 --- a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -38,11 +38,11 @@ import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.EntryTypes; -import net.sf.jabref.model.database.BibDatabaseMode; -import net.sf.jabref.model.entry.EntryType; import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; +import net.sf.jabref.model.database.BibDatabaseMode; +import net.sf.jabref.model.entry.EntryType; import net.sf.jabref.preferences.JabRefPreferences; public class BibtexKeyPatternPanel extends JPanel { diff --git a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java index 8274098ccda..c2995179304 100644 --- a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/SearchFixDuplicateLabels.java @@ -27,9 +27,9 @@ import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.undo.UndoableKeyChange; import net.sf.jabref.gui.worker.AbstractWorker; -import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.entry.BibEntry; diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 6015a4157c8..fd3bcfd3648 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -97,10 +97,10 @@ import net.sf.jabref.logic.bibtex.BibEntryWriter; import net.sf.jabref.logic.bibtex.LatexFieldFormatter; import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences; -import net.sf.jabref.logic.help.HelpFile; -import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.help.HelpFile; +import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.search.SearchQueryHighlightListener; import net.sf.jabref.logic.util.date.TimeStamp; import net.sf.jabref.model.EntryTypes; diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java index 6ddd8786e84..e78fdba8801 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -60,10 +60,10 @@ import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.undo.UndoableKeyChange; import net.sf.jabref.gui.worker.AbstractWorker; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.openoffice.OOBibStyle; import net.sf.jabref.logic.openoffice.OpenOfficePreferences; diff --git a/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java b/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java index d4ceeafa0fb..56447bd41e1 100644 --- a/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java +++ b/src/main/java/net/sf/jabref/importer/fileformat/FreeCiteImporter.java @@ -38,9 +38,9 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefGUI; import net.sf.jabref.importer.ParserResult; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.BibtexEntryTypes; diff --git a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java index 5fff98a9a6d..bb46e558782 100644 --- a/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java +++ b/src/main/java/net/sf/jabref/pdfimport/PdfImporter.java @@ -39,9 +39,9 @@ import net.sf.jabref.importer.ParserResult; import net.sf.jabref.importer.fileformat.PdfContentImporter; import net.sf.jabref.importer.fileformat.PdfXmpImporter; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences; +import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil; +import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.UpdateField; import net.sf.jabref.logic.util.io.FileUtil; import net.sf.jabref.logic.xmp.XMPPreferences; diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 3516621a7b0..0c250491e8b 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -74,13 +74,13 @@ import net.sf.jabref.logic.util.OS; import net.sf.jabref.logic.util.VersionPreferences; import net.sf.jabref.logic.util.strings.StringUtil; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.CustomEntryType; import net.sf.jabref.model.entry.EntryUtil; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; -import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import net.sf.jabref.specialfields.SpecialFieldsUtils; import org.apache.commons.logging.Log; diff --git a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java index 7b157d014ab..f6419c19c4e 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java @@ -26,11 +26,11 @@ import net.sf.jabref.logic.groups.KeywordGroup; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.entry.BibtexString; import net.sf.jabref.model.entry.EntryType; -import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.preferences.JabRefPreferences; import org.junit.BeforeClass; diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 797299aafde..5a850ff7dfc 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -24,6 +24,8 @@ import net.sf.jabref.logic.groups.GroupTreeNode; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.EntryTypes; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; @@ -31,8 +33,6 @@ import net.sf.jabref.model.entry.BibtexString; import net.sf.jabref.model.entry.CustomEntryType; import net.sf.jabref.model.entry.IdGenerator; -import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; -import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; import net.sf.jabref.preferences.JabRefPreferences; import com.google.common.base.Charsets; From 6ff87ad0bdc2820d3263d68cfd9bef95f2ec5fcf Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Tue, 9 Aug 2016 21:16:54 +0200 Subject: [PATCH 3/9] rename label pattern in methods, params, variables and text --- src/main/java/net/sf/jabref/MetaData.java | 36 +++++++++---------- .../sf/jabref/gui/BibtexKeyPatternDialog.java | 4 +-- .../BibtexKeyPatternPanel.java | 28 +++++++-------- .../gui/preftabs/BibtexKeyPatternPrefTab.java | 6 ++-- .../BibtexKeyPatternPreferences.java | 10 +++--- .../BibtexKeyPatternUtil.java | 2 +- .../AbstractBibtexKeyPattern.java | 36 +++++++++---------- .../DatabaseBibtexKeyPattern.java | 2 +- .../GlobalBibtexKeyPattern.java | 10 +++--- .../jabref/preferences/JabRefPreferences.java | 10 +++--- .../importer/fileformat/BibtexParserTest.java | 6 ++-- .../exporter/BibtexDatabaseWriterTest.java | 16 ++++----- .../net/sf/jabref/customPreferences.xml | 2 +- 13 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index f972b85f7e4..97050544e48 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -70,7 +70,7 @@ public class MetaData implements Iterable { private GroupTreeNode groupsRoot; private final EventBus eventBus = new EventBus(); - private AbstractBibtexKeyPattern labelPattern; + private AbstractBibtexKeyPattern bibtexKeyPattern; private Charset encoding = Globals.prefs.getDefaultEncoding(); @@ -239,36 +239,36 @@ private static Optional getNextUnit(Reader reader) throws IOException { /** * @return the stored label patterns */ - public AbstractBibtexKeyPattern getLabelPattern() { - if (labelPattern != null) { - return labelPattern; + public AbstractBibtexKeyPattern getBibtexKeyPattern() { + if (bibtexKeyPattern != null) { + return bibtexKeyPattern; } - labelPattern = new DatabaseBibtexKeyPattern(Globals.prefs); + bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs); - // read the data from the metadata and store it into the labelPattern + // read the data from the metadata and store it into the bibtexKeyPattern for (String key : this) { if (key.startsWith(PREFIX_KEYPATTERN)) { List value = getData(key); String type = key.substring(PREFIX_KEYPATTERN.length()); - labelPattern.addLabelPattern(type, value.get(0)); + bibtexKeyPattern.addBibtexKeyPattern(type, value.get(0)); } } List defaultPattern = getData(KEYPATTERNDEFAULT); if (defaultPattern != null) { - labelPattern.setDefaultValue(defaultPattern.get(0)); + bibtexKeyPattern.setDefaultValue(defaultPattern.get(0)); } - return labelPattern; + return bibtexKeyPattern; } /** * Updates the stored key patterns to the given key patterns. * - * @param labelPattern the key patterns to update to.
- * A reference to this object is stored internally and is returned at getLabelPattern(); + * @param bibtexKeyPattern the key patterns to update to.
+ * A reference to this object is stored internally and is returned at getBibtexKeyPattern(); */ - public void setLabelPattern(AbstractBibtexKeyPattern labelPattern) { + public void setBibtexKeyPattern(AbstractBibtexKeyPattern bibtexKeyPattern) { // remove all keypatterns from metadata Iterator iterator = this.iterator(); while (iterator.hasNext()) { @@ -279,26 +279,26 @@ public void setLabelPattern(AbstractBibtexKeyPattern labelPattern) { } // set new value if it is not a default value - Set allKeys = labelPattern.getAllKeys(); + Set allKeys = bibtexKeyPattern.getAllKeys(); for (String key : allKeys) { String metaDataKey = PREFIX_KEYPATTERN + key; - if (!labelPattern.isDefaultValue(key)) { + if (!bibtexKeyPattern.isDefaultValue(key)) { List data = new ArrayList<>(); - data.add(labelPattern.getValue(key).get(0)); + data.add(bibtexKeyPattern.getValue(key).get(0)); this.putData(metaDataKey, data); } } // store default pattern - if (labelPattern.getDefaultValue() == null) { + if (bibtexKeyPattern.getDefaultValue() == null) { this.remove(KEYPATTERNDEFAULT); } else { List data = new ArrayList<>(); - data.add(labelPattern.getDefaultValue().get(0)); + data.add(bibtexKeyPattern.getDefaultValue().get(0)); this.putData(KEYPATTERNDEFAULT, data); } - this.labelPattern = labelPattern; + this.bibtexKeyPattern = bibtexKeyPattern; } public Optional getSaveActions() { diff --git a/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java b/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java index 84a1986ee28..c0e12ea908e 100644 --- a/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java +++ b/src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java @@ -58,7 +58,7 @@ public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) { public void setPanel(BasePanel panel) { this.panel = panel; this.metaData = panel.getBibDatabaseContext().getMetaData(); - AbstractBibtexKeyPattern keypatterns = metaData.getLabelPattern(); + AbstractBibtexKeyPattern keypatterns = metaData.getBibtexKeyPattern(); bibtexKeyPatternPanel.setValues(keypatterns); } @@ -84,7 +84,7 @@ private void init() { pack(); ok.addActionListener(e -> { - metaData.setLabelPattern(bibtexKeyPatternPanel.getLabelPatternAsDatabaseLabelPattern()); + metaData.setBibtexKeyPattern(bibtexKeyPatternPanel.getKeyPatternAsDatabaseBibtexKeyPattern()); panel.markNonUndoableBaseChanged(); dispose(); }); diff --git a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index 8d0045373e8..06afc9fd356 100644 --- a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -110,7 +110,7 @@ private void buildGUI() { con.insets = new Insets(5, 5, 10, 5); JButton btnDefault = new JButton(Localization.lang("Default")); btnDefault.addActionListener( - e -> defaultPat.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); + e -> defaultPat.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); con.gridx = 2; int y = 2; gbl.setConstraints(btnDefault, con); @@ -172,7 +172,7 @@ private void buildGUI() { } // also reset the default pattern - defaultPat.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_LABEL_PATTERN)); + defaultPat.setText((String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); }); add(btnDefaultAll); } @@ -227,7 +227,7 @@ private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) { for (Map.Entry entry : textFields.entrySet()) { String text = entry.getValue().getText(); if (!text.trim().isEmpty()) { - keypatterns.addLabelPattern(entry.getKey(), text); + keypatterns.addBibtexKeyPattern(entry.getKey(), text); } } @@ -238,14 +238,14 @@ private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) { } } - protected GlobalBibtexKeyPattern getLabelPatternAsGlobalLabelPattern() { + protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() { GlobalBibtexKeyPattern res = new GlobalBibtexKeyPattern( - AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); + AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); fillPatternUsingPanelData(res); return res; } - public DatabaseBibtexKeyPattern getLabelPatternAsDatabaseLabelPattern() { + public DatabaseBibtexKeyPattern getKeyPatternAsDatabaseBibtexKeyPattern() { DatabaseBibtexKeyPattern res = new DatabaseBibtexKeyPattern(Globals.prefs); fillPatternUsingPanelData(res); return res; @@ -254,25 +254,25 @@ public DatabaseBibtexKeyPattern getLabelPatternAsDatabaseLabelPattern() { /** * Fills the current values to the text fields * - * @param keypatterns the LabelPattern to use as initial value + * @param keyPattern the BibtexKeyPattern to use as initial value */ - public void setValues(AbstractBibtexKeyPattern keypatterns) { + public void setValues(AbstractBibtexKeyPattern keyPattern) { for (Map.Entry entry : textFields.entrySet()) { - setValue(entry.getValue(), entry.getKey(), keypatterns); + setValue(entry.getValue(), entry.getKey(), keyPattern); } - if (keypatterns.getDefaultValue() == null) { + if (keyPattern.getDefaultValue() == null) { defaultPat.setText(""); } else { - defaultPat.setText(keypatterns.getDefaultValue().get(0)); + defaultPat.setText(keyPattern.getDefaultValue().get(0)); } } - private static void setValue(JTextField tf, String fieldName, AbstractBibtexKeyPattern keypatterns) { - if (keypatterns.isDefaultValue(fieldName)) { + private static void setValue(JTextField tf, String fieldName, AbstractBibtexKeyPattern keyPattern) { + if (keyPattern.isDefaultValue(fieldName)) { tf.setText(""); } else { - tf.setText(keypatterns.getValue(fieldName).get(0)); + tf.setText(keyPattern.getValue(fieldName).get(0)); } } diff --git a/src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java b/src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java index a57e35c98b8..8e5cb8c2415 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/BibtexKeyPatternPrefTab.java @@ -68,7 +68,7 @@ public BibtexKeyPatternPrefTab(JabRefPreferences prefs, BasePanel panel) { public void storeSettings() { // Set the default value: - Globals.prefs.put(JabRefPreferences.DEFAULT_LABEL_PATTERN, defaultPat.getText()); + 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()); @@ -90,7 +90,7 @@ public void storeSettings() { } // fetch entries from GUI - GlobalBibtexKeyPattern keypatterns = getLabelPatternAsGlobalLabelPattern(); + GlobalBibtexKeyPattern keypatterns = getKeyPatternAsGlobalBibtexKeyPattern(); // store new patterns globally prefs.putKeyPattern(keypatterns); } @@ -155,7 +155,7 @@ public boolean validateSettings() { @Override public void setValues() { super.setValues(Globals.prefs.getKeyPattern()); - defaultPat.setText(Globals.prefs.get(JabRefPreferences.DEFAULT_LABEL_PATTERN)); + defaultPat.setText(Globals.prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); dontOverwrite.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AVOID_OVERWRITING_KEY)); generateOnSave.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING)); autoGenerateOnImport.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_AFTER_INSPECTION)); diff --git a/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java index e6f49381b0a..f07034b23bd 100644 --- a/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java +++ b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternPreferences.java @@ -4,16 +4,16 @@ public class BibtexKeyPatternPreferences { - private final String defaultLabelPattern; + private final String defaultBibtexKeyPattern; private final String keyPatternRegex; private final String keyPatternReplacement; private final boolean alwaysAddLetter; private final boolean firstLetterA; private final boolean enforceLegalKey; - public BibtexKeyPatternPreferences(String defaultLabelPattern, String keyPatternRegex, String keyPatternReplacement, + public BibtexKeyPatternPreferences(String defaultBibtexKeyPattern, String keyPatternRegex, String keyPatternReplacement, boolean alwaysAddLetter, boolean firstLetterA, boolean enforceLegalKey) { - this.defaultLabelPattern = defaultLabelPattern; + this.defaultBibtexKeyPattern = defaultBibtexKeyPattern; this.keyPatternRegex = keyPatternRegex; this.keyPatternReplacement = keyPatternReplacement; this.alwaysAddLetter = alwaysAddLetter; @@ -22,7 +22,7 @@ public BibtexKeyPatternPreferences(String defaultLabelPattern, String keyPattern } public static BibtexKeyPatternPreferences fromPreferences(JabRefPreferences jabRefPreferences) { - return new BibtexKeyPatternPreferences(jabRefPreferences.get(JabRefPreferences.DEFAULT_LABEL_PATTERN), + return new BibtexKeyPatternPreferences(jabRefPreferences.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN), jabRefPreferences.get(JabRefPreferences.KEY_PATTERN_REGEX), jabRefPreferences.get(JabRefPreferences.KEY_PATTERN_REPLACEMENT), jabRefPreferences.getBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER), @@ -50,5 +50,5 @@ public boolean isEnforceLegalKey() { return enforceLegalKey; } - public String getDefaultLabelPattern() { return defaultLabelPattern;} + public String getDefaultBibtexKeyPattern() { return defaultBibtexKeyPattern;} } diff --git a/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java index e81d0de97ac..6477afe0b7a 100644 --- a/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java +++ b/src/main/java/net/sf/jabref/logic/bibtexkeypattern/BibtexKeyPatternUtil.java @@ -401,7 +401,7 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr // get the type of entry String entryType = entry.getType(); // Get the arrayList corresponding to the type - List typeList = new ArrayList<>(metaData.getLabelPattern().getValue(entryType)); + List typeList = new ArrayList<>(metaData.getBibtexKeyPattern().getValue(entryType)); if (!typeList.isEmpty()) { typeList.remove(0); } diff --git a/src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java b/src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java index 04643176ebc..96d9d99f6e2 100644 --- a/src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java +++ b/src/main/java/net/sf/jabref/model/bibtexkeypattern/AbstractBibtexKeyPattern.java @@ -26,8 +26,8 @@ import java.util.StringTokenizer; /** - * A small table, where an entry type is associated with a label pattern (an - * ArrayList). A parent LabelPattern can be set. + * A small table, where an entry type is associated with a Bibtex key pattern (an + * ArrayList). A parent BibtexKeyPattern can be set. */ public abstract class AbstractBibtexKeyPattern { @@ -35,7 +35,7 @@ public abstract class AbstractBibtexKeyPattern { protected Map> data = new HashMap<>(); - public void addLabelPattern(String type, String pattern) { + public void addBibtexKeyPattern(String type, String pattern) { data.put(type, AbstractBibtexKeyPattern.split(pattern)); } @@ -66,20 +66,20 @@ public int hashCode() { } /** - * Remove a label pattern from the LabelPattern. + * Remove a Bibtex key pattern from the BibtexKeyPattern. * * @param type a String */ - public void removeLabelPattern(String type) { + public void removeBibtexKeyPattern(String type) { if (data.containsKey(type)) { data.remove(type); } } /** - * Gets an object for a desired label from this LabelPattern or one of it's - * parents (in the case of DatabaseLAbelPattern). This method first tries to obtain the object from this - * LabelPattern via the get method of Hashtable. + * Gets an object for a desired key from this BibtexKeyPattern or one of it's + * parents (in the case of DatabaseBibtexKeyPattern). This method first tries to obtain the object from this + * BibtexKeyPattern via the get method of Hashtable. * If this fails, we try the default.
* If that fails, we try the parent.
* If that fails, we return the DEFAULT_LABELPATTERN
@@ -96,7 +96,7 @@ public List getValue(String key) { if (result == null) { // we are the "last" to ask // we don't have anything left - return getLastLevelLabelPattern(key); + return getLastLevelBibtexKeyPattern(key); } } return result; @@ -108,19 +108,19 @@ public List getValue(String key) { * where the fields are the (required) fields of a BibTex entry. The string is split * into fields and spacers by recognizing the [ and ]. * - * @param labelPattern a String + * @param bibtexKeyPattern a String * @return an ArrayList The first item of the list * is a string representation of the key pattern (the parameter), * the remaining items are the fields */ - public static List split(String labelPattern) { + public static List split(String bibtexKeyPattern) { // A holder for fields of the entry to be used for the key List fieldList = new ArrayList<>(); // Before we do anything, we add the parameter to the ArrayLIst - fieldList.add(labelPattern); + fieldList.add(bibtexKeyPattern); - StringTokenizer tok = new StringTokenizer(labelPattern, "[]", true); + StringTokenizer tok = new StringTokenizer(bibtexKeyPattern, "[]", true); while (tok.hasMoreTokens()) { fieldList.add(tok.nextToken()); } @@ -144,16 +144,16 @@ public List getDefaultValue() { } /** - * Sets the DEFAULT PATTERN for this label pattern - * @param labelPattern the pattern to store + * Sets the DEFAULT PATTERN for this key pattern + * @param bibtexKeyPattern the pattern to store */ - public void setDefaultValue(String labelPattern) { - this.defaultPattern = AbstractBibtexKeyPattern.split(labelPattern); + public void setDefaultValue(String bibtexKeyPattern) { + this.defaultPattern = AbstractBibtexKeyPattern.split(bibtexKeyPattern); } public Set getAllKeys() { return data.keySet(); } - public abstract List getLastLevelLabelPattern(String key); + public abstract List getLastLevelBibtexKeyPattern(String key); } diff --git a/src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java b/src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java index 197650713a8..b447842919f 100644 --- a/src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java +++ b/src/main/java/net/sf/jabref/model/bibtexkeypattern/DatabaseBibtexKeyPattern.java @@ -29,7 +29,7 @@ public DatabaseBibtexKeyPattern(JabRefPreferences prefs) { } @Override - public List getLastLevelLabelPattern(String key) { + public List getLastLevelBibtexKeyPattern(String key) { return prefs.getKeyPattern().getValue(key); } diff --git a/src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java b/src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java index dc3d4c70dc6..61ef21ca014 100644 --- a/src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java +++ b/src/main/java/net/sf/jabref/model/bibtexkeypattern/GlobalBibtexKeyPattern.java @@ -19,14 +19,14 @@ public class GlobalBibtexKeyPattern extends AbstractBibtexKeyPattern { - private List defaultLabelPattern; + private List defaultBibtexKeyPattern; - public GlobalBibtexKeyPattern(List labelPattern) { - defaultLabelPattern = labelPattern; + public GlobalBibtexKeyPattern(List bibtexKeyPattern) { + defaultBibtexKeyPattern = bibtexKeyPattern; } @Override - public List getLastLevelLabelPattern(String key) { - return defaultLabelPattern; + public List getLastLevelBibtexKeyPattern(String key) { + return defaultBibtexKeyPattern; } } diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 0c250491e8b..aa8dd599814 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -292,8 +292,8 @@ public class JabRefPreferences { public static final String USE_DEFAULT_CONSOLE_APPLICATION = "useDefaultConsoleApplication"; // Currently, it is not possible to specify defaults for specific entry types - // When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getLabelPattern(); etc - public static final String DEFAULT_LABEL_PATTERN = "defaultLabelPattern"; + // When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getBibtexKeyPattern(); etc + public static final String DEFAULT_BIBTEX_KEY_PATTERN = "defaultLabelPattern"; public static final String SEARCH_MODE_FLOAT = "floatSearch"; public static final String GRAY_OUT_NON_HITS = "grayOutNonHits"; @@ -722,7 +722,7 @@ private JabRefPreferences() { defaults.put(CONFIRM_DELETE, Boolean.TRUE); defaults.put(GRAY_OUT_NON_HITS, Boolean.TRUE); defaults.put(SEARCH_MODE_FLOAT, Boolean.FALSE); - defaults.put(DEFAULT_LABEL_PATTERN, "[auth][year]"); + defaults.put(DEFAULT_BIBTEX_KEY_PATTERN, "[auth][year]"); defaults.put(PREVIEW_ENABLED, Boolean.TRUE); defaults.put(ACTIVE_PREVIEW, 0); defaults.put(PREVIEW_0, @@ -1139,13 +1139,13 @@ public void flush() { * @return LabelPattern containing all keys. Returned LabelPattern has no parent */ public GlobalBibtexKeyPattern getKeyPattern() { - keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_LABEL_PATTERN))); + keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); Preferences pre = Preferences.userNodeForPackage(GlobalBibtexKeyPattern.class); try { String[] keys = pre.keys(); if (keys.length > 0) { for (String key : keys) { - keyPattern.addLabelPattern(key, pre.get(key, null)); + keyPattern.addBibtexKeyPattern(key, pre.get(key, null)); } } } catch (BackingStoreException ex) { diff --git a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java index f6419c19c4e..641d3b3220d 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/BibtexParserTest.java @@ -1393,13 +1393,13 @@ public void integrationTestCustomKeyPattern() throws IOException { + OS.NEWLINE + "@comment{jabref-meta: keypatterndefault:test;}")); - AbstractBibtexKeyPattern labelPattern = result.getMetaData().getLabelPattern(); + AbstractBibtexKeyPattern bibtexKeyPattern = result.getMetaData().getBibtexKeyPattern(); AbstractBibtexKeyPattern expectedPattern = new DatabaseBibtexKeyPattern(Globals.prefs); expectedPattern.setDefaultValue("test"); - expectedPattern.addLabelPattern("article", "articleTest"); + expectedPattern.addBibtexKeyPattern("article", "articleTest"); - assertEquals(expectedPattern, labelPattern); + assertEquals(expectedPattern, bibtexKeyPattern); } @Test diff --git a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 5a850ff7dfc..79c59ec63b9 100644 --- a/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/net/sf/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -156,9 +156,9 @@ public void writeEpilogueAndEncoding() throws Exception { @Test public void writeMetadata() throws Exception { - DatabaseBibtexKeyPattern labelPattern = new DatabaseBibtexKeyPattern(Globals.prefs); - labelPattern.setDefaultValue("test"); - metaData.setLabelPattern(labelPattern); + DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs); + bibtexKeyPattern.setDefaultValue("test"); + metaData.setBibtexKeyPattern(bibtexKeyPattern); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences()); @@ -169,9 +169,9 @@ public void writeMetadata() throws Exception { @Test public void writeMetadataAndEncoding() throws Exception { SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII); - DatabaseBibtexKeyPattern labelPattern = new DatabaseBibtexKeyPattern(Globals.prefs); - labelPattern.setDefaultValue("test"); - metaData.setLabelPattern(labelPattern); + DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs); + bibtexKeyPattern.setDefaultValue("test"); + metaData.setBibtexKeyPattern(bibtexKeyPattern); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences); @@ -424,8 +424,8 @@ public void writeSaveOrderConfig() throws Exception { public void writeCustomKeyPattern() throws Exception { AbstractBibtexKeyPattern pattern = new DatabaseBibtexKeyPattern(Globals.prefs); pattern.setDefaultValue("test"); - pattern.addLabelPattern("article", "articleTest"); - metaData.setLabelPattern(pattern); + pattern.addBibtexKeyPattern("article", "articleTest"); + metaData.setBibtexKeyPattern(pattern); StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences()); diff --git a/src/test/resources/net/sf/jabref/customPreferences.xml b/src/test/resources/net/sf/jabref/customPreferences.xml index 4180f5a71ae..cecad1b31b6 100644 --- a/src/test/resources/net/sf/jabref/customPreferences.xml +++ b/src/test/resources/net/sf/jabref/customPreferences.xml @@ -192,7 +192,7 @@ - + From 1b1f14b195dbb07cfdc32f95fb6f022b5a00aa04 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Tue, 9 Aug 2016 21:45:50 +0200 Subject: [PATCH 4/9] use fixed subnode for bibtexKeyPattern pref storage --- .../java/net/sf/jabref/preferences/JabRefPreferences.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index aa8dd599814..4d88c3e0d4e 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -413,6 +413,8 @@ public class JabRefPreferences { private static final String CUSTOM_TYPE_OPT = "customTypeOpt_"; private static final String CUSTOM_TYPE_PRIOPT = "customTypePriOpt_"; + // Prefs node for BibtexKeyPatterns + private static final String BIBTEX_KEY_PATTERNS_NODE = "bibtexkeypatterns"; public String WRAPPED_USERNAME; public final String MARKING_WITH_NUMBER_PATTERN; @@ -1140,7 +1142,7 @@ public void flush() { */ public GlobalBibtexKeyPattern getKeyPattern() { keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern.split(JabRefPreferences.getInstance().get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); - Preferences pre = Preferences.userNodeForPackage(GlobalBibtexKeyPattern.class); + Preferences pre = Preferences.userNodeForPackage(JabRefMain.class).node(BIBTEX_KEY_PATTERNS_NODE); try { String[] keys = pre.keys(); if (keys.length > 0) { @@ -1163,7 +1165,7 @@ public void putKeyPattern(GlobalBibtexKeyPattern pattern) { keyPattern = pattern; // Store overridden definitions to Preferences. - Preferences pre = Preferences.userNodeForPackage(GlobalBibtexKeyPattern.class); + Preferences pre = Preferences.userNodeForPackage(JabRefMain.class).node(BIBTEX_KEY_PATTERNS_NODE); try { pre.clear(); // We remove all old entries. } catch (BackingStoreException ex) { From a547f8a2d8a70f8727e2cca5a54cd8ab5b2344b5 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Wed, 10 Aug 2016 14:46:09 +0200 Subject: [PATCH 5/9] add migration from labelPattern to bibtexKeyPattern --- src/main/java/net/sf/jabref/JabRefGUI.java | 1 + .../migrations/PreferencesMigrations.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/main/java/net/sf/jabref/JabRefGUI.java b/src/main/java/net/sf/jabref/JabRefGUI.java index fc5f530db67..58abf4242fb 100644 --- a/src/main/java/net/sf/jabref/JabRefGUI.java +++ b/src/main/java/net/sf/jabref/JabRefGUI.java @@ -90,6 +90,7 @@ private void openWindow() { // Perform checks and changes for users with a preference set from an older JabRef version. PreferencesMigrations.upgradeSortOrder(); PreferencesMigrations.upgradeFaultyEncodingStrings(); + PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern(); // This property is set to make the Mac OSX Java VM move the menu bar to the top of the screen if (OS.OS_X) { diff --git a/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java b/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java index 967b34b17a0..cf465d39dc2 100644 --- a/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java @@ -2,13 +2,22 @@ import java.util.HashMap; import java.util.Map; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; import net.sf.jabref.Globals; +import net.sf.jabref.JabRefMain; +import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; +import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern; import net.sf.jabref.model.entry.FieldName; import net.sf.jabref.preferences.JabRefPreferences; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + public class PreferencesMigrations { + private static final Log LOGGER = LogFactory.getLog(PreferencesMigrations.class); /** * Added from Jabref 2.11 beta 4 onwards to fix wrong encoding names @@ -79,4 +88,32 @@ public static void upgradeSortOrder() { } } + /** + * Migrate LabelPattern configuration from version 3.3-3.5 to new BibtexKeyPatterns + */ + public static void upgradeLabelPatternToBibtexKeyPattern() { + + try { + Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class); + + if (mainPrefsNode.nodeExists("bibtexkeypatterns")) { + return; //Pref node already exists do not migrate from previous version + } + + if (mainPrefsNode.nodeExists("logic/labelpattern")) { + LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version."); + JabRefPreferences prefs = Globals.prefs; + GlobalBibtexKeyPattern keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern + .split(prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); + Preferences oldPatternPrefs = mainPrefsNode.node("logic/labelpattern"); + for (String key : oldPatternPrefs.keys()) { + keyPattern.addBibtexKeyPattern(key, oldPatternPrefs.get(key, null)); + } + prefs.putKeyPattern(keyPattern); + } + } catch (BackingStoreException e) { + LOGGER.error("Migrating old bibtexKeyPatterns failed.", e); + } + } + } From 570233bdc105eaff45186ad6a623731084f9a4c6 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Wed, 10 Aug 2016 15:10:13 +0200 Subject: [PATCH 6/9] add migration for defaultLabelPattern pref key --- .../sf/jabref/migrations/PreferencesMigrations.java | 13 ++++++++++++- .../sf/jabref/preferences/JabRefPreferences.java | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java b/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java index cf465d39dc2..b8ab8733b92 100644 --- a/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java @@ -93,16 +93,27 @@ public static void upgradeSortOrder() { */ public static void upgradeLabelPatternToBibtexKeyPattern() { + JabRefPreferences prefs = Globals.prefs; + try { Preferences mainPrefsNode = Preferences.userNodeForPackage(JabRefMain.class); + 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."); + } + + } if (mainPrefsNode.nodeExists("bibtexkeypatterns")) { return; //Pref node already exists do not migrate from previous version } if (mainPrefsNode.nodeExists("logic/labelpattern")) { LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version."); - JabRefPreferences prefs = Globals.prefs; + GlobalBibtexKeyPattern keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern .split(prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); Preferences oldPatternPrefs = mainPrefsNode.node("logic/labelpattern"); diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 4d88c3e0d4e..391b627708b 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -293,7 +293,7 @@ public class JabRefPreferences { // Currently, it is not possible to specify defaults for specific entry types // When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.BibtexKeyPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getBibtexKeyPattern(); etc - public static final String DEFAULT_BIBTEX_KEY_PATTERN = "defaultLabelPattern"; + public static final String DEFAULT_BIBTEX_KEY_PATTERN = "defaultBibtexKeyPattern"; public static final String SEARCH_MODE_FLOAT = "floatSearch"; public static final String GRAY_OUT_NON_HITS = "grayOutNonHits"; From 784a9ae3cc010305103397c21eb3462f60f039e2 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Wed, 10 Aug 2016 15:10:34 +0200 Subject: [PATCH 7/9] use new name for help page --- .../sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java | 2 +- src/main/java/net/sf/jabref/logic/help/HelpFile.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java index 06afc9fd356..cbec0ac3650 100644 --- a/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java +++ b/src/main/java/net/sf/jabref/gui/bibtexkeypattern/BibtexKeyPatternPanel.java @@ -63,7 +63,7 @@ public class BibtexKeyPatternPanel extends JPanel { public BibtexKeyPatternPanel(BasePanel panel) { this.panel = panel; - help = new HelpAction(Localization.lang("Help on key patterns"), HelpFile.LABEL_PATTERN); + help = new HelpAction(Localization.lang("Help on key patterns"), HelpFile.BIBTEX_KEY_PATTERN); buildGUI(); } diff --git a/src/main/java/net/sf/jabref/logic/help/HelpFile.java b/src/main/java/net/sf/jabref/logic/help/HelpFile.java index 7b878bc65f2..2c7eaa8f430 100644 --- a/src/main/java/net/sf/jabref/logic/help/HelpFile.java +++ b/src/main/java/net/sf/jabref/logic/help/HelpFile.java @@ -31,7 +31,7 @@ public enum HelpFile { GROUP("GroupsHelp"), CONTENT_SELECTOR("ContentSelectorHelp"), SPECIAL_FIELDS("SpecialFieldsHelp"), - LABEL_PATTERN("LabelPatterns"), + BIBTEX_KEY_PATTERN("BibtexKeyPatterns"), OWNER("OwnerHelp"), TIMESTAMP("TimeStampHelp"), CUSTOM_EXPORTS("CustomExports"), From fd21ad401e699a9a045b3656274dd4d649635a2e Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Thu, 11 Aug 2016 11:33:15 +0200 Subject: [PATCH 8/9] add additional migrations for earliear version --- .../migrations/PreferencesMigrations.java | 34 +++++++++++++------ .../jabref/preferences/JabRefPreferences.java | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java b/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java index b8ab8733b92..4e421ef09de 100644 --- a/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/net/sf/jabref/migrations/PreferencesMigrations.java @@ -98,6 +98,7 @@ public static void upgradeLabelPatternToBibtexKeyPattern() { 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); @@ -107,24 +108,35 @@ public static void upgradeLabelPatternToBibtexKeyPattern() { } } - if (mainPrefsNode.nodeExists("bibtexkeypatterns")) { - return; //Pref node already exists do not migrate from previous version + //Pref node already exists do not migrate from previous version + if (mainPrefsNode.nodeExists(JabRefPreferences.BIBTEX_KEY_PATTERNS_NODE)) { + return; } + // Migrate type specific patterns + // Check for prefs node for Version 3.3-3.5 if (mainPrefsNode.nodeExists("logic/labelpattern")) { - LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version."); - - GlobalBibtexKeyPattern keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern - .split(prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); - Preferences oldPatternPrefs = mainPrefsNode.node("logic/labelpattern"); - for (String key : oldPatternPrefs.keys()) { - keyPattern.addBibtexKeyPattern(key, oldPatternPrefs.get(key, null)); - } - prefs.putKeyPattern(keyPattern); + 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); } } + private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences oldPatternPrefs) + throws BackingStoreException { + LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version."); + + GlobalBibtexKeyPattern keyPattern = new GlobalBibtexKeyPattern(AbstractBibtexKeyPattern + .split(prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); + for (String key : oldPatternPrefs.keys()) { + keyPattern.addBibtexKeyPattern(key, oldPatternPrefs.get(key, null)); + } + prefs.putKeyPattern(keyPattern); + } + } diff --git a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java index 391b627708b..ee5fee1a58b 100644 --- a/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/preferences/JabRefPreferences.java @@ -414,7 +414,7 @@ public class JabRefPreferences { private static final String CUSTOM_TYPE_PRIOPT = "customTypePriOpt_"; // Prefs node for BibtexKeyPatterns - private static final String BIBTEX_KEY_PATTERNS_NODE = "bibtexkeypatterns"; + public static final String BIBTEX_KEY_PATTERNS_NODE = "bibtexkeypatterns"; public String WRAPPED_USERNAME; public final String MARKING_WITH_NUMBER_PATTERN; From f2c438f722d24395e52620dee42404afd8434362 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Thu, 11 Aug 2016 12:10:43 +0200 Subject: [PATCH 9/9] add Changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0baad9ea57c..e57071da6c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Unified dialogs for opening/saving files ### Fixed -- Fixed [#1632](https://github.com/JabRef/jabref/issues/1632) User comments (@Comment) with or without brackets are now kept +- Fixed [#1632](https://github.com/JabRef/jabref/issues/1632): User comments (@Comment) with or without brackets are now kept - Fixed [#1264](https://github.com/JabRef/jabref/issues/1264): S with caron does not render correctly - LaTeX to Unicode converter now handles combining accents - Fixed NullPointerException when clicking Browse in Journal abbreviations with empty text field @@ -57,6 +57,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Fixed NullPointerException when clicking OK without specifying a field name in set/clear/rename fields - Fixed IndexOutOfBoundsException when trying to download a full text document without selecting an entry - Fixed NullPointerException when trying to set a special field or mark an entry through the menu without having an open database +- Fixed [#1257](https://github.com/JabRef/jabref/issues/1324): Preferences for the BibTeX key generator set in a version prior to 3.2 are now migrated automatically to the new version ### Removed - It is not longer possible to choose to convert HTML sub- and superscripts to equations