2 Copyright (C) 2003 David Weitzman, Morten O. Alver
4 All programs in this directory and
5 subdirectories are published under the GNU General Public License as
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 Further information about the GNU GPL is available at:
24 http://www.gnu.org/copyleft/gpl.ja.html
27 Modified for use in JabRef.
30 package net.sf.jabref;
32 import java.util.Iterator;
33 import java.util.TreeMap;
35 public abstract class BibtexEntryType implements Comparable<BibtexEntryType>
38 public static final BibtexEntryType OTHER =
41 public String getName()
46 public String[] getOptionalFields()
51 public String[] getRequiredFields()
57 public String describeRequiredFields()
62 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
69 public static final BibtexEntryType ARTICLE =
72 public String getName()
77 public String[] getOptionalFields()
81 "number", "month", "eid", "note"
85 public String[] getRequiredFields()
89 "author", "title", "journal", "year", "volume", "pages"
93 public String describeRequiredFields()
95 return "AUTHOR, TITLE, JOURNAL and YEAR";
98 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
100 return entry.allFieldsPresent(new String[]
102 "author", "title", "journal", "year", "bibtexkey", "volume", "pages"
107 public static final BibtexEntryType BOOKLET =
108 new BibtexEntryType()
110 public String getName()
115 public String[] getOptionalFields()
119 "author", "howpublished", "lastchecked", "address", "month", "year", "note"
123 public String[] getRequiredFields()
131 public String describeRequiredFields()
136 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
138 return entry.allFieldsPresent(new String[]
146 public static final BibtexEntryType INBOOK =
147 new BibtexEntryType()
149 public String getName()
154 public String[] getOptionalFields()
158 "volume", "number", "pages", "series", "type", "address", "edition",
163 public String[] getRequiredFields()
167 "chapter", "pages", "title", "publisher", "year", "editor",
172 public String describeRequiredFields()
174 return "TITLE, CHAPTER and/or PAGES, PUBLISHER, YEAR, and an "
175 +"EDITOR and/or AUTHOR";
178 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
180 return entry.allFieldsPresent(new String[]
182 "title", "publisher", "year", "bibtexkey"
184 (((entry.getField("author") != null) ||
185 (entry.getField("editor") != null)) &&
186 ((entry.getField("chapter") != null) ||
187 (entry.getField("pages") != null)));
191 public static final BibtexEntryType BOOK =
192 new BibtexEntryType()
194 public String getName()
199 public String[] getOptionalFields()
203 "volume", "number", "pages", "series", "address", "edition", "month",
208 public String[] getRequiredFields()
212 "title", "publisher", "year", "editor", "author"
216 public String describeRequiredFields()
218 return "TITLE, PUBLISHER, YEAR, and an EDITOR and/or AUTHOR";
221 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
223 return entry.allFieldsPresent(new String[]
225 "title", "publisher", "year", "bibtexkey"
227 ((entry.getField("author") != null) ||
228 (entry.getField("editor") != null));
233 public static final BibtexEntryType INCOLLECTION =
234 new BibtexEntryType()
236 public String getName()
238 return "Incollection";
241 public String[] getOptionalFields()
245 "editor", "volume", "number", "series", "type", "chapter",
246 "pages", "address", "edition", "month", "note"
250 public String[] getRequiredFields()
254 "author", "title", "booktitle", "publisher", "year"
258 public String describeRequiredFields()
260 return "AUTHOR, TITLE, BOOKTITLE, PUBLISHER and YEAR";
263 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
265 return entry.allFieldsPresent(new String[]
267 "author", "title", "booktitle", "publisher", "year",
274 public static final BibtexEntryType CONFERENCE =
275 new BibtexEntryType()
277 public String getName()
282 public String[] getOptionalFields()
286 "editor", "volume", "number", "series", "pages",
287 "address", "month", "organization", "publisher", "note"
291 public String[] getRequiredFields()
295 "author", "title", "booktitle", "year"
299 public String describeRequiredFields()
301 return "AUTHOR, TITLE, BOOKTITLE and YEAR";
304 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
306 return entry.allFieldsPresent(new String[]
308 "author", "title", "booktitle", "year" , "bibtexkey"
313 public static final BibtexEntryType INPROCEEDINGS =
314 new BibtexEntryType()
316 public String getName()
318 return "Inproceedings";
321 public String[] getOptionalFields()
325 "editor", "volume", "number", "series", "pages",
326 "address", "month", "organization", "publisher", "note"
330 public String[] getRequiredFields()
334 "author", "title", "booktitle", "year"
338 public String describeRequiredFields()
340 return "AUTHOR, TITLE, BOOKTITLE and YEAR";
343 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
345 return entry.allFieldsPresent(new String[]
347 "author", "title", "booktitle", "year" , "bibtexkey"
352 public static final BibtexEntryType PROCEEDINGS =
353 new BibtexEntryType()
355 public String getName()
357 return "Proceedings";
360 public String[] getOptionalFields()
364 "editor", "volume", "number", "series", "address",
365 "publisher", "note", "month", "organization"
369 public String[] getRequiredFields()
377 public String describeRequiredFields()
379 return "TITLE and YEAR";
382 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
384 return entry.allFieldsPresent(new String[]
386 "title", "year", "bibtexkey"
392 public static final BibtexEntryType MANUAL =
393 new BibtexEntryType()
395 public String getName()
400 public String[] getOptionalFields()
404 "author", "organization", "address", "edition",
405 "month", "year", "note"
409 public String[] getRequiredFields()
417 public String describeRequiredFields()
422 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
424 return entry.allFieldsPresent(new String[]
431 public static final BibtexEntryType TECHREPORT =
432 new BibtexEntryType()
434 public String getName()
439 public String[] getOptionalFields()
443 "type", "number", "address", "month", "note"
447 public String[] getRequiredFields()
451 "author", "title", "institution", "year"
455 public String describeRequiredFields()
457 return "AUTHOR, TITLE, INSTITUTION and YEAR";
460 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
462 return entry.allFieldsPresent(new String[]
464 "author", "title", "institution", "year",
471 public static final BibtexEntryType MASTERSTHESIS =
472 new BibtexEntryType()
474 public String getName()
476 return "Mastersthesis";
479 public String[] getOptionalFields()
483 "type", "address", "month", "note"
487 public String[] getRequiredFields()
491 "author", "title", "school", "year"
495 public String describeRequiredFields()
497 return "AUTHOR, TITLE, SCHOOL and YEAR";
500 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
502 return entry.allFieldsPresent(new String[]
504 "author", "title", "school", "year", "bibtexkey"
510 public static final BibtexEntryType PHDTHESIS =
511 new BibtexEntryType()
513 public String getName()
518 public String[] getOptionalFields()
522 "type", "address", "month", "note"
526 public String[] getRequiredFields()
530 "author", "title", "school", "year"
534 public String describeRequiredFields()
536 return "AUTHOR, TITLE, SCHOOL and YEAR";
539 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
541 return entry.allFieldsPresent(new String[]
543 "author", "title", "school", "year", "bibtexkey"
548 public static final BibtexEntryType UNPUBLISHED =
549 new BibtexEntryType()
551 public String getName()
553 return "Unpublished";
556 public String[] getOptionalFields()
564 public String[] getRequiredFields()
568 "author", "title", "note"
572 public String describeRequiredFields()
574 return "AUTHOR, TITLE and NOTE";
577 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
579 return entry.allFieldsPresent(new String[]
581 "author", "title", "note", "bibtexkey"
587 public static final BibtexEntryType MISC =
588 new BibtexEntryType()
590 public String getName()
595 public String[] getOptionalFields()
599 "author", "title", "howpublished", "month", "year", "note"
603 public String[] getRequiredFields()
608 public String describeRequiredFields()
613 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
615 return entry.allFieldsPresent(new String[]
623 * This type is provided as an emergency choice if the user makes
624 * customization changes that remove the type of an entry.
626 public static final BibtexEntryType TYPELESS =
627 new BibtexEntryType()
629 public String getName()
634 public String[] getOptionalFields()
639 public String[] getRequiredFields()
644 public String describeRequiredFields()
649 public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
656 public abstract String getName();
658 public int compareTo(BibtexEntryType o) {
659 return getName().compareTo(o.getName());
662 public abstract String[] getOptionalFields();
664 public abstract String[] getRequiredFields();
666 public String[] getGeneralFields() {
668 {"crossref", "keywords", "doi", "url",
669 "citeseerurl", "pdf", "abstract", "comment"};
672 public abstract String describeRequiredFields();
674 public abstract boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database);
677 public String[] getUtilityFields(){
678 return new String[] {"search" } ;
682 public boolean isRequired(String field) {
683 String[] req = getRequiredFields();
684 if (req == null) return false;
685 for (int i=0; i<req.length; i++)
686 if (req[i].equals(field)) return true;
690 public boolean isOptional(String field) {
691 String[] opt = getOptionalFields();
692 if (opt == null) return false;
693 for (int i=0; i<opt.length; i++)
694 if (opt[i].equals(field)) return true;
698 public static TreeMap<String, BibtexEntryType> ALL_TYPES = new TreeMap<String, BibtexEntryType>();
699 public static TreeMap<String, BibtexEntryType> STANDARD_TYPES = new TreeMap<String, BibtexEntryType>();
701 // Put the standard entry types into the type map.
702 ALL_TYPES.put("article", ARTICLE);
703 ALL_TYPES.put("inbook", INBOOK);
704 ALL_TYPES.put("book", BOOK);
705 ALL_TYPES.put("booklet", BOOKLET);
706 ALL_TYPES.put("incollection", INCOLLECTION);
707 ALL_TYPES.put("conference", CONFERENCE);
708 ALL_TYPES.put("inproceedings", INPROCEEDINGS);
709 ALL_TYPES.put("proceedings", PROCEEDINGS);
710 ALL_TYPES.put("manual", MANUAL);
711 ALL_TYPES.put("mastersthesis", MASTERSTHESIS);
712 ALL_TYPES.put("phdthesis", PHDTHESIS);
713 ALL_TYPES.put("techreport", TECHREPORT);
714 ALL_TYPES.put("unpublished", UNPUBLISHED);
715 ALL_TYPES.put("misc", MISC);
716 ALL_TYPES.put("other", OTHER);
718 // We need a record of the standard types, in case the user wants
719 // to remove a customized version. Therefore we clone the map.
720 STANDARD_TYPES = new TreeMap<String, BibtexEntryType>(ALL_TYPES);
724 * This method returns the BibtexEntryType for the name of a type,
725 * or null if it does not exist.
727 public static BibtexEntryType getType(String name) {
728 //Util.pr("'"+name+"'");
729 Object o = ALL_TYPES.get(name.toLowerCase());
732 else return (BibtexEntryType)o;
736 * This method returns the standard BibtexEntryType for the
737 * name of a type, or null if it does not exist.
739 public static BibtexEntryType getStandardType(String name) {
740 //Util.pr("'"+name+"'");
741 Object o = STANDARD_TYPES.get(name.toLowerCase());
744 else return (BibtexEntryType)o;
748 * Removes a customized entry type from the type map. If this type
749 * overrode a standard type, we reinstate the standard one.
751 * @param name The customized entry type to remove.
753 public static void removeType(String name) {
754 //BibtexEntryType type = getType(name);
755 String nm = name.toLowerCase();
756 //System.out.println(ALL_TYPES.size());
757 ALL_TYPES.remove(nm);
758 //System.out.println(ALL_TYPES.size());
759 if (STANDARD_TYPES.get(nm) != null) {
760 // In this case the user has removed a customized version
761 // of a standard type. We reinstate the standard type.
762 ALL_TYPES.put(nm, STANDARD_TYPES.get(nm));
768 * Load all custom entry types from preferences. This method is
769 * called from JabRef when the program starts.
771 public static void loadCustomEntryTypes(JabRefPreferences prefs) {
773 CustomEntryType type;
774 while ((type = prefs.getCustomEntryType(number)) != null) {
775 ALL_TYPES.put(type.getName().toLowerCase(), type);
781 * Iterate through all entry types, and store those that are
782 * custom defined to preferences. This method is called from
783 * JabRefFrame when the program closes.
785 public static void saveCustomEntryTypes(JabRefPreferences prefs) {
786 Iterator<String> i=ALL_TYPES.keySet().iterator();
788 //Vector customTypes = new Vector(10, 10);
789 while (i.hasNext()) {
790 Object o=ALL_TYPES.get(i.next());
791 if (o instanceof CustomEntryType) {
792 // Store this entry type.
793 prefs.storeCustomEntryType((CustomEntryType)o, number);
797 // Then, if there are more 'old' custom types defined, remove these
798 // from preferences. This is necessary if the number of custom types
800 prefs.purgeCustomEntryTypes(number);