Commit a7b9f94a authored by Stephan Kreutzer's avatar Stephan Kreutzer

osis2haggai1: Support for non-milestoned <verse/>s in the OSIS input file.

parent a96a5bf5
......@@ -120,6 +120,7 @@ class OSISProcessor
String verseID = "";
int verseNumberCurrent = 0;
int verseNumberLast = 0;
boolean inNonMilestonedVerse = false;
boolean paragraphSpan = false;
......@@ -373,67 +374,121 @@ class OSISProcessor
{
Attribute attributeStartID = event.asStartElement().getAttributeByName(new QName("sID"));
Attribute attributeEndID = event.asStartElement().getAttributeByName(new QName("eID"));
Attribute attributeOsisId = event.asStartElement().getAttributeByName(new QName("osisID"));
if (attributeStartID != null)
if (attributeStartID != null ||
attributeEndID != null)
{
Attribute attributeNumber = event.asStartElement().getAttributeByName(new QName("n"));
// Milestoned.
if (attributeNumber != null)
if (inNonMilestonedVerse == true)
{
String attributeNumberString = attributeNumber.getValue();
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Milestoned verse within another non-milestoned verse detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
if (attributeNumberString.contains("-") == true)
if (attributeStartID != null)
{
if (readingVerse == true)
{
String[] span = attributeNumberString.split("-");
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse start within another started verse detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
writer.write(" <!-- This verse spans from " + span[0] + " to " + span[1] + " -->\n");
attributeNumberString = span[0];
Attribute attributeNumber = event.asStartElement().getAttributeByName(new QName("n"));
if (attributeNumber != null)
{
String attributeNumberString = attributeNumber.getValue();
if (attributeNumberString.contains("-") == true)
{
String[] span = attributeNumberString.split("-");
writer.write(" <!-- This verse spans from " + span[0] + " to " + span[1] + " -->\n");
attributeNumberString = span[0];
}
verseNumberCurrent = Integer.parseInt(attributeNumberString);
}
else
{
verseNumberCurrent = verseNumberLast + 1;
}
if (verseNumberLast < verseNumberCurrent)
{
verseNumberLast = verseNumberCurrent;
}
else
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": verse " + verseNumberCurrent + " detected after verse " + verseNumberLast + " - output continues with " + (verseNumberLast + 1) + ".\n");
verseNumberCurrent = Integer.parseInt(attributeNumberString);
verseNumberCurrent = verseNumberLast + 1;
verseNumberLast = verseNumberCurrent;
}
verseID = attributeStartID.getValue();
writer.write(" <VERSE vnumber=\"" + verseNumberCurrent + "\">");
readingVerse = true;
}
else
else if (attributeEndID != null)
{
verseNumberCurrent = verseNumberLast + 1;
if (readingVerse != true)
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse end with no corresponding verse start detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
verseID = "";
verseNumberCurrent = 0;
writer.write("</VERSE>\n");
readingVerse = false;
}
}
else if (attributeOsisId != null)
{
if (inNonMilestonedVerse == true)
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Non-milestoned verse within another non-milestoned verse detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
if (readingVerse == true)
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Non-milestoned verse start while already in another verse detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
verseNumberCurrent = verseNumberLast + 1;
if (verseNumberLast < verseNumberCurrent)
{
verseNumberLast = verseNumberCurrent;
}
else
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": verse " + verseNumberCurrent + " detected after verse " + verseNumberLast + " - output continues with " + (verseNumberLast + 1) + ".\n");
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse " + verseNumberCurrent + " detected after verse " + verseNumberLast + " - output continues with " + (verseNumberLast + 1) + ".\n");
verseNumberCurrent = verseNumberLast + 1;
verseNumberLast = verseNumberCurrent;
}
verseID = attributeStartID.getValue();
verseID = attributeOsisId.getValue();
writer.write(" <VERSE vnumber=\"" + verseNumberCurrent + "\">");
readingVerse = true;
}
else if (attributeEndID != null)
{
if (readingVerse != true)
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse end with no corresponding verse start detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
verseID = "";
verseNumberCurrent = 0;
writer.write("</VERSE>\n");
readingVerse = false;
inNonMilestonedVerse = true;
}
else
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse tag without supported attribute detected.\n");
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse tag without supported attribute detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
}
......@@ -746,6 +801,25 @@ class OSISProcessor
writer.write("<!-- Paragraph ending within a verse. -->");
}
}
else if (fullElementName.equalsIgnoreCase("verse") == true)
{
if (inNonMilestonedVerse == true)
{
if (readingVerse != true)
{
System.out.print("osis2haggai1: Book " + bookNumber + ", chapter " + chapterNumberCurrent + ": Verse end with no corresponding verse start detected around verse number " + verseNumberCurrent + ".\n");
System.exit(-1);
}
verseID = "";
verseNumberCurrent = 0;
writer.write("</VERSE>\n");
readingVerse = false;
inNonMilestonedVerse = false;
}
}
else if (fullElementName.equalsIgnoreCase("note") == true &&
readingVerse == true &&
readingNote == true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment