The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
thmlwebif.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * thmlwebif.cpp - ThML to HTML filter with hrefs
4  *
5  * $Id: thmlwebif.cpp 2980 2013-09-14 21:51:47Z scribe $
6  *
7  * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <stdlib.h>
24 #include <thmlwebif.h>
25 #include <swmodule.h>
26 #include <url.h>
27 #include <utilxml.h>
28 #include <ctype.h>
29 
31 
32 
33 ThMLWEBIF::ThMLWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp") {
34 }
35 
36 
37 bool ThMLWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
38 
39  if (!substituteToken(buf, token)) { // manually process if it wasn't a simple substitution
40  MyUserData *u = (MyUserData *)userData;
41  XMLTag tag(token);
42  SWBuf url;
43  if (!strcmp(tag.getName(), "sync")) {
44  const char* value = tag.getAttribute("value");
45  url = value;
46  if ((url.length() > 1) && strchr("GH", url[0])) {
47  if (isdigit(url[1]))
48  url = url.c_str()+1;
49  }
50 
51  if(tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "morph")){
52  buf += "<small><em> (";
53  buf.appendFormatted("<a href=\"%s?showMorph=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str() );
54  }
55  else {
56  if (value) {
57  value++; //skip leading G, H or T
58  //url = value;
59  }
60 
61  buf += "<small><em> &lt;";
62  buf.appendFormatted("<a href=\"%s?showStrong=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str() );
63  }
64 
65  buf += value;
66  buf += "</a>";
67 
68  if (tag.getAttribute("type") && !strcmp(tag.getAttribute("type"), "morph")) {
69  buf += ") </em></small>";
70  }
71  else {
72  buf += "&gt; </em></small>";
73  }
74  }
75  else if (!strcmp(tag.getName(), "scripRef")) {
76  if (tag.isEndTag()) {
77  if (u->inscriptRef) { // like "<scripRef passage="John 3:16">John 3:16</scripRef>"
78  u->inscriptRef = false;
79  buf += "</a>";
80  }
81  else { // end of scripRef like "<scripRef>John 3:16</scripRef>"
82  url = u->lastTextNode;
83  buf.appendFormatted("<a href=\"%s?key=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
84  buf += u->lastTextNode.c_str();
85  buf += "</a>";
86 
87  // let's let text resume to output again
88  u->suspendTextPassThru = false;
89  }
90  }
91  else if (tag.getAttribute("passage")) { //passage given
92  u->inscriptRef = true;
93 
94  buf.appendFormatted("<a href=\"%s?key=%s#cv\">", passageStudyURL.c_str(), URL::encode(tag.getAttribute("passage")).c_str());
95  }
96  else { //no passage given
97  u->inscriptRef = false;
98  // let's stop text from going to output
99  u->suspendTextPassThru = true;
100  }
101  }
102  else {
103  return ThMLXHTML::handleToken(buf, token, userData);
104  }
105  }
106  return true;
107 }
108 
109 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: thmlxhtml.cpp:174
const char * getName() const
Definition: utilxml.h:58
Definition: utilxml.h:38
bool substituteToken(SWBuf &buf, const char *token)
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: thmlwebif.cpp:37
const char * c_str() const
Definition: swbuf.h:158
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
#define SWORD_NAMESPACE_END
Definition: defs.h:40
const SWBuf passageStudyURL
Definition: thmlwebif.h:37
static const SWBuf encode(const char *urlText)
Definition: url.cpp:231