Skip to content

Commit

Permalink
Some more fields and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jul 21, 2016
1 parent 430f431 commit c7493d5
Show file tree
Hide file tree
Showing 57 changed files with 281 additions and 266 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public Optional<SaveOrderConfig> getSaveOrderConfig() {
* Add default metadata for new database:
*/
public void initializeNewDatabase() {
metaData.put(SELECTOR_META_PREFIX + "keywords", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.KEYWORDS, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.AUTHOR, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + "journal", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + "publisher", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.JOURNAL, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.PUBLISHER, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.REVIEW, new Vector<>());
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/ContentSelectorDialog2.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ private void setupFieldSelector() {
if (contents.isEmpty()) {
// if nothing was added, put the default fields (as described in the help)
fieldListModel.addElement(FieldName.AUTHOR);
fieldListModel.addElement("journal");
fieldListModel.addElement("keywords");
fieldListModel.addElement("publisher");
fieldListModel.addElement(FieldName.JOURNAL);
fieldListModel.addElement(FieldName.KEYWORDS);
fieldListModel.addElement(FieldName.PUBLISHER);
} else {
for (String s : contents) {
fieldListModel.addElement(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.specialfields.Printed;
import net.sf.jabref.specialfields.Priority;
Expand All @@ -67,8 +68,6 @@
import com.jgoodies.forms.builder.FormBuilder;
import com.jgoodies.forms.layout.FormLayout;

import static net.sf.jabref.model.entry.BibEntry.KEYWORDS_FIELD;

/**
* An Action for launching keyword managing dialog
*
Expand Down Expand Up @@ -195,7 +194,7 @@ public void keyPressed(KeyEvent arg0) {
});

AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters()
.get(KEYWORDS_FIELD);
.get(FieldName.KEYWORDS);
AutoCompleteListener acl = new AutoCompleteListener(autoComp);
keyword.addKeyListener(acl);
keyword.addFocusListener(acl);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private void setupFieldPanels() {

Set<String> deprecatedFields = new HashSet<>(EntryConverter.FIELD_ALIASES_TEX_TO_LTX.keySet());
deprecatedFields.add(FieldName.YEAR);
deprecatedFields.add("month");
deprecatedFields.add(FieldName.MONTH);
List<String> secondaryOptionalFields = type.getSecondaryOptionalFields();
List<String> optionalFieldsNotPrimaryOrDeprecated = new ArrayList<>(secondaryOptionalFields);
optionalFieldsNotPrimaryOrDeprecated.removeAll(deprecatedFields);
Expand Down Expand Up @@ -307,7 +307,7 @@ private void setupFieldPanels() {
// other fields
List<String> displayedFields = Stream.concat(requiredFields.stream(), displayedOptionalFields.stream()).map(String::toLowerCase).collect(Collectors.toList());
List<String> otherFields = entry.getFieldNames().stream().map(String::toLowerCase).filter(f -> !displayedFields.contains(f)).collect(Collectors.toList());
otherFields.remove("bibtexkey");
otherFields.remove(BibEntry.KEY_FIELD);
otherFields.removeAll(Globals.prefs.getCustomTabFieldNames());

if (!otherFields.isEmpty()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.search.SearchQuery;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;

import com.jgoodies.forms.builder.ButtonBarBuilder;
Expand Down Expand Up @@ -89,7 +90,7 @@ class GroupDialog extends JDialog {
Localization.lang("Include subgroups: When selected, view entries contained in this group or its subgroups"));
// for KeywordGroup
private final JTextField keywordGroupSearchField = new JTextField(GroupDialog.TEXTFIELD_LENGTH);
private final TextField keywordGroupSearchTerm = new TextField("keywords", "", false);
private final TextField keywordGroupSearchTerm = new TextField(FieldName.KEYWORDS, "", false);
private final JCheckBox keywordGroupCaseSensitive = new JCheckBox(Localization.lang("Case sensitive"));
private final JCheckBox keywordGroupRegExp = new JCheckBox(Localization.lang("regular expression"));
// for SearchGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.sf.jabref.logic.groups.AbstractGroup;
import net.sf.jabref.logic.groups.KeywordGroup;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.InternalBibtexFields;

public class WarnAssignmentSideEffects {
Expand All @@ -30,7 +31,7 @@ public static boolean warnAssignmentSideEffects(List<AbstractGroup> groups, Comp
if (group instanceof KeywordGroup) {
KeywordGroup keywordGroup = (KeywordGroup) group;
String field = keywordGroup.getSearchField().toLowerCase();
if ("keywords".equals(field) || "groups".equals(field)) {
if (FieldName.KEYWORDS.equals(field) || "groups".equals(field)) {
continue; // this is not undesired
}
int len = InternalBibtexFields.numberOfPublicFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.sf.jabref.logic.journals.JournalAbbreviationPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

/**
* Converts journal full names to either iso or medline abbreviations for all selected entries.
Expand Down Expand Up @@ -60,10 +61,10 @@ public void run() {
NamedCompound ce = new NamedCompound(Localization.lang("Abbreviate journal names"));
int count = 0;
for (BibEntry entry : entries) {
if (undoableAbbreviator.abbreviate(panel.getDatabase(), entry, "journal", ce)) {
if (undoableAbbreviator.abbreviate(panel.getDatabase(), entry, FieldName.JOURNAL, ce)) {
count++;
}
if (undoableAbbreviator.abbreviate(panel.getDatabase(), entry, "journaltitle", ce)) {
if (undoableAbbreviator.abbreviate(panel.getDatabase(), entry, FieldName.JOURNALTITLE, ce)) {
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.sf.jabref.logic.journals.JournalAbbreviationPreferences;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

/**
* Converts journal abbreviations back to full name for all selected entries.
Expand Down Expand Up @@ -57,10 +58,10 @@ public void run() {
NamedCompound ce = new NamedCompound(Localization.lang("Unabbreviate journal names"));
int count = 0;
for (BibEntry entry : entries) {
if (undoableAbbreviator.unabbreviate(panel.getDatabase(), entry, "journal", ce)) {
if (undoableAbbreviator.unabbreviate(panel.getDatabase(), entry, FieldName.JOURNAL, ce)) {
count++;
}
if (undoableAbbreviator.unabbreviate(panel.getDatabase(), entry, "journaltitle", ce)) {
if (undoableAbbreviator.unabbreviate(panel.getDatabase(), entry, FieldName.JOURNALTITLE, ce)) {
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ private void setupPrevEntry() {
prevEntry.setField(FieldName.AUTHOR, "Smith, Bill and Jones, Bob and Williams, Jeff");
prevEntry.setField(FieldName.EDITOR, "Taylor, Phil");
prevEntry.setField(FieldName.TITLE, "Title of the test entry for reference styles");
prevEntry.setField("volume", "34");
prevEntry.setField(FieldName.VOLUME, "34");
prevEntry.setField(FieldName.YEAR, "2008");
prevEntry.setField("journal", "BibTeX journal");
prevEntry.setField("publisher", "JabRef publishing");
prevEntry.setField(FieldName.JOURNAL, "BibTeX journal");
prevEntry.setField(FieldName.PUBLISHER, "JabRef publishing");
prevEntry.setField("address", "Trondheim");
prevEntry.setField("www", "https://github.com/JabRef");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryType;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.FieldProperties;
import net.sf.jabref.model.entry.InternalBibtexFields;
import net.sf.jabref.preferences.JabRefPreferences;
Expand Down Expand Up @@ -475,7 +476,7 @@ private void insertTextForTag(boolean overrideField) {
// insert a new name with an additional "and"
if (InternalBibtexFields.getFieldExtras(fieldName).contains(FieldProperties.PERSON_NAMES)) {
entry.setField(fieldName, old.get() + " and " + txt);
} else if ("keywords".equals(fieldName)) {
} else if (FieldName.KEYWORDS.equals(fieldName)) {
// Add keyword
entry.addKeyword(txt, Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/gui/preftabs/PreviewPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ private static BibEntry getTestEntry() {
PreviewPrefsTab.entry.setField(FieldName.TITLE,
"Amino acid metabolism and protein turnover in larval turbot (Scophthalmus maximus) fed natural zooplankton or Artemia");
PreviewPrefsTab.entry.setField(FieldName.YEAR, "1997");
PreviewPrefsTab.entry.setField("journal", "Marine Biology");
PreviewPrefsTab.entry.setField("month", "January");
PreviewPrefsTab.entry.setField("number", "2");
PreviewPrefsTab.entry.setField("volume", "123");
PreviewPrefsTab.entry.setField(FieldName.JOURNAL, "Marine Biology");
PreviewPrefsTab.entry.setField(FieldName.MONTH, "January");
PreviewPrefsTab.entry.setField(FieldName.NUMBER, "2");
PreviewPrefsTab.entry.setField(FieldName.VOLUME, "123");
PreviewPrefsTab.entry.setField("pdf", "conceicao1997.pdf");
PreviewPrefsTab.entry.setField(FieldName.PAGES, "255--265");
PreviewPrefsTab.entry.setField("keywords", "energetics, artemia, metabolism, amino acid, turbot");
PreviewPrefsTab.entry.setField(FieldName.KEYWORDS, "energetics, artemia, metabolism, amino acid, turbot");
PreviewPrefsTab.entry.setField(FieldName.URL, "http://ejournals.ebsco.com/direct.asp?ArticleID=TYY4NT82XA9H7R8PFPPV");
PreviewPrefsTab.entry.setField(FieldName.ABSTRACT,
"Abstract The present paper studied the influence of different food regimes "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class SearchResultsDialog {

private JDialog diag;
private static final String[] FIELDS = new String[] {
FieldName.AUTHOR, FieldName.TITLE, FieldName.YEAR, "journal"
FieldName.AUTHOR, FieldName.TITLE, FieldName.YEAR, FieldName.JOURNAL
};
private static final int FILE_COL = 0;
private static final int URL_COL = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Optional<BibEntry> createEntry(File f, boolean addPathTokensAsKeywords) {
}

if (addPathTokensAsKeywords) {
appendToField(newEntry.get(), "keywords", extractPathesToKeyWordsfield(f.getAbsolutePath()));
appendToField(newEntry.get(), FieldName.KEYWORDS, extractPathesToKeyWordsfield(f.getAbsolutePath()));
}

if (!newEntry.get().hasField(FieldName.TITLE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;

Expand Down Expand Up @@ -96,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, "timestamp", date);
appendToField(entry, InternalBibtexFields.TIMESTAMP, date);
}

if (pdfDocInfo.getCustomMetadataValue("bibtex/bibtexkey") != null) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/importer/OAI2Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public void endElement(String uri, String localName, String qualifiedName) throw
forenames = content;
} else if ("journal-ref".equals(qualifiedName)) {
String journal = content.replaceFirst("[0-9].*", "");
entry.setField("journal", journal);
entry.setField(FieldName.JOURNAL, journal);
String volume = content.replaceFirst(journal, "");
volume = volume.replaceFirst(" .*", "");
entry.setField("volume", volume);
entry.setField(FieldName.VOLUME, volume);
String year = content.replaceFirst(".*?\\(", "");
year = year.replaceFirst("\\).*", "");
entry.setField(FieldName.YEAR, year);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/importer/fetcher/GVKParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private BibEntry parseEntry(Element e) {
result.setField("subtitle", newSubtitle.toString());
}
if (publisher != null) {
result.setField("publisher", publisher);
result.setField(FieldName.PUBLISHER, publisher);
}
if (year != null) {
result.setField(FieldName.YEAR, year);
Expand All @@ -406,7 +406,7 @@ private BibEntry parseEntry(Element e) {
result.setField(FieldName.ISSN, issn);
}
if (number != null) {
result.setField("number", number);
result.setField(FieldName.NUMBER, number);
}
if (pagetotal != null) {
result.setField("pagetotal", pagetotal);
Expand All @@ -415,10 +415,10 @@ private BibEntry parseEntry(Element e) {
result.setField(FieldName.PAGES, pages);
}
if (volume != null) {
result.setField("volume", volume);
result.setField(FieldName.VOLUME, volume);
}
if (journal != null) {
result.setField("journal", journal);
result.setField(FieldName.JOURNAL, journal);
}
if (ppn != null) {
result.setField("ppn_GVK", ppn);
Expand All @@ -431,7 +431,7 @@ private BibEntry parseEntry(Element e) {
}

if ("article".equals(entryType) && (journal != null)) {
result.setField("journal", journal);
result.setField(FieldName.JOURNAL, journal);
} else if ("incollection".equals(entryType) && (booktitle != null)) {
result.setField("booktitle", booktitle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private BibEntry cleanup(BibEntry entry) {
}

// clean up month
String month = entry.getField("month");
String month = entry.getField(FieldName.MONTH);
if ((month != null) && !month.isEmpty()) {
month = month.replace(".", "");
month = month.toLowerCase();
Expand Down Expand Up @@ -352,7 +352,7 @@ private BibEntry cleanup(BibEntry entry) {
.append(mm.group(3)).append(',');
}
}
entry.setField("month", date.toString());
entry.setField(FieldName.MONTH, date.toString());
}

// clean up pages
Expand All @@ -372,7 +372,7 @@ private BibEntry cleanup(BibEntry entry) {
String type = entry.getType();
String sourceField = "";
if ("article".equals(type)) {
sourceField = "journal";
sourceField = FieldName.JOURNAL;
entry.clearField("booktitle");
} else if ("inproceedings".equals(type)) {
sourceField = "booktitle";
Expand All @@ -384,9 +384,9 @@ private BibEntry cleanup(BibEntry entry) {
if (ind > 0) {
fullName = fullName.substring(0, ind);
entry.setField(FieldName.YEAR, "to be published");
entry.clearField("month");
entry.clearField(FieldName.MONTH);
entry.clearField(FieldName.PAGES);
entry.clearField("number");
entry.clearField(FieldName.NUMBER);
}
String[] parts = fullName.split("[\\[\\]]"); //[see also...], [legacy...]
fullName = parts[0];
Expand All @@ -396,9 +396,9 @@ private BibEntry cleanup(BibEntry entry) {
String note = entry.getField("note");
if ("Early Access".equals(note)) {
entry.setField(FieldName.YEAR, "to be published");
entry.clearField("month");
entry.clearField(FieldName.MONTH);
entry.clearField(FieldName.PAGES);
entry.clearField("number");
entry.clearField(FieldName.NUMBER);
}
} else {
fullName = fullName.replace("Conference Proceedings", "Proceedings")
Expand Down Expand Up @@ -510,7 +510,7 @@ private BibEntry cleanup(BibEntry entry) {
.ifPresent(url -> entry.setField(FieldName.URL, "http://ieeexplore.ieee.org" + url.replace("tp=&", "")));

// Replace ; as keyword separator
entry.getFieldOptional("keywords").ifPresent(keys -> entry.setField("keywords",
entry.getFieldOptional(FieldName.KEYWORDS).ifPresent(keys -> entry.setField(FieldName.KEYWORDS,
keys.replace(";", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR))));
return entry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public BibEntry importOai2Entry(String key) {
int monthNumber = Integer.parseInt(fixedKey.substring(2, 4));
MonthUtil.Month month = MonthUtil.getMonthByNumber(monthNumber);
if (month.isValid()) {
be.setField("month", month.bibtexFormat);
be.setField(FieldName.MONTH, month.bibtexFormat);
}
}
}
Expand Down
Loading

0 comments on commit c7493d5

Please sign in to comment.