Skip to content

Commit

Permalink
Removed static initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jul 23, 2016
1 parent 17870e5 commit 09a4af0
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 67 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import net.sf.jabref.logic.exporter.ExportFormats;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;
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.net.ProxyAuthenticator;
import net.sf.jabref.logic.net.ProxyPreferences;
import net.sf.jabref.logic.net.ProxyRegisterer;
Expand Down Expand Up @@ -71,6 +73,9 @@ private static void start(String[] args) {
// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();

// Set key pattern based on preferences
LabelPatternUtil.updateDefaultPattern(LabelPatternPreferences.fromPreferences(Globals.prefs));

// Check for running JabRef
RemotePreferences remotePreferences = new RemotePreferences(Globals.prefs);
if (remotePreferences.useRemoteServer()) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/sf/jabref/gui/EntryTypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.CustomEntryType;
import net.sf.jabref.model.entry.EntryType;
import net.sf.jabref.preferences.JabRefPreferences;

/**
* This class extends FieldSetComponent to provide some required functionality for the
Expand Down Expand Up @@ -70,7 +72,8 @@ protected void addField(String str) {
return;
}

String testString = LabelPatternUtil.checkLegalKey(s);
String testString = LabelPatternUtil.checkLegalKey(s,
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(s) || (s.indexOf('&') >= 0)) {
// Report error and exit.
JOptionPane.showMessageDialog(this, Localization.lang("Entry type names are not allowed to contain white space or the following "
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/sf/jabref/gui/FieldSetComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionListener;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.preferences.JabRefPreferences;

/**
* @author alver
Expand Down Expand Up @@ -249,7 +251,8 @@ protected void addField(String str) {
return;
}

String testString = LabelPatternUtil.checkLegalKey(s);
String testString = LabelPatternUtil.checkLegalKey(s,
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(s) || (s.indexOf('&') >= 0)) {
// Report error and exit.
JOptionPane.showMessageDialog(this, Localization.lang("Field names are not allowed to contain white space or the following "
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ private void okActionPerformed() {
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
return;
}
String testString = LabelPatternUtil.checkLegalKey(parts[1]);
String testString = LabelPatternUtil.checkLegalKey(parts[1],
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if (!testString.equals(parts[1]) || (parts[1].indexOf('&') >= 0)) {
// Report error and exit.
JOptionPane.showMessageDialog(this, Localization.lang("Field names are not allowed to contain white space or the following "
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,8 @@ public void actionPerformed(ActionEvent event) {
}

// Make sure the key is legal:
String cleaned = LabelPatternUtil.checkLegalKey(newValue);
String cleaned = LabelPatternUtil.checkLegalKey(newValue,
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
if ((cleaned == null) || cleaned.equals(newValue)) {
textField.setValidBackgroundColor();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import java.util.Map;
import java.util.regex.Pattern;

import net.sf.jabref.Globals;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.model.entry.AuthorList;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;

/**
* Importer for the Refer/Endnote format.
Expand Down Expand Up @@ -236,7 +238,8 @@ 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, LabelPatternUtil.checkLegalKey(val,
Globals.prefs.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ public class LabelPatternPreferences {
private final String keyPatternReplacement;
private final boolean alwaysAddLetter;
private final boolean firstLetterA;
private final boolean enforceLegalKey;

public LabelPatternPreferences(String defaultLabelPattern, String keyPatternRegex, String keyPatternReplacement,
boolean alwaysAddLetter, boolean firstLetterA) {
boolean alwaysAddLetter, boolean firstLetterA, boolean enforceLegalKey) {
this.defaultLabelPattern = defaultLabelPattern;
this.keyPatternRegex = keyPatternRegex;
this.keyPatternReplacement = keyPatternReplacement;
this.alwaysAddLetter = alwaysAddLetter;
this.firstLetterA = firstLetterA;
this.enforceLegalKey = enforceLegalKey;
}

public static LabelPatternPreferences fromPreferences(JabRefPreferences jabRefPreferences) {
return new LabelPatternPreferences(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),
jabRefPreferences.getBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A));
jabRefPreferences.getBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A),
jabRefPreferences.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
}

public String getDefaultLabelPattern() {
Expand All @@ -46,4 +49,8 @@ public boolean isAlwaysAddLetter() {
public boolean isFirstLetterA() {
return firstLetterA;
}

public boolean isEnforceLegalKey() {
return enforceLegalKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.sf.jabref.model.entry.AuthorList;
import net.sf.jabref.model.entry.BibEntry;
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;
Expand All @@ -58,11 +57,6 @@ public class LabelPatternUtil {

private static final int CHARS_OF_FIRST = 5;


static {
updateDefaultPattern(LabelPatternPreferences.fromPreferences(JabRefPreferences.getInstance()));
}

private static BibDatabase database;


Expand Down Expand Up @@ -473,7 +467,7 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr
}

// Remove all illegal characters from the key.
key = checkLegalKey(stringBuilder.toString());
key = checkLegalKey(stringBuilder.toString(), labelPatternPreferences.isEnforceLegalKey());

// Remove Regular Expressions while generating Keys
String regex = labelPatternPreferences.getKeyPatternRegex();
Expand Down Expand Up @@ -1382,21 +1376,6 @@ private static String[] parseFieldMarker(String arg) {
return parts.toArray(new String[parts.size()]);
}

/**
* This method returns a String similar to the one passed in, except that it is molded into a form that is
* acceptable for bibtex.
* <p>
* Watch-out that the returned string might be of length 0 afterwards.
*
* @param key mayBeNull
*/
public static String checkLegalKey(String key) {
if (key == null) {
return null;
}
return checkLegalKey(key,
JabRefPreferences.getInstance().getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
}

/**
* This method returns a String similar to the one passed in, except that it is molded into a form that is
Expand Down
Loading

0 comments on commit 09a4af0

Please sign in to comment.