| VerseFactory.java |
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: VerseFactory.java 2223 2012-01-26 21:28:02Z dmsmith $
21 */
22 package org.crosswire.jsword.passage;
23
24 import org.crosswire.jsword.versification.Versification;
25
26 /**
27 * A factory to create a Verse from user input.
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 */
33 public final class VerseFactory {
34 /**
35 * Prevent a VerseFactory from being created.
36 */
37 private VerseFactory() {
38 }
39
40 /**
41 * Construct a Verse from a String - something like "Gen 1:1". in case the
42 * user does not want to have their typing 'fixed' by a meddling patronizing
43 * computer. The following initial letters can not be matched at all -
44 * 'bfquvwx'.
45 *
46 * @param original
47 * The text string to be converted
48 * @return the Verse representation of the string
49 * @exception NoSuchVerseException
50 * If the text can not be understood
51 * @deprecated use {@link #fromString(Versification, String)} instead
52 */
53 @Deprecated
54 public static Verse fromString(String original) throws NoSuchVerseException {
55 return fromString(null, original);
56 }
57
58 public static Verse fromString(Versification v11n, String original) throws NoSuchVerseException {
59 if ("".equals(original)) {
60 return null;
61 }
62 String[] parts = AccuracyType.tokenize(original);
63 AccuracyType accuracy = AccuracyType.fromText(v11n, original, parts);
64 assert accuracy != null;
65 return accuracy.createStartVerse(v11n, original, null, parts);
66 }
67
68 /**
69 * Construct a Verse from a String and a VerseRange. For example given "2:2"
70 * and a basis of Gen 1:1 - 12 the result would be Gen 2:2
71 *
72 * @param original
73 * The string describing the verse e.g "2:2"
74 * @param verseRangeBasis
75 * The basis by which to understand the desc.
76 * @return the verse representation of the string
77 * @exception NoSuchVerseException
78 * If the reference is illegal
79 * @deprecated use {@link #fromString(Versification, String, VerseRange)} instead
80 */
81 @Deprecated
82 public static Verse fromString(String original, VerseRange verseRangeBasis) throws NoSuchVerseException {
83 return fromString(null, original, verseRangeBasis);
84 }
85
86 public static Verse fromString(Versification v11n, String original, VerseRange verseRangeBasis) throws NoSuchVerseException {
87 if ("".equals(original)) {
88 return null;
89 }
90 String[] parts = AccuracyType.tokenize(original);
91 AccuracyType accuracy = AccuracyType.fromText(v11n, original, parts, null, verseRangeBasis);
92 assert accuracy != null;
93 return accuracy.createStartVerse(v11n, original, verseRangeBasis, parts);
94 }
95
96 }
97