Skip to content

Commit

Permalink
Additional fixes for #654
Browse files Browse the repository at this point in the history
  • Loading branch information
berry120 committed May 10, 2024
1 parent 2e6e6f7 commit ef80d35
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
37 changes: 20 additions & 17 deletions Quelea/src/main/java/org/quelea/data/bible/BibleBook.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
/*
* This file is part of Quelea, free projection software for churches.
*
*
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -149,6 +149,17 @@ public Bible getBible() {
*/
public static BibleBook parseXML(Node node, int defaultBookNum, String defaultBookName) {
BibleBook ret = new BibleBook();

NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i).getNodeName().equalsIgnoreCase("chapter")
|| list.item(i).getNodeName().equalsIgnoreCase("c")) {
BibleChapter chapter = BibleChapter.parseXML(list.item(i), i);
chapter.setBook(ret);
ret.addChapter(chapter);
}
}

if (node.getAttributes().getNamedItem("bnumber") != null) {
ret.bookNumber = Integer.parseInt(node.getAttributes().getNamedItem("bnumber").getNodeValue().trim());
} else if (node.getAttributes().getNamedItem("number") != null) {
Expand All @@ -167,24 +178,16 @@ public static BibleBook parseXML(Node node, int defaultBookNum, String defaultBo
ret.bookName = node.getAttributes().getNamedItem("name").getNodeValue();
} else if (node.getAttributes().getNamedItem("osisID") != null) {
ret.bookName = node.getAttributes().getNamedItem("osisID").getNodeValue();
} else {
ret.bookName = defaultBookName;
} else if (ret.getChapters().length > 0 && ret.getChapter(0).getCaptions().length > 0) {
ret.bookName = ret.getChapter(0).getCaptions()[0];
}

if (node.getAttributes().getNamedItem("bsname") != null) {
ret.bsname = node.getAttributes().getNamedItem("bsname").getNodeValue();
} else {
ret.bsname = ret.bookName;
}
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i).getNodeName().equalsIgnoreCase("chapter")
|| list.item(i).getNodeName().equalsIgnoreCase("c")) {
BibleChapter chapter = BibleChapter.parseXML(list.item(i), i);
chapter.setBook(ret);
ret.addChapter(chapter);
}
}

LOGGER.log(Level.INFO, "Parsed " + ret.getChapters().length + " chapters in " + ret.bookName);
return ret;
}
Expand Down
39 changes: 34 additions & 5 deletions Quelea/src/main/java/org/quelea/data/bible/BibleChapter.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/*
/*
* This file is part of Quelea, free projection software for churches.
*
*
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.quelea.data.bible;

import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.quelea.services.utils.Utils;
Expand All @@ -36,6 +38,7 @@ public final class BibleChapter implements BibleInterface, Serializable {
private static int statId = 0;
private final int num;
private final Map<Integer, BibleVerse> verses;
private final List<String> captions;
private transient SoftReference<String> softRefText;
private final int id = statId++;
private BibleBook book;
Expand All @@ -48,6 +51,7 @@ public final class BibleChapter implements BibleInterface, Serializable {
private BibleChapter(int num) {
this.num = num;
verses = new HashMap<>();
captions = new ArrayList<>();
}

@Override
Expand Down Expand Up @@ -141,6 +145,12 @@ public static BibleChapter parseXML(Node node, int defaultNum) {
ret.addVerse(verse);
}
}
else if (list.item(i).getNodeName().equalsIgnoreCase("caption")) {
String caption = list.item(i).getTextContent();
if (caption != null) {
ret.addCaption(caption);
}
}
}
return ret;
}
Expand Down Expand Up @@ -185,6 +195,16 @@ private void addVerse(BibleVerse verse) {
verses.put(verse.getNum(), verse);
}


/**
* Add a caption to this chapter.
* <p/>
* @param caption the caption to add.
*/
private void addCaption(String caption) {
captions.add(caption);
}

/**
* Get all the verses in this chapter .
* <p/>
Expand All @@ -194,6 +214,15 @@ public BibleVerse[] getVerses() {
return verses.values().toArray(new BibleVerse[verses.size()]);
}

/**
* Get all the captions in this chapter .
* <p/>
* @return all the captions in the chapter.
*/
public String[] getCaptions() {
return captions.toArray(new String[captions.size()]);
}

/**
* Get a specific verse from this chapter.
* <p/>
Expand Down

0 comments on commit ef80d35

Please sign in to comment.