234a79918d97c83a96c3e4fb705077d93bcf0fe8
[debian/jabref.git] / src / java / net / sf / jabref / BibtexEntryType.java
1 /*
2 Copyright (C) 2003 David Weitzman, Morten O. Alver
3
4 All programs in this directory and
5 subdirectories are published under the GNU General Public License as
6 described below.
7
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.
12
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.
17
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
21 USA
22
23 Further information about the GNU GPL is available at:
24 http://www.gnu.org/copyleft/gpl.ja.html
25
26 Note:
27 Modified for use in JabRef.
28
29 */
30 package net.sf.jabref;
31
32 import java.util.Iterator;
33 import java.util.TreeMap;
34 import java.util.Locale;
35
36 /**
37  * Provides a list of known entry types
38  *
39  * The list of optional and required fields is derived from http://en.wikipedia.org/wiki/BibTeX#Entry_types
40  */
41 public abstract class BibtexEntryType implements Comparable<BibtexEntryType>
42 {
43
44     public static final BibtexEntryType OTHER =
45         new BibtexEntryType()
46         {
47             public String getName()
48             {
49                 return "Other";
50             }
51
52             public String[] getOptionalFields()
53             {
54                 return new String[0];
55             }
56
57             public String[] getRequiredFields()
58             {
59                 return new String[0];
60             }
61
62
63             public String describeRequiredFields()
64             {
65                 return "";
66             }
67
68             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
69             {
70                 return true;
71             }
72         };
73
74
75     public static final BibtexEntryType ARTICLE =
76         new BibtexEntryType()
77         {
78             public String getName()
79             {
80                 return "Article";
81             }
82
83             public String[] getOptionalFields()
84             {
85                 return new String[]
86                 {
87                     "volume", "number", "pages", "month", "note", //- "volume", "pages", "part", "eid"
88                 };
89             }
90
91             public String[] getRequiredFields()
92             {
93                 return new String[]
94                 {
95                     "author", "title", "journal", "year" //+ "volume", "pages"
96                 };
97             }
98
99             public String describeRequiredFields()
100             {
101                 return "AUTHOR, TITLE, JOURNAL and YEAR";
102             }
103
104             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
105             {
106                 return entry.allFieldsPresent(new String[]
107                     {
108                         "author", "title", "journal", "year", "bibtexkey", "volume", "pages"
109                     }, database);
110             }
111         };
112
113     public static final BibtexEntryType BOOKLET =
114         new BibtexEntryType()
115         {
116             public String getName()
117             {
118                 return "Booklet";
119             }
120
121             public String[] getOptionalFields()
122             {
123                 return new String[]
124                 {
125                     "author", "howpublished", "address", "month", "year", "note" //+ "lastchecked"
126                 };
127             }
128
129             public String[] getRequiredFields()
130             {
131                 return new String[]
132                 {
133                     "title"
134                 };
135             }
136
137             public String describeRequiredFields()
138             {
139                 return "TITLE";
140             }
141
142             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
143             {
144                 return entry.allFieldsPresent(new String[]
145                     {
146                         "title", "bibtexkey"
147                     }, database);
148             }
149         };
150
151
152    public static final BibtexEntryType INBOOK =
153         new BibtexEntryType()
154         {
155             public String getName()
156             {
157                 return "InBook";
158             }
159
160             public String[] getOptionalFields()
161             {
162                 return new String[]
163                 {
164                     "volume", "number", "series", "type", "address", "edition",
165                     "month", "note" //+ "pages"
166                 };
167             }
168
169             public String[] getRequiredFields()
170             {
171                 return new String[]
172                 {
173                     "chapter", "pages", "title", "publisher", "year", "editor",
174                     "author"
175                 };
176             }
177
178             @Override
179             public String[] getRequiredFieldsForCustomization() {
180                 return new String[] {"author/editor", "title", "chapter/pages", "year", "publisher"};
181             }
182
183             public String describeRequiredFields()
184             {
185                 return "TITLE, CHAPTER and/or PAGES, PUBLISHER, YEAR, and an "
186                     +"EDITOR and/or AUTHOR";
187             }
188
189             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
190             {
191                 return entry.allFieldsPresent(new String[]
192                     {
193                         "title", "publisher", "year", "bibtexkey"
194                     }, database) &&
195                     (((entry.getField("author") != null) ||
196                       (entry.getField("editor") != null)) &&
197                      ((entry.getField("chapter") != null) ||
198                       (entry.getField("pages") != null)));
199             }
200         };
201
202     public static final BibtexEntryType BOOK =
203         new BibtexEntryType()
204         {
205             public String getName()
206             {
207                 return "Book";
208             }
209
210             public String[] getOptionalFields()
211             {
212                 return new String[]
213                 {
214                     "volume", "number", "series", "address", "edition", "month",
215                     "note" //+ pages
216                 };
217             }
218
219             public String[] getRequiredFields()
220             {
221                 return new String[]
222                 {
223                     "title", "publisher", "year", "editor", "author"
224                 };
225             }
226
227             public String[] getRequiredFieldsForCustomization()
228             {
229                 return new String[]
230                 {
231                     "title", "publisher", "year", "author/editor"
232                 };
233             }
234
235             public String describeRequiredFields()
236             {
237                 return "TITLE, PUBLISHER, YEAR, and an EDITOR and/or AUTHOR";
238             }
239
240             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
241             {
242                 return entry.allFieldsPresent(new String[]
243                     {
244                         "title", "publisher", "year", "bibtexkey"
245                     }, database) &&
246                 ((entry.getField("author") != null) ||
247                 (entry.getField("editor") != null));
248             }
249         };
250
251
252     public static final BibtexEntryType INCOLLECTION =
253         new BibtexEntryType()
254         {
255             public String getName()
256             {
257                 return "InCollection";
258             }
259
260             public String[] getOptionalFields()
261             {
262                 return new String[]
263                 {
264                     "editor", "volume", "number", "series", "type", "chapter",
265                     "pages", "address", "edition", "month", "note"
266                 };
267             }
268
269             public String[] getRequiredFields()
270             {
271                 return new String[]
272                 {
273                     "author", "title", "booktitle", "publisher", "year"
274                 };
275             }
276
277             public String describeRequiredFields()
278             {
279                 return "AUTHOR, TITLE, BOOKTITLE, PUBLISHER and YEAR";
280             }
281
282             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
283             {
284                 return entry.allFieldsPresent(new String[]
285                     {
286                         "author", "title", "booktitle", "publisher", "year",
287                         "bibtexkey"
288
289                     }, database);
290             }
291         };
292
293     public static final BibtexEntryType CONFERENCE =
294         new BibtexEntryType()
295         {
296             public String getName()
297             {
298                 return "Conference";
299             }
300
301             public String[] getOptionalFields()
302             {
303                 return new String[]
304                 {
305                     "editor", "volume", "number", "series", "pages",
306                     "address", "month", "organization", "publisher", "note"
307                 };
308             }
309
310             public String[] getRequiredFields()
311             {
312                 return new String[]
313                 {
314                     "author", "title", "booktitle", "year"
315                 };
316             }
317
318             public String describeRequiredFields()
319             {
320                 return "AUTHOR, TITLE, BOOKTITLE and YEAR";
321             }
322
323             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
324             {
325                 return entry.allFieldsPresent(new String[]
326                     {
327                         "author", "title", "booktitle", "year" , "bibtexkey"
328                     }, database);
329             }
330         };
331
332     public static final BibtexEntryType INPROCEEDINGS =
333         new BibtexEntryType()
334         {
335             public String getName()
336             {
337                 return "InProceedings";
338             }
339
340             public String[] getOptionalFields()
341             {
342                 return new String[]
343                 {
344                     "editor", "volume", "number", "series", "pages",
345                     "address", "month", "organization", "publisher", "note"
346                 };
347             }
348
349             public String[] getRequiredFields()
350             {
351                 return new String[]
352                 {
353                     "author", "title", "booktitle", "year"
354                 };
355             }
356
357             public String describeRequiredFields()
358             {
359                 return "AUTHOR, TITLE, BOOKTITLE and YEAR";
360             }
361
362             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
363             {
364                 return entry.allFieldsPresent(new String[]
365                     {
366                         "author", "title", "booktitle", "year" , "bibtexkey"
367                     }, database);
368             }
369         };
370
371     public static final BibtexEntryType PROCEEDINGS =
372         new BibtexEntryType()
373         {
374             public String getName()
375             {
376                 return "Proceedings";
377             }
378
379             public String[] getOptionalFields()
380             {
381                 return new String[]
382                 {
383                     "editor", "volume", "number", "series", "address",
384                     "publisher", "note", "month", "organization"
385                 };
386             }
387
388             public String[] getRequiredFields()
389             {
390                 return new String[]
391                 {
392                     "title", "year"
393                 };
394             }
395
396             public String describeRequiredFields()
397             {
398                 return "TITLE and YEAR";
399             }
400
401             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
402             {
403                 return entry.allFieldsPresent(new String[]
404                     {
405                         "title", "year", "bibtexkey"
406                     }, database);
407             }
408         };
409
410
411     public static final BibtexEntryType MANUAL =
412         new BibtexEntryType()
413         {
414             public String getName()
415             {
416                 return "Manual";
417             }
418
419             public String[] getOptionalFields()
420             {
421                 return new String[]
422                 {
423                     "author", "organization", "address", "edition",
424                     "month", "year", "note"
425                 };
426             }
427
428             public String[] getRequiredFields()
429             {
430                 return new String[]
431                 {
432                     "title"
433                 };
434             }
435
436             public String describeRequiredFields()
437             {
438                 return "TITLE";
439             }
440
441             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
442             {
443                 return entry.allFieldsPresent(new String[]
444                     {
445                         "title", "bibtexkey"
446                     }, database);
447             }
448         };
449
450     public static final BibtexEntryType TECHREPORT =
451         new BibtexEntryType()
452         {
453             public String getName()
454             {
455                 return "TechReport";
456             }
457
458             public String[] getOptionalFields()
459             {
460                 return new String[]
461                 {
462                     "type", "number", "address", "month", "note"
463                 };
464             }
465
466             public String[] getRequiredFields()
467             {
468                 return new String[]
469                 {
470                     "author", "title", "institution", "year"
471                 };
472             }
473
474             public String describeRequiredFields()
475             {
476                 return "AUTHOR, TITLE, INSTITUTION and YEAR";
477             }
478
479             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
480             {
481                 return entry.allFieldsPresent(new String[]
482                     {
483                         "author", "title", "institution", "year",
484                         "bibtexkey"
485                     }, database);
486             }
487         };
488
489
490     public static final BibtexEntryType MASTERSTHESIS =
491         new BibtexEntryType()
492         {
493             public String getName()
494             {
495                 return "MastersThesis";
496             }
497
498             public String[] getOptionalFields()
499             {
500                 return new String[]
501                 {
502                     "type", "address", "month", "note"
503                 };
504             }
505
506             public String[] getRequiredFields()
507             {
508                 return new String[]
509                 {
510                     "author", "title", "school", "year"
511                 };
512             }
513
514             public String describeRequiredFields()
515             {
516                 return "AUTHOR, TITLE, SCHOOL and YEAR";
517             }
518
519             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
520             {
521                 return entry.allFieldsPresent(new String[]
522                     {
523                         "author", "title", "school", "year", "bibtexkey"
524                     }, database);
525             }
526         };
527
528
529     public static final BibtexEntryType PHDTHESIS =
530         new BibtexEntryType()
531         {
532             public String getName()
533             {
534                 return "PhdThesis";
535             }
536
537             public String[] getOptionalFields()
538             {
539                 return new String[]
540                 {
541                     "type", "address", "month", "note"
542                 };
543             }
544
545             public String[] getRequiredFields()
546             {
547                 return new String[]
548                 {
549                     "author", "title", "school", "year"
550                 };
551             }
552
553             public String describeRequiredFields()
554             {
555                 return "AUTHOR, TITLE, SCHOOL and YEAR";
556             }
557
558             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
559             {
560                 return entry.allFieldsPresent(new String[]
561                     {
562                         "author", "title", "school", "year", "bibtexkey"
563                     }, database);
564             }
565         };
566
567     public static final BibtexEntryType UNPUBLISHED =
568         new BibtexEntryType()
569         {
570             public String getName()
571             {
572                 return "Unpublished";
573             }
574
575             public String[] getOptionalFields()
576             {
577                 return new String[]
578                 {
579                     "month", "year"
580                 };
581             }
582
583             public String[] getRequiredFields()
584             {
585                 return new String[]
586                 {
587                     "author", "title", "note"
588                 };
589             }
590
591             public String describeRequiredFields()
592             {
593                 return "AUTHOR, TITLE and NOTE";
594             }
595
596             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
597             {
598                 return entry.allFieldsPresent(new String[]
599                     {
600                         "author", "title", "note", "bibtexkey"
601                     }, database);
602             }
603         };
604
605      public static final BibtexEntryType PERIODICAL =
606         new BibtexEntryType()
607         {
608             public String getName()
609             {
610                 return "Periodical";
611             }
612
613             public String[] getOptionalFields()
614             {
615                 return new String[]
616                 {
617                     "editor", "language", "series", "volume", "number", "organization", "month", "note", "url"
618                 };
619             }
620
621             public String[] getRequiredFields()
622             {
623                 return new String[]
624                 {
625                     "title", "year"
626                 };
627             }
628
629             public String describeRequiredFields()
630             {
631                 return "TITLE and YEAR";
632             }
633
634             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
635             {
636                 return entry.allFieldsPresent(new String[]
637                     {
638                         "title", "year", "bibtexkey"
639                     }, database);
640             }
641         };
642
643      public static final BibtexEntryType PATENT =
644         new BibtexEntryType()
645         {
646             public String getName()
647             {
648                 return "Patent";
649             }
650
651             public String[] getOptionalFields()
652             {
653                 return new String[]
654                 {
655                     "author", "title", "language", "assignee", "address", "type", "number", "day", "dayfiled", "month", "monthfiled", "note", "url"
656                 };
657             }
658
659             public String[] getRequiredFields()
660             {
661                 return new String[]
662                 {
663                     "nationality", "number", "year", "yearfiled"
664                 };
665             }
666
667             public String describeRequiredFields()
668             {
669                 return "NATIONALITY, NUMBER, YEAR or YEARFILED";
670             }
671
672             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
673             {
674                 return entry.allFieldsPresent(new String[]
675                     {
676                         "number", "bibtexkey"
677                     }, database) &&
678                 ((entry.getField("year") != null) ||
679                 (entry.getField("yearfiled") != null));
680             }
681         };
682
683    public static final BibtexEntryType STANDARD =
684         new BibtexEntryType()
685         {
686             public String getName()
687             {
688                 return "Standard";
689             }
690
691             public String[] getOptionalFields()
692             {
693                 return new String[]
694                 {
695                     "author", "language", "howpublished", "type", "number", "revision", "address", "month", "year", "note", "url"
696                 };
697             }
698
699             public String[] getRequiredFields()
700             {
701                 return new String[]
702                 {
703                     "title", "organization", "institution"
704                 };
705             }
706
707             @Override
708             public String[] getRequiredFieldsForCustomization() {
709                 return new String[] {"title", "organization/institution"};
710             }
711
712             public String describeRequiredFields()
713             {
714                 return "TITLE, ORGANIZATION or INSTITUTION";
715             }
716
717             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
718             {
719                 return entry.allFieldsPresent(new String[]
720                     {
721                         "title", "bibtexkey"
722                     }, database) &&
723                 ((entry.getField("organization") != null) ||
724                 (entry.getField("institution") != null));
725             }
726         };
727
728     public static final BibtexEntryType ELECTRONIC =
729         new BibtexEntryType()
730         {
731             public String getName()
732             {
733                 return "Electronic";
734             }
735
736             public String[] getOptionalFields()
737             {
738                 return new String[]
739                 {
740                     "author", "month", "year", "title", "language", "howpublished", "organization", "address", "note", "url"
741                 };
742             }
743
744             public String[] getRequiredFields()
745             {
746                 return null;
747             }
748
749             public String describeRequiredFields()
750             {
751                 return "None";
752             }
753
754             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
755             {
756                 return entry.allFieldsPresent(new String[]
757                     {
758                         "bibtexkey"
759                     }, database);
760             }
761         };
762
763     public static final BibtexEntryType MISC =
764         new BibtexEntryType()
765         {
766             public String getName()
767             {
768                 return "Misc";
769             }
770
771             public String[] getOptionalFields()
772             {
773                 return new String[]
774                 {
775                     "author", "title", "howpublished", "month", "year", "note"
776                 };
777             }
778
779             public String[] getRequiredFields()
780             {
781                 return null;
782             }
783
784             public String describeRequiredFields()
785             {
786                 return "None";
787             }
788
789             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
790             {
791                 return entry.allFieldsPresent(new String[]
792                     {
793                         "bibtexkey"
794                     }, database);
795             }
796         };
797
798     /**
799      * This type is used for IEEEtran.bst to control various 
800      * be repeated or not. Not a very elegant solution, but it works...
801      */
802     public static final BibtexEntryType IEEETRANBSTCTL =
803         new BibtexEntryType()
804         {
805             public String getName()
806             {
807                 return "IEEEtranBSTCTL";
808             }
809
810             public String[] getOptionalFields()
811             {
812                 return new String[] {
813                 "ctluse_article_number", "ctluse_paper", "ctluse_forced_etal",
814                 "ctlmax_names_forced_etal", "ctlnames_show_etal", "ctluse_alt_spacing",
815                 "ctlalt_stretch_factor", "ctldash_repeated_names", "ctlname_format_string",
816                 "ctlname_latex_cmd", "ctlname_url_prefix"
817                 };
818             }
819
820             public String[] getRequiredFields()
821             {
822                 return null;
823             }
824
825             public String describeRequiredFields()
826             {
827                 return "None";
828             }
829
830             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
831             {
832                 return true;
833            }
834
835             public boolean isVisibleAtNewEntryDialog() {
836                 return false;
837             }
838 };
839
840     /**
841      * This type is provided as an emergency choice if the user makes
842      * customization changes that remove the type of an entry.
843      */
844     public static final BibtexEntryType TYPELESS =
845         new BibtexEntryType()
846         {
847             public String getName()
848             {
849                 return "Typeless";
850             }
851
852             public String[] getOptionalFields()
853             {
854                 return null;
855             }
856
857             public String[] getRequiredFields()
858             {
859                 return null;
860             }
861
862             public String describeRequiredFields()
863             {
864                 return "None";
865             }
866
867             public boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database)
868             {
869                 return false;
870            }
871         };
872
873
874     public abstract String getName();
875
876     public int compareTo(BibtexEntryType o) {
877         return getName().compareTo(o.getName());
878     }
879
880     public abstract String[] getOptionalFields();
881
882     public abstract String[] getRequiredFields();
883
884     public String[] getPrimaryOptionalFields() {
885         return new String[0];
886     }
887
888     public abstract String describeRequiredFields();
889
890     public abstract boolean hasAllRequiredFields(BibtexEntry entry, BibtexDatabase database);
891
892
893     public String[] getUtilityFields(){
894         return new String[] {"search" } ;
895     }
896
897
898     public boolean isRequired(String field) {
899         String[] req = getRequiredFields();
900         if (req == null) return false;
901         for (int i=0; i<req.length; i++)
902             if (req[i].equals(field)) return true;
903         return false;
904     }
905
906     public boolean isOptional(String field) {
907         String[] opt = getOptionalFields();
908         if (opt == null) return false;
909         for (int i=0; i<opt.length; i++)
910             if (opt[i].equals(field)) return true;
911         return false;
912     }
913     
914     public boolean isVisibleAtNewEntryDialog() {
915         return true;
916     }
917
918     public static TreeMap<String, BibtexEntryType> ALL_TYPES = new TreeMap<String, BibtexEntryType>();
919     public static TreeMap<String, BibtexEntryType> STANDARD_TYPES = new TreeMap<String, BibtexEntryType>();
920     static {
921         // Put the standard entry types into the type map.
922         if (!Globals.prefs.getBoolean("biblatexMode")) {
923             ALL_TYPES.put("article", ARTICLE);
924             ALL_TYPES.put("inbook", INBOOK);
925             ALL_TYPES.put("book", BOOK);
926             ALL_TYPES.put("booklet", BOOKLET);
927             ALL_TYPES.put("incollection", INCOLLECTION);
928             ALL_TYPES.put("conference", CONFERENCE);
929             ALL_TYPES.put("inproceedings", INPROCEEDINGS);
930             ALL_TYPES.put("proceedings", PROCEEDINGS);
931             ALL_TYPES.put("manual", MANUAL);
932             ALL_TYPES.put("mastersthesis", MASTERSTHESIS);
933             ALL_TYPES.put("phdthesis", PHDTHESIS);
934             ALL_TYPES.put("techreport", TECHREPORT);
935             ALL_TYPES.put("unpublished", UNPUBLISHED);
936             ALL_TYPES.put("patent", PATENT);
937             ALL_TYPES.put("standard", STANDARD);
938             ALL_TYPES.put("electronic", ELECTRONIC);
939             ALL_TYPES.put("periodical", PERIODICAL);
940             ALL_TYPES.put("misc", MISC);
941             ALL_TYPES.put("other", OTHER);
942             ALL_TYPES.put("ieeetranbstctl", IEEETRANBSTCTL);
943         }
944         else {
945             ALL_TYPES.put("article", BibLatexEntryTypes.ARTICLE);
946             ALL_TYPES.put("book", BibLatexEntryTypes.BOOK);
947             ALL_TYPES.put("inbook", BibLatexEntryTypes.INBOOK);
948             ALL_TYPES.put("bookinbook", BibLatexEntryTypes.BOOKINBOOK);
949             ALL_TYPES.put("suppbook", BibLatexEntryTypes.SUPPBOOK);
950             ALL_TYPES.put("booklet", BibLatexEntryTypes.BOOKLET);
951             ALL_TYPES.put("collection", BibLatexEntryTypes.COLLECTION);
952             ALL_TYPES.put("incollection", BibLatexEntryTypes.INCOLLECTION);
953             ALL_TYPES.put("suppcollection", BibLatexEntryTypes.SUPPCOLLECTION);
954             ALL_TYPES.put("manual", BibLatexEntryTypes.MANUAL);
955             ALL_TYPES.put("misc", BibLatexEntryTypes.MISC);
956             ALL_TYPES.put("online", BibLatexEntryTypes.ONLINE);
957             ALL_TYPES.put("patent", BibLatexEntryTypes.PATENT);
958             ALL_TYPES.put("periodical", BibLatexEntryTypes.PERIODICAL);
959             ALL_TYPES.put("suppperiodical", BibLatexEntryTypes.SUPPPERIODICAL);
960             ALL_TYPES.put("proceedings", BibLatexEntryTypes.PROCEEDINGS);
961             ALL_TYPES.put("inproceedings", BibLatexEntryTypes.INPROCEEDINGS);
962             ALL_TYPES.put("reference", BibLatexEntryTypes.REFERENCE);
963             ALL_TYPES.put("inreference", BibLatexEntryTypes.INREFERENCE);
964             ALL_TYPES.put("report", BibLatexEntryTypes.REPORT);
965             ALL_TYPES.put("set", BibLatexEntryTypes.SET);
966             ALL_TYPES.put("thesis", BibLatexEntryTypes.THESIS);
967             ALL_TYPES.put("unpublished", BibLatexEntryTypes.UNPUBLISHED);
968             ALL_TYPES.put("conference", BibLatexEntryTypes.CONFERENCE);
969             ALL_TYPES.put("electronic", BibLatexEntryTypes.ELECTRONIC);
970             ALL_TYPES.put("mastersthesis", BibLatexEntryTypes.MASTERSTHESIS);
971             ALL_TYPES.put("phdthesis", BibLatexEntryTypes.PHDTHESIS);
972             ALL_TYPES.put("techreport", BibLatexEntryTypes.TECHREPORT);
973             ALL_TYPES.put("www", BibLatexEntryTypes.WWW);
974             ALL_TYPES.put("ieeetranbstctl", BibLatexEntryTypes.IEEETRANBSTCTL);
975         }
976
977         // We need a record of the standard types, in case the user wants
978         // to remove a customized version. Therefore we clone the map.
979         STANDARD_TYPES = new TreeMap<String, BibtexEntryType>(ALL_TYPES);
980     }
981
982     /**
983      * This method returns the BibtexEntryType for the name of a type,
984      * or null if it does not exist.
985      */
986     public static BibtexEntryType getType(String name) {
987         //Util.pr("'"+name+"'");
988         Object o = ALL_TYPES.get(name.toLowerCase(Locale.US));
989         if (o == null)
990             return null;
991         else return (BibtexEntryType)o;
992     }
993
994     /**
995      * This method returns the standard BibtexEntryType for the
996      * name of a type, or null if it does not exist.
997      */
998     public static BibtexEntryType getStandardType(String name) {
999         //Util.pr("'"+name+"'");
1000         Object o = STANDARD_TYPES.get(name.toLowerCase());
1001         if (o == null)
1002             return null;
1003         else return (BibtexEntryType)o;
1004     }
1005
1006     /**
1007      * Removes a customized entry type from the type map. If this type
1008      * overrode a standard type, we reinstate the standard one.
1009      *
1010      * @param name The customized entry type to remove.
1011      */
1012     public static void removeType(String name) {
1013         //BibtexEntryType type = getType(name);
1014         String nm = name.toLowerCase();
1015         //System.out.println(ALL_TYPES.size());
1016         ALL_TYPES.remove(nm);
1017         //System.out.println(ALL_TYPES.size());
1018         if (STANDARD_TYPES.get(nm) != null) {
1019             // In this case the user has removed a customized version
1020             // of a standard type. We reinstate the standard type.
1021             ALL_TYPES.put(nm, STANDARD_TYPES.get(nm));
1022         }
1023
1024     }
1025
1026     /**
1027      * Load all custom entry types from preferences. This method is
1028      * called from JabRef when the program starts.
1029      */
1030     public static void loadCustomEntryTypes(JabRefPreferences prefs) {
1031         int number = 0;
1032         CustomEntryType type;
1033         while ((type = prefs.getCustomEntryType(number)) != null) {
1034             ALL_TYPES.put(type.getName().toLowerCase(), type);
1035             number++;
1036         }
1037     }
1038
1039     /**
1040      * Iterate through all entry types, and store those that are
1041      * custom defined to preferences. This method is called from
1042      * JabRefFrame when the program closes.
1043      */
1044     public static void saveCustomEntryTypes(JabRefPreferences prefs) {
1045         Iterator<String> i=ALL_TYPES.keySet().iterator();
1046         int number = 0;
1047         //Vector customTypes = new Vector(10, 10);
1048         while (i.hasNext()) {
1049             Object o=ALL_TYPES.get(i.next());
1050             if (o instanceof CustomEntryType) {
1051                 // Store this entry type.
1052                 prefs.storeCustomEntryType((CustomEntryType)o, number);
1053                 number++;
1054             }
1055         }
1056         // Then, if there are more 'old' custom types defined, remove these
1057         // from preferences. This is necessary if the number of custom types
1058         // has decreased.
1059         prefs.purgeCustomEntryTypes(number);
1060     }
1061
1062     /**
1063      * Get an array of the required fields in a form appropriate for the entry customization
1064      * dialog - that is, thie either-or fields together and separated by slashes.
1065      * @return Array of the required fields in a form appropriate for the entry customization dialog.
1066      */
1067     public String[] getRequiredFieldsForCustomization() {
1068         return getRequiredFields();
1069     }
1070 }