1
/***************************************************************************
2
* OSISWEBIF.cpp - OSIS to HTML filter with hrefs
3
* for strongs and morph tags
6
* copyright : 2003 by CrossWire Bible Society
8
* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
9
* CrossWire Bible Society
11
* Tempe, AZ 85280-2528
13
* This program is free software; you can redistribute it and/or modify it
14
* under the terms of the GNU General Public License as published by the
15
* Free Software Foundation version 2.
17
* This program is distributed in the hope that it will be useful, but
18
* WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
* General Public License for more details.
25
#include <osiswebif.h>
36
OSISWEBIF::OSISWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp"), javascript(false) {
40
BasicFilterUserData *OSISWEBIF::createUserData(const SWModule *module, const SWKey *key) {
41
MyUserData *u = new MyUserData(module, key);
42
u->wordsOfChristStart = "<span class=\"wordsOfJesus\"> ";
43
u->wordsOfChristEnd = "</span> ";
48
bool OSISWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
49
MyUserData *u = (MyUserData *)userData;
51
bool sub = (u->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
53
// manually process if it wasn't a simple substitution
57
if (!strcmp(tag.getName(), "w")) {
60
if ((!tag.isEmpty()) && (!tag.isEndTag())) {
64
// end or empty <w> tag
66
bool endTag = tag.isEndTag();
68
bool show = true; // to handle unplaced article in kjv2003-- temporary till combined
72
lastText = u->lastTextNode.c_str();
74
else lastText = "stuff";
78
if ((attrib = tag.getAttribute("xlit"))) {
79
val = strchr(attrib, ':');
80
val = (val) ? (val + 1) : attrib;
81
// buf.appendFormatted(" %s", val);
83
if ((attrib = tag.getAttribute("gloss"))) {
84
val = strchr(attrib, ':');
85
val = (val) ? (val + 1) : attrib;
86
buf.appendFormatted(" %s", val);
88
if ((attrib = tag.getAttribute("lemma"))) {
89
int count = tag.getAttributePartCount("lemma", ' ');
90
int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
92
attrib = tag.getAttribute("lemma", i, ' ');
93
if (i < 0) i = 0; // to handle our -1 condition
94
val = strchr(attrib, ':');
95
val = (val) ? (val + 1) : attrib;
96
const char *val2 = val;
97
if ((strchr("GH", *val)) && (isdigit(val[1])))
99
if ((!strcmp(val2, "3588")) && (lastText.length() < 1))
101
else buf.appendFormatted(" <small><em><<a href=\"%s?showStrong=%s#cv\">%s</a>></em></small> ", passageStudyURL.c_str(), URL::encode(val2).c_str(), val2);
102
} while (++i < count);
104
if ((attrib = tag.getAttribute("morph")) && (show)) {
105
SWBuf savelemma = tag.getAttribute("savlm");
106
if ((strstr(savelemma.c_str(), "3588")) && (lastText.length() < 1))
109
int count = tag.getAttributePartCount("morph", ' ');
110
int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
112
attrib = tag.getAttribute("morph", i, ' ');
113
if (i < 0) i = 0; // to handle our -1 condition
114
val = strchr(attrib, ':');
115
val = (val) ? (val + 1) : attrib;
116
const char *val2 = val;
117
if ((*val == 'T') && (strchr("GH", val[1])) && (isdigit(val[2])))
119
buf.appendFormatted(" <small><em>(<a href=\"%s?showMorph=%s#cv\">%s</a>)</em></small> ", passageStudyURL.c_str(), URL::encode(val2).c_str(), val2);
120
} while (++i < count);
123
if ((attrib = tag.getAttribute("POS"))) {
124
val = strchr(attrib, ':');
125
val = (val) ? (val + 1) : attrib;
126
buf.appendFormatted(" %s", val);
135
else if (!strcmp(tag.getName(), "note")) {
136
if (!tag.isEndTag()) {
137
SWBuf type = tag.getAttribute("type");
138
bool strongsMarkup = (type == "x-strongsMarkup" || type == "strongsMarkup"); // the latter is deprecated
140
tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... />
143
if (!tag.isEmpty()) {
144
if (!strongsMarkup) { // leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off
145
SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
146
SWBuf modName = (u->module) ? u->module->Name() : "";
147
VerseKey *vkey = NULL;
148
// see if we have a VerseKey * or descendant
150
vkey = SWDYNAMIC_CAST(VerseKey, u->key);
154
char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
155
// buf.appendFormatted("<a href=\"noteID=%s.%c.%s\"><small><sup>*%c</sup></small></a> ", vkey->getText(), ch, footnoteNumber.c_str(), ch);
156
buf.appendFormatted("<span class=\"fn\" onclick=\"f(\'%s\',\'%s\',\'%s\');\" >%c</span>", modName.c_str(), u->key->getText(), footnoteNumber.c_str(), ch);
159
u->suspendTextPassThru = (++u->suspendLevel);
162
if (tag.isEndTag()) {
163
u->suspendTextPassThru = (--u->suspendLevel);
169
else if (!strcmp(tag.getName(), "title")) {
170
if ((!tag.isEndTag()) && (!tag.isEmpty())) {
173
else if (tag.isEndTag()) {
178
// Milestoned paragraphs, created by osis2mod
179
// <div type="paragraph" sID.../>
180
// <div type="paragraph" eID.../>
181
else if (tag.isEmpty() && !strcmp(tag.getName(), "div") && tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "paragraph")) {
182
// This is properly handled by base class.
183
return OSISHTMLHREF::handleToken(buf, token, userData);
186
// ok to leave these in
187
else if (!strcmp(tag.getName(), "div")) {
190
else if (!strcmp(tag.getName(), "span")) {
193
else if (!strcmp(tag.getName(), "br")) {
197
// handled appropriately in base class
198
// <catchWord> & <rdg> tags (italicize)
199
// <hi> text highlighting
201
// <milestone type="cQuote" marker="x"/>
204
return OSISHTMLHREF::handleToken(buf, token, userData);