Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved, removed, and used String constants #1618

Merged
merged 7 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 0 additions & 16 deletions src/main/java/net/sf/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,14 @@

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.OS;
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);
OS.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE);

// Process arguments
ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START);
Expand Down
10 changes: 6 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,8 @@
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.OS;
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 +60,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 +366,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(OS.NEWLINE);
}
}

Expand All @@ -379,12 +381,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(OS.NEWLINE);

for (String groupNode : groupsRoot.getTreeAsString()) {
stringBuilder.append(StringUtil.quote(groupNode, ";", '\\'));
stringBuilder.append(";");
stringBuilder.append(Globals.NEWLINE);
stringBuilder.append(OS.NEWLINE);
}
serializedMetaData.put(GROUPSTREE, stringBuilder.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ public void download(URL url, final DownloadCallback callback) throws IOExceptio
if (directory == null) {
dirPrefix = null;
} else {
if (directory.endsWith(System.getProperty("file.separator"))) {
if (directory.endsWith(OS.FILE_SEPARATOR)) {
dirPrefix = directory;
} else {
dirPrefix = directory + System.getProperty("file.separator");
dirPrefix = directory + OS.FILE_SEPARATOR;
}
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public void download(URL url, final DownloadCallback callback) throws IOExceptio
private File expandFilename(String directory, String link) {
File toFile = new File(link);
// If this is a relative link, we should perhaps append the directory:
String dirPrefix = directory + System.getProperty("file.separator");
String dirPrefix = directory + OS.FILE_SEPARATOR;
if (!toFile.isAbsolute()) {
toFile = new File(dirPrefix + link);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/external/DroppedFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.gui.undo.UndoableInsertEntry;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.database.BibDatabase;
Expand Down Expand Up @@ -478,7 +479,7 @@ private boolean doMove(String fileName, String destFilename,
LOGGER.warn("Cannot determine destination directory or destination directory does not exist");
return false;
}
File toFile = new File(dirs.get(found) + System.getProperty("file.separator") + destFilename);
File toFile = new File(dirs.get(found) + OS.FILE_SEPARATOR + destFilename);
if (toFile.exists()) {
int answer = JOptionPane.showConfirmDialog(frame,
Localization.lang("'%0' exists. Overwrite file?", toFile.getAbsolutePath()),
Expand Down Expand Up @@ -530,7 +531,7 @@ private boolean doCopy(String fileName, String toFile, NamedCompound edits) {
}
String destinationFileName = new File(toFile).getName();

File destFile = new File(dirs.get(found) + System.getProperty("file.separator") + destinationFileName);
File destFile = new File(dirs.get(found) + OS.FILE_SEPARATOR + destinationFileName);
if (destFile.equals(new File(fileName))) {
// File is already in the correct position. Don't override!
return true;
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public class ImportInspectionDialog extends JDialog implements ImportInspector,
private static final int FILE_COL = 2;
private static final int URL_COL = 3;
private static final int PAD = 4;
private static final String URL_FIELD = FieldName.URL;


/**
Expand Down Expand Up @@ -917,7 +916,7 @@ public void mouseClicked(MouseEvent e) {
fl.type)).actionPerformed(null);
}
} else { // Must be URL_COL
openExternalLink(URL_FIELD, e);
openExternalLink(FieldName.URL, e);
}
}
}
Expand Down Expand Up @@ -1130,14 +1129,14 @@ public void actionPerformed(ActionEvent event) {
}
BibEntry entry = selectionModel.getSelected().get(0);
String result = JOptionPane.showInputDialog(ImportInspectionDialog.this, Localization.lang("Enter URL"),
entry.getFieldOptional(URL_FIELD).orElse(""));
entry.getFieldOptional(FieldName.URL).orElse(""));
entries.getReadWriteLock().writeLock().lock();
try {
if (result != null) {
if (result.isEmpty()) {
entry.clearField(URL_FIELD);
entry.clearField(FieldName.URL);
} else {
entry.setField(URL_FIELD, result);
entry.setField(FieldName.URL, result);
}
}
} finally {
Expand Down Expand Up @@ -1308,7 +1307,7 @@ private void setupComparatorChooser() {
if (i == FILE_COL) {
comparators.add(new IconComparator(Collections.singletonList(FieldName.FILE)));
} else if (i == URL_COL) {
comparators.add(new IconComparator(Collections.singletonList(URL_FIELD)));
comparators.add(new IconComparator(Collections.singletonList(FieldName.URL)));
}

}
Expand Down Expand Up @@ -1428,16 +1427,16 @@ public Object getColumnValue(BibEntry entry, int i) {
FileListTableModel model = new FileListTableModel();
entry.getFieldOptional(FieldName.FILE).ifPresent(model::setContent);
fileLabel.setToolTipText(model.getToolTipHTMLRepresentation());
if (model.getRowCount() > 0 && model.getEntry(0).type.isPresent()) {
if ((model.getRowCount() > 0) && model.getEntry(0).type.isPresent()) {
fileLabel.setIcon(model.getEntry(0).type.get().getIcon());
}
return fileLabel;
} else {
return null;
}
case URL_COL:
if (entry.hasField(URL_FIELD)) {
urlLabel.setToolTipText(entry.getFieldOptional(URL_FIELD).orElse(""));
if (entry.hasField(FieldName.URL)) {
urlLabel.setToolTipText(entry.getFieldOptional(FieldName.URL).orElse(""));
return urlLabel;
} else {
return null;
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.OS;
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(OS.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.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.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 @@ -125,6 +125,7 @@
import net.sf.jabref.logic.bibtex.LatexFieldFormatter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.entry.BibEntry;
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(OS.NEWLINE.concat(OS.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(OS.NEWLINE), "/");
text = text.replace(OS.NEWLINE, " ");
text = text.replace("##NEWLINE##", OS.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.OS;
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;
OS.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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this field name moved from model to JabRefPreferences?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see. We might consider to drop this configuration option at some point in time. I don't really see why you might want to configure this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Moving ahead to date-added, date-modified (#1575, comment and JabRef#130) will sort this out.

}

if (pdfDocInfo.getCustomMetadataValue("bibtex/bibtexkey") != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/importer/fetcher/GVKParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private BibEntry parseEntry(Element e) {
// Dokumenttyp bestimmen und Eintrag anlegen

if (mak.startsWith("As")) {
entryType = "misc";
entryType = BibEntry.DEFAULT_TYPE;

if (quelle.contains("ISBN")) {
entryType = "incollection";
Expand All @@ -346,9 +346,9 @@ private BibEntry parseEntry(Element e) {
entryType = "article";
}
} else if (mak.isEmpty()) {
entryType = "misc";
entryType = BibEntry.DEFAULT_TYPE;
} else if (mak.startsWith("O")) {
entryType = "misc";
entryType = BibEntry.DEFAULT_TYPE;
// FIXME: online only available in Biblatex
//entryType = "online";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException {
}
}

String bibtexType = "misc";
String bibtexType = BibEntry.DEFAULT_TYPE;
// to find type, first check TW, then RT
for (int i = 1; (i >= 0) && "misc".equals(bibtexType); --i) {
for (int i = 1; (i >= 0) && BibEntry.DEFAULT_TYPE.equals(bibtexType); --i) {
if (type[i] == null) {
continue;
}
Expand Down
Loading