Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DivTag |
|
| 2.75;2.75 |
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 or later | |
5 | * as published by the Free Software Foundation. This program is distributed | |
6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
7 | * the 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 | * © CrossWire Bible Society, 2005 - 2016 | |
18 | * | |
19 | */ | |
20 | package org.crosswire.jsword.book.filter.thml; | |
21 | ||
22 | import org.crosswire.jsword.book.Book; | |
23 | import org.crosswire.jsword.book.OSISUtil; | |
24 | import org.crosswire.jsword.passage.Key; | |
25 | import org.jdom2.Element; | |
26 | import org.xml.sax.Attributes; | |
27 | ||
28 | /** | |
29 | * THML Tag to process the div element. | |
30 | * | |
31 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
32 | * @author Joe Walker | |
33 | */ | |
34 | public class DivTag extends AbstractTag { | |
35 | /** | |
36 | * Create an div tag | |
37 | */ | |
38 | public DivTag() { | |
39 | 0 | super(); |
40 | 0 | this.level = 0; |
41 | 0 | } |
42 | ||
43 | /** | |
44 | * Create an div tag of the given level | |
45 | * | |
46 | * @param level | |
47 | */ | |
48 | public DivTag(int level) { | |
49 | 0 | super(); |
50 | 0 | this.level = level; |
51 | 0 | } |
52 | ||
53 | /* (non-Javadoc) | |
54 | * @see org.crosswire.jsword.book.filter.thml.Tag#getTagName() | |
55 | */ | |
56 | public String getTagName() { | |
57 | 0 | if (level == 0) { |
58 | 0 | return "div"; |
59 | } | |
60 | 0 | return "div" + level; |
61 | } | |
62 | ||
63 | @Override | |
64 | public Element processTag(Book book, Key key, Element ele, Attributes attrs) { | |
65 | // See if there are variant readings e.g. WHNU Mat 1.9 | |
66 | 0 | String typeAttr = attrs.getValue("type"); |
67 | 0 | if ("variant".equals(typeAttr)) { |
68 | 0 | Element seg = OSISUtil.factory().createSeg(); |
69 | 0 | seg.setAttribute(OSISUtil.OSIS_ATTR_TYPE, OSISUtil.VARIANT_TYPE); |
70 | 0 | String classAttr = attrs.getValue("class"); |
71 | 0 | if (classAttr != null) { |
72 | 0 | seg.setAttribute(OSISUtil.OSIS_ATTR_SUBTYPE, OSISUtil.VARIANT_CLASS + '-' + classAttr); |
73 | } | |
74 | ||
75 | 0 | if (ele != null) { |
76 | 0 | ele.addContent(seg); |
77 | } | |
78 | ||
79 | 0 | return seg; |
80 | } | |
81 | ||
82 | 0 | Element div = OSISUtil.factory().createDiv(); |
83 | ||
84 | 0 | if (ele != null) { |
85 | 0 | ele.addContent(div); |
86 | } | |
87 | ||
88 | 0 | return div; |
89 | } | |
90 | ||
91 | /** | |
92 | * The level of the division | |
93 | */ | |
94 | private int level; | |
95 | } |