1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: BookCategory.java 2145 2011-04-05 01:15:52Z dmsmith $
21   */
22  package org.crosswire.jsword.book;
23  
24  import org.crosswire.jsword.JSMsg;
25  
26  /**
27   * An Enumeration of the possible types of Book.
28   *
29   * @see gnu.lgpl.License for license details.<br>
30   *      The copyright to this program is held by it's authors.
31   * @author Joe Walker [joe at eireneh dot com]
32   * @author DM Smith [dmsmith555 at yahoo dot com]
33   */
34  public enum BookCategory {
35      /** Books that are Bibles */
36      // TRANSLATOR: The name for the book category consisting of Bibles.
37      BIBLE("Biblical Texts", JSMsg.gettext("Biblical Texts")),
38  
39      /** Books that are Dictionaries */
40      // TRANSLATOR: The name for the book category consisting of Lexicons and Dictionaries.
41      DICTIONARY("Lexicons / Dictionaries", JSMsg.gettext("Dictionaries")),
42  
43      /** Books that are Commentaries */
44      // TRANSLATOR: The name for the book category consisting of Commentaries.
45      COMMENTARY("Commentaries", JSMsg.gettext("Commentaries")),
46  
47      /** Books that are indexed by day. AKA, Daily Devotions */
48      // TRANSLATOR: The name for the book category consisting of Daily Devotions, indexed by day of the year.
49      DAILY_DEVOTIONS("Daily Devotional", JSMsg.gettext("Daily Devotionals")),
50  
51      /** Books that map words from one language to another. */
52      // TRANSLATOR: The name for the book category consisting of Glossaries that map words/phrases from one language into another.
53      GLOSSARY("Glossaries", JSMsg.gettext("Glossaries")),
54  
55      /** Books that are questionable. */
56      // TRANSLATOR: The name for the book category consisting of books that are considered unorthodox by mainstream Christianity.
57      QUESTIONABLE("Cults / Unorthodox / Questionable Material", JSMsg.gettext("Cults / Unorthodox / Questionable Materials")),
58  
59      /** Books that are just essays. */
60      // TRANSLATOR: The name for the book category consisting of just essays.
61      ESSAYS("Essays", JSMsg.gettext("Essays")),
62  
63      /** Books that are predominately images. */
64      // TRANSLATOR: The name for the book category consisting of books containing mostly images.
65      IMAGES("Images", JSMsg.gettext("Images")),
66  
67      /** Books that are a collection of maps. */
68      // TRANSLATOR: The name for the book category consisting of books containing mostly maps.
69      MAPS("Maps", JSMsg.gettext("Maps")),
70  
71      /** Books that are just books. */
72      // TRANSLATOR: The name for the book category consisting of general books.
73      GENERAL_BOOK("Generic Books", JSMsg.gettext("General Books")),
74  
75      /** Books that are not any of the above. This is a catch all for new book categories. */
76      // TRANSLATOR: The name for the book category consisting of books not in any of the other categories.
77      OTHER("Other", JSMsg.gettext("Other"));
78  
79      /**
80       * @param name
81       *            The name of the BookCategory
82       */
83      private BookCategory(String name, String externalName) {
84          this.name = name;
85          this.externalName = externalName;
86      }
87  
88      /**
89       * Lookup method to convert from a String
90       */
91      public static BookCategory fromString(String name) {
92          for (BookCategory o : BookCategory.values()) {
93              if (o.name.equalsIgnoreCase(name)) {
94                  return o;
95              }
96          }
97          return OTHER;
98      }
99  
100     /**
101      * Lookup method to convert from a String
102      */
103     public static BookCategory fromExternalString(String name) {
104         for (BookCategory o : BookCategory.values()) {
105             if (o.externalName.equalsIgnoreCase(name)) {
106                 return o;
107             }
108         }
109         return OTHER;
110     }
111 
112     /**
113      * Lookup method to convert from an integer
114      */
115     public static BookCategory fromInteger(int i) {
116         for (BookCategory o : BookCategory.values()) {
117             if (i == o.ordinal()) {
118                 return o;
119             }
120         }
121         return OTHER;
122     }
123 
124     /**
125      * @return the internal name.
126      */
127     public String getName() {
128         return name;
129     }
130 
131     /**
132      * @return the internationalized name.
133      */
134     @Override
135     public String toString() {
136         return externalName;
137     }
138 
139     /**
140      * The names of the BookCategory
141      */
142     private transient String name;
143     private transient String externalName;
144 }
145