1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package org.crosswire.jsword.book.filter.thml; |
21 | |
|
22 | |
import org.crosswire.jsword.book.Book; |
23 | |
import org.crosswire.jsword.book.DataPolice; |
24 | |
import org.crosswire.jsword.book.OSISUtil; |
25 | |
import org.crosswire.jsword.passage.Key; |
26 | |
import org.crosswire.jsword.passage.KeyUtil; |
27 | |
import org.crosswire.jsword.passage.NoSuchKeyException; |
28 | |
import org.crosswire.jsword.passage.Passage; |
29 | |
import org.crosswire.jsword.passage.PassageKeyFactory; |
30 | |
import org.jdom2.Element; |
31 | |
import org.xml.sax.Attributes; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class ScripRefTag extends AbstractTag { |
40 | |
|
41 | |
|
42 | |
|
43 | |
public String getTagName() { |
44 | 0 | return "scripRef"; |
45 | |
} |
46 | |
|
47 | |
@Override |
48 | |
public Element processTag(Book book, Key key, Element ele, Attributes attrs) { |
49 | 0 | Element reference = null; |
50 | |
|
51 | 0 | String refstr = attrs.getValue("passage"); |
52 | 0 | if (refstr != null) { |
53 | 0 | Passage ref = null; |
54 | |
try { |
55 | 0 | ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key); |
56 | 0 | } catch (NoSuchKeyException ex) { |
57 | 0 | DataPolice.report(book, key, "Unparsable passage: (" + refstr + ") due to " + ex.getMessage()); |
58 | 0 | } |
59 | |
|
60 | |
|
61 | 0 | String osisname = ref != null ? ref.getOsisRef() : refstr; |
62 | 0 | reference = OSISUtil.factory().createReference(); |
63 | 0 | reference.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname); |
64 | 0 | } else { |
65 | |
|
66 | 0 | reference = OSISUtil.factory().createReference(); |
67 | |
} |
68 | |
|
69 | 0 | if (ele != null) { |
70 | 0 | ele.addContent(reference); |
71 | |
} |
72 | |
|
73 | 0 | return reference; |
74 | |
} |
75 | |
|
76 | |
@Override |
77 | |
public void processContent(Book book, Key key, Element ele) { |
78 | 0 | String refstr = ele.getValue(); |
79 | |
try { |
80 | 0 | if (ele.getAttribute(OSISUtil.OSIS_ATTR_REF) == null) { |
81 | 0 | Passage ref = PassageKeyFactory.instance().getKey(KeyUtil.getVersification(key), refstr, key); |
82 | 0 | String osisname = ref.getOsisRef(); |
83 | 0 | ele.setAttribute(OSISUtil.OSIS_ATTR_REF, osisname); |
84 | |
} |
85 | 0 | } catch (NoSuchKeyException ex) { |
86 | 0 | DataPolice.report(book, key, "scripRef has no passage attribute, unable to guess: (" + refstr + ") due to " + ex.getMessage()); |
87 | 0 | } |
88 | 0 | } |
89 | |
} |