~ubuntu-branches/ubuntu/lucid/sword/lucid

« back to all changes in this revision

Viewing changes to src/modules/filters/osiswebif.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.1.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090530115555-1tdz23ekn0pk1va1
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                         OSISWEBIF.cpp  -   OSIS to HTML filter with hrefs 
 
3
 *                              for strongs and morph tags
 
4
 *                            -------------------
 
5
 *   begin                    : 2003-10-23
 
6
 *   copyright            : 2003 by CrossWire Bible Society
 
7
 *
 
8
 * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
 
9
 *      CrossWire Bible Society
 
10
 *      P. O. Box 2528
 
11
 *      Tempe, AZ  85280-2528
 
12
 *
 
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.
 
16
 *
 
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.
 
21
 *
 
22
 */
 
23
 
 
24
#include <stdlib.h>
 
25
#include <osiswebif.h>
 
26
#include <utilxml.h>
 
27
#include <url.h>
 
28
#include <versekey.h>
 
29
#include <swmodule.h>
 
30
#include <ctype.h>
 
31
 
 
32
 
 
33
SWORD_NAMESPACE_START
 
34
 
 
35
 
 
36
OSISWEBIF::OSISWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp"), javascript(false) {
 
37
}
 
38
 
 
39
 
 
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> ";
 
44
        return u;
 
45
}
 
46
 
 
47
 
 
48
bool OSISWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
 
49
        MyUserData *u = (MyUserData *)userData;
 
50
        SWBuf scratch;
 
51
        bool sub = (u->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
 
52
        if (!sub) {
 
53
  // manually process if it wasn't a simple substitution
 
54
                XMLTag tag(token);
 
55
 
 
56
                // <w> tag
 
57
                if (!strcmp(tag.getName(), "w")) {
 
58
 
 
59
                        // start <w> tag
 
60
                        if ((!tag.isEmpty()) && (!tag.isEndTag())) {
 
61
                                u->w = token;
 
62
                        }
 
63
 
 
64
                        // end or empty <w> tag
 
65
                        else {
 
66
                                bool endTag = tag.isEndTag();
 
67
                                SWBuf lastText;
 
68
                                bool show = true;       // to handle unplaced article in kjv2003-- temporary till combined
 
69
 
 
70
                                if (endTag) {
 
71
                                        tag = u->w.c_str();
 
72
                                        lastText = u->lastTextNode.c_str();
 
73
                                }
 
74
                                else lastText = "stuff";
 
75
 
 
76
                                const char *attrib;
 
77
                                const char *val;
 
78
                                if ((attrib = tag.getAttribute("xlit"))) {
 
79
                                        val = strchr(attrib, ':');
 
80
                                        val = (val) ? (val + 1) : attrib;
 
81
//                                      buf.appendFormatted(" %s", val);
 
82
                                }
 
83
                                if ((attrib = tag.getAttribute("gloss"))) {
 
84
                                        val = strchr(attrib, ':');
 
85
                                        val = (val) ? (val + 1) : attrib;
 
86
                                        buf.appendFormatted(" %s", val);
 
87
                                }
 
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
 
91
                                        do {
 
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])))
 
98
                                                        val2++;
 
99
                                                if ((!strcmp(val2, "3588")) && (lastText.length() < 1))
 
100
                                                        show = false;
 
101
                                                else    buf.appendFormatted(" <small><em>&lt;<a href=\"%s?showStrong=%s#cv\">%s</a>&gt;</em></small> ", passageStudyURL.c_str(), URL::encode(val2).c_str(), val2);
 
102
                                        } while (++i < count);
 
103
                                }
 
104
                                if ((attrib = tag.getAttribute("morph")) && (show)) {
 
105
                                        SWBuf savelemma = tag.getAttribute("savlm");
 
106
                                        if ((strstr(savelemma.c_str(), "3588")) && (lastText.length() < 1))
 
107
                                                show = false;
 
108
                                        if (show) {
 
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
 
111
                                                do {
 
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])))
 
118
                                                                val2+=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);
 
121
                                        }
 
122
                                }
 
123
                                if ((attrib = tag.getAttribute("POS"))) {
 
124
                                        val = strchr(attrib, ':');
 
125
                                        val = (val) ? (val + 1) : attrib;
 
126
                                        buf.appendFormatted(" %s", val);
 
127
                                }
 
128
 
 
129
                                /*if (endTag)
 
130
                                        buf += "}";*/
 
131
                        }
 
132
                }
 
133
 
 
134
                // <note> tag
 
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
 
139
                                if (strongsMarkup) {
 
140
                                        tag.setEmpty(false);    // handle bug in KJV2003 module where some note open tags were <note ... />
 
141
                                }                       
 
142
                                                        
 
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
 
149
                                                SWTRY {
 
150
                                                        vkey = SWDYNAMIC_CAST(VerseKey, u->key);
 
151
                                                }
 
152
                                                SWCATCH ( ... ) {       }
 
153
                                                if (vkey) {
 
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);
 
157
                                                }
 
158
                                        }
 
159
                                        u->suspendTextPassThru = (++u->suspendLevel);
 
160
                                }
 
161
                        }
 
162
                        if (tag.isEndTag()) {
 
163
                                u->suspendTextPassThru = (--u->suspendLevel);
 
164
 
 
165
                        }
 
166
                }
 
167
 
 
168
                // <title>
 
169
                else if (!strcmp(tag.getName(), "title")) {
 
170
                        if ((!tag.isEndTag()) && (!tag.isEmpty())) {
 
171
                                buf += "<h3>";
 
172
                        }
 
173
                        else if (tag.isEndTag()) {
 
174
                                buf += "</h3>";
 
175
                        }
 
176
                }
 
177
 
 
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);
 
184
                }
 
185
 
 
186
                // ok to leave these in
 
187
                else if (!strcmp(tag.getName(), "div")) {
 
188
                        buf += tag;
 
189
                }
 
190
                else if (!strcmp(tag.getName(), "span")) {
 
191
                        buf += tag;
 
192
                }
 
193
                else if (!strcmp(tag.getName(), "br")) {
 
194
                        buf += tag;
 
195
                }
 
196
 
 
197
                // handled appropriately in base class
 
198
                // <catchWord> & <rdg> tags (italicize)
 
199
                // <hi> text highlighting
 
200
                // <q> quote
 
201
                // <milestone type="cQuote" marker="x"/>
 
202
                // <transChange>
 
203
                else {
 
204
                        return OSISHTMLHREF::handleToken(buf, token, userData);
 
205
                }
 
206
        }
 
207
        return true;
 
208
}
 
209
 
 
210
 
 
211
SWORD_NAMESPACE_END
 
212