Skip to content

Commit

Permalink
Moved, removed, and used String constants
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jul 22, 2016
1 parent 23fdfe2 commit 8e5355b
Show file tree
Hide file tree
Showing 43 changed files with 360 additions and 362 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/BibDatabaseContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Objects;
import java.util.Optional;

import net.sf.jabref.logic.layout.format.FileLinkPreferences;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.BibDatabaseModeDetection;
Expand Down Expand Up @@ -137,7 +138,7 @@ public List<String> getFileDirectory(String fieldName) {
}

// 3. preferences directory
String dir = Globals.prefs.get(fieldName + Globals.DIR_SUFFIX); // FILE_DIR
String dir = Globals.prefs.get(fieldName + FileLinkPreferences.DIR_SUFFIX); // FILE_DIR
if (dir != null) {
fileDirs.add(dir);
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/net/sf/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,17 @@

public class Globals {

public static final String DIR_SUFFIX = "Directory";

// JabRef version info
public static final BuildInfo BUILD_INFO = new BuildInfo();
// Signature written at the top of the .bib file.
public static final String SIGNATURE = "This file was created with JabRef";
public static final String ENCODING_PREFIX = "Encoding: ";
// Character separating field names that are to be used in sequence as
// fallbacks for a single column (e.g. "author/editor" to use editor where
// author is not set):
public static final String COL_DEFINITION_FIELD_SEPARATOR = "/";
// Newlines
// will be overridden in initialization due to feature #857 @ JabRef.java
public static String NEWLINE = System.lineSeparator();

// Remote listener
public static final RemoteListenerServerLifecycle REMOTE_LISTENER = new RemoteListenerServerLifecycle();

public static final ImportFormatReader IMPORT_FORMAT_READER = new ImportFormatReader();


// Non-letters which are used to denote accents in LaTeX-commands, e.g., in {\"{a}}
public static final String SPECIAL_COMMAND_CHARS = "\"`^~'=.|";

// In the main program, this field is initialized in JabRef.java
// Each test case initializes this field if required
public static JabRefPreferences prefs;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.sf.jabref.logic.net.ProxyRegisterer;
import net.sf.jabref.logic.remote.RemotePreferences;
import net.sf.jabref.logic.remote.client.RemoteListenerClient;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.InternalBibtexFields;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -92,7 +93,7 @@ private static void start(String[] args) {

// override used newline character with the one stored in the preferences
// The preferences return the system newline character sequence as default
Globals.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE);
StringUtil.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE);

// Process arguments
ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.AbstractLabelPattern;
import net.sf.jabref.logic.labelpattern.DatabaseLabelPattern;
import net.sf.jabref.logic.layout.format.FileLinkPreferences;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.FieldName;
Expand All @@ -58,7 +59,7 @@ public class MetaData implements Iterable<String> {
private static final String DATABASE_TYPE = "databaseType";

private static final String GROUPSTREE = "groupstree";
private static final String FILE_DIRECTORY = FieldName.FILE + Globals.DIR_SUFFIX;
private static final String FILE_DIRECTORY = FieldName.FILE + FileLinkPreferences.DIR_SUFFIX;
public static final String SELECTOR_META_PREFIX = "selector_";
private static final String PROTECTED_FLAG_META = "protectedFlag";

Expand Down Expand Up @@ -364,7 +365,7 @@ public Map<String, String> getAsStringMap() {

//in case of save actions, add an additional newline after the enabled flag
if (metaItem.getKey().equals(SAVE_ACTIONS) && ("enabled".equals(dataItem) || "disabled".equals(dataItem))) {
stringBuilder.append(Globals.NEWLINE);
stringBuilder.append(StringUtil.NEWLINE);
}
}

Expand All @@ -379,12 +380,12 @@ public Map<String, String> getAsStringMap() {
// (which is always the AllEntriesGroup).
if ((groupsRoot != null) && (groupsRoot.getNumberOfChildren() > 0)) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Globals.NEWLINE);
stringBuilder.append(StringUtil.NEWLINE);

for (String groupNode : groupsRoot.getTreeAsString()) {
stringBuilder.append(StringUtil.quote(groupNode, ";", '\\'));
stringBuilder.append(";");
stringBuilder.append(Globals.NEWLINE);
stringBuilder.append(StringUtil.NEWLINE);
}
serializedMetaData.put(GROUPSTREE, stringBuilder.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;
import net.sf.jabref.logic.journals.JournalAbbreviationPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down Expand Up @@ -373,7 +374,7 @@ private void storeSettings() {
writer.write(entry.getName());
writer.write(" = ");
writer.write(entry.getAbbreviation());
writer.write(Globals.NEWLINE);
writer.write(StringUtil.NEWLINE);
}
} catch (IOException e) {
LOGGER.warn("Problem writing abbreviation file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import javax.swing.JLabel;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.layout.LayoutFormatter;
import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryUtil;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.FieldProperties;
import net.sf.jabref.model.entry.InternalBibtexFields;

Expand Down Expand Up @@ -64,7 +64,7 @@ public String getDisplayName() {
return null;
}

StringJoiner joiner = new StringJoiner(Globals.COL_DEFINITION_FIELD_SEPARATOR);
StringJoiner joiner = new StringJoiner(FieldName.COL_DEFINITION_FIELD_SEPARATOR);
for (String field : bibtexFields) {
joiner.add(field);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void updateTableFormat() {
// stored column name will be used as columnName
// There might be more than one field to display, e.g., "author/editor" or "date/year" - so split
// at MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR
String[] fields = columnName.split(Globals.COL_DEFINITION_FIELD_SEPARATOR);
String[] fields = columnName.split(FieldName.COL_DEFINITION_FIELD_SEPARATOR);
tableColumns.add(new MainTableColumn(columnName, Arrays.asList(fields), database));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
*/
public class PersistenceTableColumnListener implements TableColumnModelListener {

public static final String ACTIVATE_PREF_KEY = "ActivatePersistenceTableColumnListener";

public static final boolean DEFAULT_ENABLED = true;

private static final String SIMPLE_CLASS_NAME = PersistenceTableColumnListener.class.getSimpleName();

// needed to get column names / indices mapped from view to model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryType;
Expand Down Expand Up @@ -507,11 +508,11 @@ private boolean parseWithFreeCiteAndAddEntries() {

// we have to remove line breaks (but keep empty lines)
// otherwise, the result is broken
text = text.replace(Globals.NEWLINE.concat(Globals.NEWLINE), "##NEWLINE##");
text = text.replace(StringUtil.NEWLINE.concat(StringUtil.NEWLINE), "##NEWLINE##");
// possible URL line breaks are removed completely.
text = text.replace("/".concat(Globals.NEWLINE), "/");
text = text.replace(Globals.NEWLINE, " ");
text = text.replace("##NEWLINE##", Globals.NEWLINE);
text = text.replace("/".concat(StringUtil.NEWLINE), "/");
text = text.replace(StringUtil.NEWLINE, " ");
text = text.replace("##NEWLINE##", StringUtil.NEWLINE);

ParserResult importerResult = fimp.importEntries(text);
if(importerResult.hasWarnings()) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/net/sf/jabref/gui/preftabs/FileTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.format.FileLinkPreferences;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -200,7 +202,7 @@ public FileTab(JabRefFrame frame, JabRefPreferences prefs) {

@Override
public void setValues() {
fileDir.setText(prefs.get(FieldName.FILE + Globals.DIR_SUFFIX));
fileDir.setText(prefs.get(FieldName.FILE + FileLinkPreferences.DIR_SUFFIX));
bibLocAsPrimaryDir.setSelected(prefs.getBoolean(JabRefPreferences.BIB_LOC_AS_PRIMARY_DIR));
runAutoFileSearch.setSelected(prefs.getBoolean(JabRefPreferences.RUN_AUTOMATIC_FILE_SEARCH));
allowFileAutoOpenBrowse.setSelected(prefs.getBoolean(JabRefPreferences.ALLOW_FILE_AUTO_OPEN_BROWSE));
Expand Down Expand Up @@ -241,7 +243,7 @@ public void setValues() {

@Override
public void storeSettings() {
prefs.put(FieldName.FILE + Globals.DIR_SUFFIX, fileDir.getText());
prefs.put(FieldName.FILE + FileLinkPreferences.DIR_SUFFIX, fileDir.getText());
prefs.putBoolean(JabRefPreferences.BIB_LOC_AS_PRIMARY_DIR, bibLocAsPrimaryDir.isSelected());
prefs.putBoolean(JabRefPreferences.RUN_AUTOMATIC_FILE_SEARCH, runAutoFileSearch.isSelected());
prefs.putBoolean(JabRefPreferences.ALLOW_FILE_AUTO_OPEN_BROWSE, allowFileAutoOpenBrowse.isSelected());
Expand All @@ -265,7 +267,7 @@ public void storeSettings() {
}
prefs.put(JabRefPreferences.NEWLINE, newline);
// we also have to change Globals variable as globals is not a getter, but a constant
Globals.NEWLINE = newline;
StringUtil.NEWLINE = newline;

prefs.putBoolean(JabRefPreferences.REFORMAT_FILE_ON_SAVE_AND_EXPORT, reformatFileOnSaveAndExport.isSelected());
prefs.putBoolean(JabRefPreferences.BACKUP, backup.isSelected());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/importer/EntryFromPDFCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.InternalBibtexFields;
import net.sf.jabref.pdfimport.PdfImporter;
import net.sf.jabref.pdfimport.PdfImporter.ImportPdfFilesResult;
import net.sf.jabref.preferences.JabRefPreferences;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
Expand Down Expand Up @@ -97,7 +97,7 @@ private void addEntryDataFromPDDocumentInformation(File pdfFile, BibEntry entry)
// default time stamp follows ISO-8601. Reason: https://xkcd.com/1179/
String date = new SimpleDateFormat("yyyy-MM-dd")
.format(creationDate.getTime());
appendToField(entry, InternalBibtexFields.TIMESTAMP, date);
appendToField(entry, Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD), date);
}

if (pdfDocInfo.getCustomMetadataValue("bibtex/bibtexkey") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.BibtexEntryTypes;
import net.sf.jabref.model.entry.EntryType;
Expand Down Expand Up @@ -192,7 +193,7 @@ public ParserResult importEntries(String text) {
noteSB.append(ln);
noteSB.append(':');
noteSB.append(parser.getElementText());
noteSB.append(Globals.NEWLINE);
noteSB.append(StringUtil.NEWLINE);
}
}
parser.next();
Expand All @@ -202,7 +203,7 @@ public ParserResult importEntries(String text) {
String note;
if (e.hasField(FieldName.NOTE)) {
// "note" could have been set during the parsing as FreeCite also returns "note"
note = e.getFieldOptional(FieldName.NOTE).get().concat(Globals.NEWLINE).concat(noteSB.toString());
note = e.getFieldOptional(FieldName.NOTE).get().concat(StringUtil.NEWLINE).concat(noteSB.toString());
} else {
note = noteSB.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
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.util.strings.StringUtil;
import net.sf.jabref.model.entry.AuthorList;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
Expand Down Expand Up @@ -375,7 +375,7 @@ private void addAbstract(Map<String, String> hm, String lab, String value) {
if (oldAb == null) {
hm.put(FieldName.ABSTRACT, abstractValue);
} else {
hm.put(FieldName.ABSTRACT, oldAb + Globals.NEWLINE + abstractValue);
hm.put(FieldName.ABSTRACT, oldAb + StringUtil.NEWLINE + abstractValue);
}
} else if ("OAB".equals(lab) || "OABL".equals(lab)) {
hm.put("other-abstract", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
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.util.strings.StringUtil;
import net.sf.jabref.model.entry.AuthorList;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
Expand Down Expand Up @@ -194,7 +194,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
if (oldAb == null) {
hm.put(FieldName.ABSTRACT, val);
} else {
hm.put(FieldName.ABSTRACT, oldAb + Globals.NEWLINE + val);
hm.put(FieldName.ABSTRACT, oldAb + StringUtil.NEWLINE + val);
}
} else if ("UR".equals(lab)) {
hm.put(FieldName.URL, val);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/sf/jabref/logic/bibtex/BibEntryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.TreeSet;
import java.util.function.Predicate;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.TypedBibEntry;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.EntryTypes;
Expand Down Expand Up @@ -50,16 +49,16 @@ public void write(BibEntry entry, Writer out, BibDatabaseMode bibDatabaseMode, B
}

writeUserComments(entry, out);
out.write(Globals.NEWLINE);
out.write(StringUtil.NEWLINE);
writeRequiredFieldsFirstRemainingFieldsSecond(entry, out, bibDatabaseMode);
out.write(Globals.NEWLINE);
out.write(StringUtil.NEWLINE);
}

private void writeUserComments(BibEntry entry, Writer out) throws IOException {
String userComments = entry.getUserComments();

if(!userComments.isEmpty()) {
out.write(userComments + Globals.NEWLINE);
out.write(userComments + StringUtil.NEWLINE);
}
}

Expand Down Expand Up @@ -131,7 +130,7 @@ private void writeRequiredFieldsFirstRemainingFieldsSecond(BibEntry entry, Write

private void writeKeyField(BibEntry entry, Writer out) throws IOException {
String keyField = StringUtil.shaveString(entry.getCiteKey());
out.write(keyField + ',' + Globals.NEWLINE);
out.write(keyField + ',' + StringUtil.NEWLINE);
}

/**
Expand All @@ -151,7 +150,7 @@ private void writeField(BibEntry entry, Writer out, String name, int indentation

try {
out.write(fieldFormatter.format(field.get(), name));
out.write(',' + Globals.NEWLINE);
out.write(',' + StringUtil.NEWLINE);
} catch (IOException ex) {
throw new IOException("Error in field '" + name + "': " + ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.ArrayList;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.InternalBibtexFields;

Expand Down Expand Up @@ -77,11 +76,11 @@ public String format(String content, String fieldName)
String result = content;

// normalize newlines
boolean shouldNormalizeNewlines = !result.contains(Globals.NEWLINE) && result.contains("\n");
boolean shouldNormalizeNewlines = !result.contains(StringUtil.NEWLINE) && result.contains("\n");
if (shouldNormalizeNewlines) {
// if we don't have real new lines, but pseudo newlines, we replace them
// On Win 8.1, this is always true for multiline fields
result = result.replace("\n", Globals.NEWLINE);
result = result.replace("\n", StringUtil.NEWLINE);
}

// If the field is non-standard, we will just append braces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Objects;
import java.util.Optional;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.config.SaveOrderConfig;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.AuthorList;
Expand Down Expand Up @@ -65,7 +64,7 @@ public FieldComparator(String field) {

public FieldComparator(String field, boolean reversed) {
this.fieldName = Objects.requireNonNull(field);
this.field = fieldName.split(Globals.COL_DEFINITION_FIELD_SEPARATOR);
this.field = fieldName.split(FieldName.COL_DEFINITION_FIELD_SEPARATOR);
fieldType = determineFieldType();
isNumeric = InternalBibtexFields.isNumeric(this.field[0]);

Expand Down
Loading

0 comments on commit 8e5355b

Please sign in to comment.