1
20 package org.crosswire.jsword.book.basic;
21
22 import java.net.URI;
23
24 import org.crosswire.common.util.Language;
25 import org.crosswire.jsword.book.BookDriver;
26 import org.crosswire.jsword.book.BookException;
27 import org.crosswire.jsword.book.BookMetaData;
28 import org.crosswire.jsword.book.FeatureType;
29 import org.crosswire.jsword.book.KeyType;
30 import org.crosswire.jsword.index.IndexStatus;
31 import org.jdom2.Document;
32
33
39
40
45 public abstract class AbstractBookMetaData implements BookMetaData {
46
47
50 public KeyType getKeyType() {
51 return KeyType.LIST;
52 }
53
54
57 public BookDriver getDriver() {
58 return driver;
59 }
60
61
64 public String getDriverName() {
65 if (getDriver() == null) {
66 return null;
67 }
68
69 return getDriver().getDriverName();
70 }
71
72
75 public boolean hasFeature(FeatureType feature) {
76 return false;
77 }
78
79
82 public String getOsisID() {
83 return getBookCategory().getName() + '.' + getInitials();
84 }
85
86
89 public boolean isSupported() {
90 return true;
91 }
92
93
96 public boolean isEnciphered() {
97 return false;
98 }
99
100
103 public boolean isLocked() {
104 return false;
105 }
106
107
110 public boolean unlock(String unlockKey) {
111 return false;
112 }
113
114
117 public String getUnlockKey() {
118 return null;
119 }
120
121
124 public boolean isQuestionable() {
125 return false;
126 }
127
128
131 public Language getLanguage() {
132 return this.language;
133 }
134
135
138 public void setLanguage(Language language) {
139 this.language = language;
140 }
141
142
145 public URI getLibrary() {
146 return library;
147 }
148
149
152 public void setLibrary(URI library) throws BookException {
153 this.library = library;
154 }
155
156
159 public void setLocation(URI location) {
160 this.location = location;
161 }
162
163
166 public URI getLocation() {
167 return location;
168 }
169
170
173 public IndexStatus getIndexStatus() {
174 return indexStatus;
175 }
176
177
180 public void setIndexStatus(IndexStatus newValue) {
181 indexStatus = newValue;
182 }
183
184
187 public void reload() throws BookException {
188 }
190
191
194 public void putProperty(String key, String value) {
195 putProperty(key, value, false);
196 }
197
198
201 public Document toOSIS() {
202 throw new UnsupportedOperationException("If you want to use this, implement it.");
203 }
204
205
208 public void setDriver(BookDriver driver) {
209 this.driver = driver;
210 }
211
212 @Override
213 public boolean equals(Object obj) {
214 if (obj == null) {
216 return false;
217 }
218
219
222 if (!obj.getClass().equals(this.getClass())) {
225 return false;
226 }
227
228 BookMetaData that = (BookMetaData) obj;
230
231 return getBookCategory().equals(that.getBookCategory()) && getName().equals(that.getName()) && getInitials().equals(that.getInitials());
232 }
233
234 @Override
235 public int hashCode() {
236 return getName().hashCode();
237 }
238
239
244 public int compareTo(BookMetaData obj) {
245 int result = this.getBookCategory().compareTo(obj.getBookCategory());
246 if (result == 0) {
247 result = this.getAbbreviation().compareTo(obj.getAbbreviation());
248 }
249 if (result == 0) {
250 result = this.getInitials().compareTo(obj.getInitials());
251 }
252 if (result == 0) {
253 result = this.getName().compareTo(obj.getName());
254 }
255 return result;
256 }
257
258 @Override
259 public String toString() {
260 String internal = getInitials();
261 String abbreviation = getAbbreviation();
262 if (internal.equals(abbreviation)) {
263 return internal;
264 }
265 StringBuffer buf = new StringBuffer(internal);
266 buf.append('(');
267 buf.append(abbreviation);
268 buf.append(')');
269 return buf.toString();
270 }
271
272 private BookDriver driver;
273 private IndexStatus indexStatus = IndexStatus.UNDONE;
274 private Language language;
275 private URI library;
276 private URI location;
277
278 }
279