/*************************************************************************** * ThMLWEBIF.cpp - ThML to HTML filter with hrefs * ------------------- * begin : 2001-09-03 * copyright : 2001 by CrossWire Bible Society * * * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 * * 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 version 2. * * 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. * */ #include #include #include #include #include #include SWORD_NAMESPACE_START ThMLWEBIF::ThMLWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp") { //all's done in ThMLHTMLHREF } bool ThMLWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) { if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution MyUserData *u = (MyUserData *)userData; XMLTag tag(token); SWBuf url; if (!strcmp(tag.getName(), "sync")) { const char* value = tag.getAttribute("value"); url = value; if ((url.length() > 1) && strchr("GH", url[0])) { if (isdigit(url[1])) url = url.c_str()+1; } if(tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "morph")){ buf += " ("; buf.appendFormatted("", passageStudyURL.c_str(), URL::encode(url).c_str() ); } else { if (value) { value++; //skip leading G, H or T //url = value; } buf += " <"; buf.appendFormatted("", passageStudyURL.c_str(), URL::encode(url).c_str() ); } buf += value; buf += ""; if (tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "morph")) { buf += ") "; } else { buf += "> "; } } else if (!strcmp(tag.getName(), "scripRef")) { if (tag.isEndTag()) { if (u->inscriptRef) { // like "John 3:16" u->inscriptRef = false; buf += ""; } else { // end of scripRef like "John 3:16" url = u->lastTextNode; buf.appendFormatted("", passageStudyURL.c_str(), URL::encode(url).c_str()); buf += u->lastTextNode.c_str(); buf += ""; // let's let text resume to output again u->suspendTextPassThru = false; } } else if (tag.getAttribute("passage")) { //passage given u->inscriptRef = true; buf.appendFormatted("", passageStudyURL.c_str(), URL::encode(tag.getAttribute("passage")).c_str()); } else { //no passage given u->inscriptRef = false; // let's stop text from going to output u->suspendTextPassThru = true; } } else { return ThMLHTMLHREF::handleToken(buf,token,userData); } } return true; } SWORD_NAMESPACE_END