[sword-svn] r1738 - in trunk: bindings/corba bindings/corba/java bindings/corba/orbitcpp include src/mgr src/modules/filters

scribe at crosswire.org scribe at crosswire.org
Mon Mar 7 20:23:21 MST 2005


Author: scribe
Date: 2005-03-07 20:23:20 -0700 (Mon, 07 Mar 2005)
New Revision: 1738

Added:
   trunk/bindings/corba/java/classes/
   trunk/bindings/corba/orbitcpp/webmgr.hpp
   trunk/include/osiswordjs.h
   trunk/include/thmlwordjs.h
   trunk/src/modules/filters/osiswordjs.cpp
   trunk/src/modules/filters/thmlwordjs.cpp
Modified:
   trunk/bindings/corba/orbitcpp/server.cpp
   trunk/bindings/corba/orbitcpp/swordorb-impl.cpp
   trunk/bindings/corba/orbitcpp/swordorb-impl.hpp
   trunk/bindings/corba/orbitcpp/testclient.cpp
   trunk/bindings/corba/swordorb.idl
   trunk/include/Makefile.am
   trunk/include/osiswebif.h
   trunk/src/mgr/stringmgr.cpp
   trunk/src/mgr/swmgr.cpp
   trunk/src/modules/filters/Makefile.am
   trunk/src/modules/filters/osiswebif.cpp
   trunk/src/modules/filters/thmlhtmlhref.cpp
   trunk/src/modules/filters/thmlstrongs.cpp
   trunk/src/modules/filters/thmlvariants.cpp
Log:
Added support for javascript
Fixed ThML Variant filters


Modified: trunk/bindings/corba/orbitcpp/server.cpp
===================================================================
--- trunk/bindings/corba/orbitcpp/server.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/bindings/corba/orbitcpp/server.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -3,10 +3,12 @@
 #include "swordorb-impl.hpp"
 #include <iostream>
 #include <swmgr.h>
-#include <markupfiltmgr.h>
+#include "webmgr.hpp"
 
-sword::SWMgr swordmgr(new sword::MarkupFilterMgr(sword::FMT_WEBIF));
+WebMgr swordmgr;
 
+
+
 int main (int argc, char* argv[]) {
   try {
  	  // Initialize the CORBA orb

Modified: trunk/bindings/corba/orbitcpp/swordorb-impl.cpp
===================================================================
--- trunk/bindings/corba/orbitcpp/swordorb-impl.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/bindings/corba/orbitcpp/swordorb-impl.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -105,6 +105,9 @@
 	return true;
 }
 
+void SWMgr_impl::setJavascript(CORBA::Boolean val) throw(CORBA::SystemException) {
+	delegate->setJavascript(val);
+}
 
 char *SWModule_impl::getCategory() throw(CORBA::SystemException) {
 	SWBuf type = delegate->Type();

Modified: trunk/bindings/corba/orbitcpp/swordorb-impl.hpp
===================================================================
--- trunk/bindings/corba/orbitcpp/swordorb-impl.hpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/bindings/corba/orbitcpp/swordorb-impl.hpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -2,6 +2,7 @@
 #define _ORBIT_CPP_IDL_sword_IMPL_HH
 
 #include "swordorb-cpp-skels.h"
+#include "webmgr.hpp"
 #include <swmodule.h>
 #include <swmgr.h>
 #include <rawtext.h>
@@ -44,10 +45,10 @@
 typedef std::map<std::string, SWModule_impl *> SWModuleMap;
 
 class SWMgr_impl : public POA_swordorb::SWMgr {
-	sword::SWMgr *delegate;
+	WebMgr *delegate;
 	SWModuleMap moduleImpls;
 public:
-	SWMgr_impl(sword::SWMgr *delegate)  { this->delegate = delegate; }
+	SWMgr_impl(WebMgr *delegate)  { this->delegate = delegate; }
 
 	ModInfoList *getModInfoList() throw(CORBA::SystemException);
 	SWModule_ptr getModuleByName(const char *name) throw(CORBA::SystemException);
@@ -61,6 +62,7 @@
 	void     setCipherKey(const char *modName, const char *key) throw(CORBA::SystemException) { delegate->setCipherKey(modName, key); }
 	void     terminate() throw(CORBA::SystemException);
 	CORBA::Boolean     testConnection() throw(CORBA::SystemException);
+	void setJavascript(CORBA::Boolean) throw(CORBA::SystemException);
 
 };
 }; // namespace hellomodule

Modified: trunk/bindings/corba/orbitcpp/testclient.cpp
===================================================================
--- trunk/bindings/corba/orbitcpp/testclient.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/bindings/corba/orbitcpp/testclient.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -3,6 +3,7 @@
 #include "swordorb-cpp-stubs.h"
 #include "swordorb-cpp-common.h"
 #include <iostream>
+#include <swbuf.h>
 	
 int main (int argc, char *argv[])
 {
@@ -30,8 +31,8 @@
 		std::cout << "Connected: "  << mgr->testConnection() << "\n";
 		std::cout << "PrefixPath: " << mgr->getPrefixPath() << "\n";
 		std::cout << "ConfigPath: " << mgr->getConfigPath() << "\n";
-		modInfoList = mgr->getModInfoList();
-		std::cout << "sequence length: " << modInfoList->length() << "\n";
+//		modInfoList = mgr->getModInfoList();
+//		std::cout << "sequence length: " << modInfoList->length() << "\n";
 /*
 		for (int i = 0; i < modInfoList->length(); i++) {
 			std::cout << (*modInfoList)[i].name << ": " << (*modInfoList)[i].category << ": " << (*modInfoList)[i].language << "\n";
@@ -43,13 +44,19 @@
 			std::cout << "\n";
 		}
 */
+		mgr->setJavascript(true);
+		module = mgr->getModuleByName("WHNU");
+		module->setKeyText("jas.1.9");
+		std::cout << "KeyText: " << module->getKeyText() << "\n";
+		std::cout << "Text: " << module->getRenderText() << "\n";
+/*
 		swordorb::SearchHitList *searchResults;
-		module = mgr->getModuleByName("KJV");
 		bool lucene = module->hasSearchFramework();
 		searchResults = module->search("God love world", (lucene)?swordorb::LUCENE:swordorb::MULTIWORD, 0, "");
 		for (int i = 0; i < searchResults->length(); i++) {
 			std::cout << (*searchResults)[i].key << "\n";
 		}
+*/
 
 
 		

Added: trunk/bindings/corba/orbitcpp/webmgr.hpp
===================================================================
--- trunk/bindings/corba/orbitcpp/webmgr.hpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/bindings/corba/orbitcpp/webmgr.hpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -0,0 +1,78 @@
+#ifndef WEBMGR_HPP
+#define WEBMGR_HPP
+
+#include <swmgr.h>
+#include <markupfiltmgr.h>
+#include <osiswordjs.h>
+#include <thmlwordjs.h>
+
+using namespace sword;
+
+class WebMgr : public SWMgr {
+	OSISWordJS *osisWordJS;
+	ThMLWordJS *thmlWordJS;
+	SWModule *defaultGreekLex;
+	SWModule *defaultHebLex;
+	SWModule *defaultGreekParse;
+	SWModule *defaultHebParse;
+
+public:
+	WebMgr() : SWMgr(0, 0, false, new MarkupFilterMgr(FMT_WEBIF)) {
+		defaultGreekLex   = 0;
+		defaultHebLex     = 0;
+		defaultGreekParse = 0;
+		defaultHebParse   = 0;
+
+		osisWordJS = new OSISWordJS();
+		thmlWordJS = new ThMLWordJS();
+		Load();
+		osisWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse);
+		thmlWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse);
+		osisWordJS->setMgr(this);
+		thmlWordJS->setMgr(this);
+		setGlobalOption("Textual Variants", "Primary Reading");
+	}
+
+	~WebMgr() {
+		delete osisWordJS;
+		delete thmlWordJS;
+	}
+
+
+	void AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) {
+		if (module->getConfig().has("Feature", "GreekDef")) {
+			defaultGreekLex = module;
+		}
+		if (module->getConfig().has("Feature", "HebrewDef")) {
+			defaultHebLex = module;
+		}
+		if (module->getConfig().has("Feature", "GreekParse")) {
+			defaultGreekParse = module;
+		}
+		if (module->getConfig().has("Feature", "HebrewParse")) {
+			defaultHebParse = module;
+		}
+		if (module->getConfig().has("GlobalOptionFilter", "ThMLVariants")) {
+			FilterMap::iterator it = optionFilters.find("ThMLVariants");
+			if (it != optionFilters.end()) {
+				module->AddOptionFilter((*it).second);	// add filter to module and option as a valid option
+			}
+		}
+
+		if (module->Markup() == FMT_OSIS) {
+			module->AddOptionFilter(osisWordJS);
+		}
+		if (module->Markup() == FMT_THML) {
+			module->AddOptionFilter(thmlWordJS);
+		}
+		SWMgr::AddGlobalOptions(module, section, start, end);
+	}
+
+
+	void setJavascript(bool val) {
+		osisWordJS->setOptionValue((val)?"On":"Off");
+		thmlWordJS->setOptionValue((val)?"On":"Off");
+	}
+};
+
+#endif

Modified: trunk/bindings/corba/swordorb.idl
===================================================================
--- trunk/bindings/corba/swordorb.idl	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/bindings/corba/swordorb.idl	2005-03-08 03:23:20 UTC (rev 1738)
@@ -76,6 +76,7 @@
 	void     setCipherKey(in string modName, in string key);
 	void     terminate();
 	boolean testConnection();
+	void setJavascript(in boolean val);
 
 };
 

Modified: trunk/include/Makefile.am
===================================================================
--- trunk/include/Makefile.am	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/include/Makefile.am	2005-03-08 03:23:20 UTC (rev 1738)
@@ -54,6 +54,7 @@
 pkginclude_HEADERS += $(swincludedir)/osislemma.h   
 pkginclude_HEADERS += $(swincludedir)/osisredletterwords.h   
 pkginclude_HEADERS += $(swincludedir)/osisscripref.h   
+pkginclude_HEADERS += $(swincludedir)/osiswordjs.h   
 
 pkginclude_HEADERS += $(swincludedir)/plainfootnotes.h
 pkginclude_HEADERS += $(swincludedir)/plainfootnotes.h
@@ -119,6 +120,7 @@
 pkginclude_HEADERS += $(swincludedir)/thmlscripref.h
 pkginclude_HEADERS += $(swincludedir)/thmlstrongs.h
 pkginclude_HEADERS += $(swincludedir)/thmlvariants.h
+pkginclude_HEADERS += $(swincludedir)/thmlwordjs.h
 
 pkginclude_HEADERS += $(swincludedir)/treekey.h
 pkginclude_HEADERS += $(swincludedir)/treekeyidx.h

Modified: trunk/include/osiswebif.h
===================================================================
--- trunk/include/osiswebif.h	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/include/osiswebif.h	2005-03-08 03:23:20 UTC (rev 1738)
@@ -30,11 +30,13 @@
 class SWDLLEXPORT OSISWEBIF : public OSISHTMLHREF {
 	const SWBuf baseURL;
 	const SWBuf passageStudyURL;
+	bool javascript;
 
 protected:
 	virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData);
 public:
 	OSISWEBIF();
+	void setJavascript(bool mode) { javascript = mode; }
 };
 
 SWORD_NAMESPACE_END

Added: trunk/include/osiswordjs.h
===================================================================
--- trunk/include/osiswordjs.h	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/include/osiswordjs.h	2005-03-08 03:23:20 UTC (rev 1738)
@@ -0,0 +1,52 @@
+/***************************************************************************
+ *
+ * $Id: osisstrongs.h 1688 2005-01-01 04:42:26Z scribe $
+ *
+ * Copyright 1998 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.
+ *
+ */
+
+#ifndef OSISWORDSJS_H
+#define OSISWORDSJS_H
+
+#include <swoptfilter.h>
+
+SWORD_NAMESPACE_START
+
+class SWMgr;
+  /** This Filter shows/hides strong's numbers in a OSIS text
+  */
+class SWDLLEXPORT OSISWordJS : public SWOptionFilter {
+     SWModule *defaultGreekLex;
+     SWModule *defaultHebLex;
+     SWModule *defaultGreekParse;
+     SWModule *defaultHebParse;
+     SWMgr *mgr;
+
+public:
+	OSISWordJS();
+	virtual ~OSISWordJS();
+	virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+	void setDefaultModules(SWModule *defaultGreekLex = 0, SWModule *defaultHebLex = 0, SWModule *defaultGreekParse = 0, SWModule *defaultHebParse = 0) {
+		this->defaultGreekLex   = defaultGreekLex;
+		this->defaultHebLex     = defaultHebLex;
+		this->defaultGreekParse = defaultGreekParse;
+		this->defaultHebParse   = defaultHebParse;
+	}
+	void setMgr(SWMgr *mgr) { this->mgr = mgr; }
+};
+
+SWORD_NAMESPACE_END
+#endif

Added: trunk/include/thmlwordjs.h
===================================================================
--- trunk/include/thmlwordjs.h	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/include/thmlwordjs.h	2005-03-08 03:23:20 UTC (rev 1738)
@@ -0,0 +1,52 @@
+/***************************************************************************
+ *
+ * $Id: thmlstrongs.h 1688 2005-01-01 04:42:26Z scribe $
+ *
+ * Copyright 1998 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.
+ *
+ */
+
+#ifndef THMLWORDSJS_H
+#define THMLWORDSJS_H
+
+#include <swoptfilter.h>
+
+SWORD_NAMESPACE_START
+
+class SWMgr;
+  /** This Filter shows/hides strong's numbers in a ThML text
+  */
+class SWDLLEXPORT ThMLWordJS : public SWOptionFilter {
+     SWModule *defaultGreekLex;
+     SWModule *defaultHebLex;
+     SWModule *defaultGreekParse;
+     SWModule *defaultHebParse;
+     SWMgr *mgr;
+
+public:
+	ThMLWordJS();
+	virtual ~ThMLWordJS();
+	virtual char processText(SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
+	void setDefaultModules(SWModule *defaultGreekLex = 0, SWModule *defaultHebLex = 0, SWModule *defaultGreekParse = 0, SWModule *defaultHebParse = 0) {
+		this->defaultGreekLex   = defaultGreekLex;
+		this->defaultHebLex     = defaultHebLex;
+		this->defaultGreekParse = defaultGreekParse;
+		this->defaultHebParse   = defaultHebParse;
+	}
+	void setMgr(SWMgr *mgr) { this->mgr = mgr; }
+};
+
+SWORD_NAMESPACE_END
+#endif

Modified: trunk/src/mgr/stringmgr.cpp
===================================================================
--- trunk/src/mgr/stringmgr.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/mgr/stringmgr.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -173,7 +173,7 @@
 			&err
 		);
 		if (err != U_ZERO_ERROR) {
-			SWLog::getSystemLog()->logError("from: %s", u_errorName(err));
+//			SWLog::getSystemLog()->logError("from: %s", u_errorName(err));
 			delete [] lowerStr;
 			delete [] upperStr;
 			return ret;
@@ -188,7 +188,7 @@
 			&err
 		);
 		if (err != U_ZERO_ERROR) {
-			SWLog::getSystemLog()->logError("upperCase: %s", u_errorName(err));
+//			SWLog::getSystemLog()->logError("upperCase: %s", u_errorName(err));
 			delete [] lowerStr;
 			delete [] upperStr;
 			return ret;

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/mgr/swmgr.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -964,29 +964,24 @@
 				AddRenderFilters(newmod, section);
 				AddEncodingFilters(newmod, section);
 				
-				printf("Adding Module: %s\n", newmod->Name());
 				SWModule *oldmod = Modules[newmod->Name()];
 
 				if (oldmod) {
-					printf("Found an existing book with the same name\n");
 					if (!multiMod)
 						delete oldmod;
 					else {
-						printf("Keeping additional copy\n");
 						SWBuf name;
 						int i = 1; 
 						SWModule *mod;
 						do {
 							name = newmod->Name();
 							name.appendFormatted("_%d", i);
-							printf("Trying name: %s\n", name.c_str());
 							mod = Modules[name];
 							i++;
 						} while (mod);
 						newmod->Name(name);
 					}
 				}
-				printf("Inserting module: %s\n", newmod->Name());
 				Modules[newmod->Name()] = newmod;
 			}
 		}

Modified: trunk/src/modules/filters/Makefile.am
===================================================================
--- trunk/src/modules/filters/Makefile.am	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/Makefile.am	2005-03-08 03:23:20 UTC (rev 1738)
@@ -26,6 +26,7 @@
 THMLFIL += $(filtersdir)/thmlhtml.cpp
 THMLFIL += $(filtersdir)/thmlhtmlhref.cpp
 THMLFIL += $(filtersdir)/thmlwebif.cpp
+THMLFIL += $(filtersdir)/thmlwordjs.cpp
 
 CONVFIL = $(filtersdir)/gbfthml.cpp
 CONVFIL += $(filtersdir)/gbfosis.cpp
@@ -44,6 +45,7 @@
 OSISFIL += $(filtersdir)/osislemma.cpp
 OSISFIL += $(filtersdir)/osisredletterwords.cpp
 OSISFIL += $(filtersdir)/osisscripref.cpp
+OSISFIL += $(filtersdir)/osiswordjs.cpp
 
 libsword_la_SOURCES += $(filtersdir)/latin1utf8.cpp
 libsword_la_SOURCES += $(filtersdir)/latin1utf16.cpp

Modified: trunk/src/modules/filters/osiswebif.cpp
===================================================================
--- trunk/src/modules/filters/osiswebif.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/osiswebif.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -26,7 +26,7 @@
 SWORD_NAMESPACE_START
 
 
-OSISWEBIF::OSISWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp") {
+OSISWEBIF::OSISWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp"), javascript(false) {
 }
 
 bool OSISWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
@@ -200,6 +200,16 @@
 			else {	// empty transChange marker?
 			}
 		}
+		// ok to leave these in
+		else if (!strcmp(tag.getName(), "div")) {
+			buf += tag;
+		}
+		else if (!strcmp(tag.getName(), "span")) {
+			buf += tag;
+		}
+		else if (!strcmp(tag.getName(), "br")) {
+			buf += tag;
+		}
 		else {
 			return OSISHTMLHREF::handleToken(buf, token, userData);
 		}

Added: trunk/src/modules/filters/osiswordjs.cpp
===================================================================
--- trunk/src/modules/filters/osiswordjs.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/osiswordjs.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -0,0 +1,141 @@
+/******************************************************************************
+ *
+ * osisstrongs -	SWFilter descendant to hide or show strongs number
+ *			in a OSIS module.
+ */
+
+
+#include <stdlib.h>
+#include <osiswordjs.h>
+#include <swmodule.h>
+#ifndef __GNUC__
+#else
+#include <unixstr.h>
+#endif
+#include <ctype.h>
+#include <utilxml.h>
+#include <versekey.h>
+
+SWORD_NAMESPACE_START
+
+const char oName[] = "Word Javascript";
+const char oTip[] = "Toggles Word Javascript data";
+
+const SWBuf choices[3] = {"Off", "On", ""};
+const StringList oValues(&choices[0], &choices[2]);
+
+
+OSISWordJS::OSISWordJS() : SWOptionFilter(oName, oTip, &oValues) {
+	setOptionValue("Off");
+
+     defaultGreekLex   = 0;
+     defaultHebLex     = 0;
+     defaultGreekParse = 0;
+     defaultHebParse   = 0;
+     mgr               = 0;
+}
+
+
+OSISWordJS::~OSISWordJS() {
+}
+
+
+char OSISWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+	char token[2112]; // cheese.  Fix.
+	int tokpos = 0;
+	bool intoken = false;
+	bool lastspace = false;
+	int wordNum = 1;
+	char val[128];
+	char *valto;
+	char *ch;
+	
+
+	const SWBuf orig = text;
+	const char * from = orig.c_str();
+
+	for (text = ""; *from; ++from) {
+		if (*from == '<') {
+			intoken = true;
+			tokpos = 0;
+			token[0] = 0;
+			token[1] = 0;
+			token[2] = 0;
+			continue;
+		}
+		if (*from == '>') {	// process tokens
+			intoken = false;
+			if ((*token == 'w') && (token[1] == ' ')) {	// Word
+				if (option) {
+					XMLTag wtag(token);
+					SWBuf lemma = wtag.getAttribute("lemma");
+					SWBuf strong = "";
+					SWBuf morph = wtag.getAttribute("morph");
+					char gh = 0;
+					VerseKey *vkey = 0;
+					if (key) {
+						vkey = SWDYNAMIC_CAST(VerseKey, key);
+					}
+					if ((!strncmp(lemma.c_str(), "x-Strongs:", 10)) || (!strncmp(lemma.c_str(), "strong:", 7))) {
+						char *num = strstr(lemma.c_str(), ":");
+						num++;
+						gh = isdigit(*num) ? 0:*num;
+						if (!gh) {
+							if (vkey) {
+								gh = vkey->Testament() ? 'H' : 'G';
+							}
+						}
+						else num++;
+						strong = num;
+						SWModule *sLex = 0;
+						if (gh == 'G') {
+							sLex = defaultGreekLex;
+						}
+						if (gh == 'H') {
+							sLex = defaultHebLex;
+						}
+						if (sLex) {
+							sLex->setKey(strong.c_str());
+							strong = sLex->RenderText();
+						}
+					}
+					SWBuf layer = (vkey)?vkey->getOSISRef():key->getText();
+					for (int i = 0; i < layer.size(); i++) {
+						if ((!isdigit(layer[i])) && (!isalpha(layer[i]))) {
+							layer[i] = '_';
+						}
+					}
+					text.appendFormatted("<div id=\"%s_%d\" class=\"word-layer\">%s<br/>%s</div>", layer.c_str(), wordNum, strong.c_str(), morph.c_str());
+					text.appendFormatted("<span onclick=\"wordInfo(\'%s_%d\', \'image0002\');\" >", layer.c_str(), wordNum);
+					wordNum++;
+
+
+
+				}
+			}
+			if ((*token == '/') && (token[1] == 'w') && option) {	// Word
+				text += "</w></span>";
+				continue;
+			}
+			
+			// if not a strongs token, keep token in text
+			text.append('<');
+			text.append(token);
+			text.append('>');
+			
+			continue;
+		}
+		if (intoken) {
+			if (tokpos < 2045)
+				token[tokpos++] = *from;
+				token[tokpos+2] = 0;
+		}
+		else	{
+			text.append(*from);
+			lastspace = (*from == ' ');
+		}
+	}
+	return 0;
+}
+
+SWORD_NAMESPACE_END

Modified: trunk/src/modules/filters/thmlhtmlhref.cpp
===================================================================
--- trunk/src/modules/filters/thmlhtmlhref.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/thmlhtmlhref.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -28,6 +28,7 @@
 	if (module) {
 		version = module->Name();
 		BiblicalText = (!strcmp(module->Type(), "Biblical Texts"));
+		SecHead = false;
 	}	
 }
 
@@ -166,7 +167,13 @@
 					u->SecHead = true;
 					buf += "<br /><b><i>";
 				}
+				else {
+					buf += tag;
+				}
 			}
+			else {
+				buf += tag;
+			}
 		}
 		else if (tag.getName() && (!strcmp(tag.getName(), "img") || !strcmp(tag.getName(), "image"))) {
 			const char *src = strstr(token, "src");

Modified: trunk/src/modules/filters/thmlstrongs.cpp
===================================================================
--- trunk/src/modules/filters/thmlstrongs.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/thmlstrongs.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -48,10 +48,10 @@
 	SWBuf tmp;
 	bool newText = false;
 
-		SWBuf orig = text;
-		from = orig.c_str();
+	SWBuf orig = text;
+	from = orig.c_str();
 
-		for (text = ""; *from; from++) {
+	for (text = ""; *from; from++) {
 		if (*from == '<') {
 			intoken = true;
 			tokpos = 0;

Modified: trunk/src/modules/filters/thmlvariants.cpp
===================================================================
--- trunk/src/modules/filters/thmlvariants.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/thmlvariants.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -58,6 +58,7 @@
         if ( option == 0 || option == 1) { //we want primary or variant only
 		bool intoken = false;
 		bool hide = false;
+		bool invar = false;
 		
 		SWBuf token;
 		SWBuf orig = text;
@@ -76,18 +77,26 @@
 				intoken = false;
 				
 				if ( !strncmp(token.c_str(), variantCompareString, 28)) { //only one of the variants, length of the two strings is 28 in both cases 
+					invar = true;
 					hide = true;
-                                  	continue;
+					continue;
 				}
+				if (!strncmp(token.c_str(), "div type=\"variant\"", 18)) {
+					invar = true;
+					continue;
+				}
+				if (!strncmp(token.c_str(), "/div", 4)) {
+					hide = false;
+					if (invar) {
+						invar = false;
+						continue;
+					}
+				}
 				if (!hide) {
 					text += '<';
 					text.append(token);
 					text += '>';
 				}
-                                if (!strncmp(token.c_str(), "/div", 4)) {
-					hide = false;
-                                	continue;
-				}
 
 				continue;
 			}

Added: trunk/src/modules/filters/thmlwordjs.cpp
===================================================================
--- trunk/src/modules/filters/thmlwordjs.cpp	2005-03-04 18:09:38 UTC (rev 1737)
+++ trunk/src/modules/filters/thmlwordjs.cpp	2005-03-08 03:23:20 UTC (rev 1738)
@@ -0,0 +1,250 @@
+/******************************************************************************
+ *
+ * thmlstrongs -	SWFilter descendant to hide or show strongs number
+ *			in a ThML module.
+ */
+
+
+#include <stdlib.h>
+#include <thmlwordjs.h>
+#include <swmodule.h>
+#ifndef __GNUC__
+#else
+#include <unixstr.h>
+#endif
+#include <ctype.h>
+#include <utilxml.h>
+#include <versekey.h>
+
+SWORD_NAMESPACE_START
+
+const char oName[] = "Word Javascript";
+const char oTip[] = "Toggles Word Javascript data";
+
+const SWBuf choices[3] = {"Off", "On", ""};
+const StringList oValues(&choices[0], &choices[2]);
+
+
+ThMLWordJS::ThMLWordJS() : SWOptionFilter(oName, oTip, &oValues) {
+	setOptionValue("Off");
+
+     defaultGreekLex   = 0;
+     defaultHebLex     = 0;
+     defaultGreekParse = 0;
+     defaultHebParse   = 0;
+     mgr               = 0;
+}
+
+
+ThMLWordJS::~ThMLWordJS() {
+}
+
+
+char ThMLWordJS::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
+	char token[2112]; // cheese.  Fix.
+	int tokpos = 0;
+	bool intoken = false;
+	bool lastspace = false;
+	int word = 1;
+	char val[128];
+	char *valto;
+	char *ch;
+	char wordstr[5];
+	unsigned int textStart = 0, lastAppendLen = 0, textEnd = 0;
+	char gh = 0;
+	SWBuf tmp;
+	bool newText = false;
+	bool needWordOut = false;
+	AttributeValue *wordAttrs = 0;
+	
+
+	const SWBuf orig = text;
+	const char * from = orig.c_str();
+	VerseKey *vkey = 0;
+	if (key) {
+		vkey = SWDYNAMIC_CAST(VerseKey, key);
+	}
+
+	for (text = ""; *from; from++) {
+		if (*from == '<') {
+			intoken = true;
+			tokpos = 0;
+			token[0] = 0;
+			token[1] = 0;
+			token[2] = 0;
+			textEnd = text.length();
+			continue;
+		}
+		if (*from == '>') {	// process tokens
+			intoken = false;
+			if (!strnicmp(token, "sync type=\"Strongs\" ", 20)) {	// Strongs
+				if (option) {
+					valto = val;
+					for (unsigned int i = 27; token[i] != '\"' && i < 150; i++)
+						*valto++ = token[i];
+					*valto = 0;
+					if (atoi((!isdigit(*val))?val+1:val) < 5627) {
+						// normal strongs number
+						sprintf(wordstr, "%03d", word++);
+						needWordOut = (word > 2);
+						wordAttrs = &(module->getEntryAttributes()["Word"][wordstr]);
+						(*wordAttrs)["Strongs"] = val;
+//printf("Adding: [\"Word\"][%s][\"Strongs\"] = %s\n", wordstr, val);
+						tmp = "";
+						tmp.append(text.c_str()+textStart, (int)(textEnd - textStart));
+						(*wordAttrs)["Text"] = tmp;
+						text.append("</span>");
+						SWBuf ts;
+						ts.appendFormatted("%d", textStart);
+						(*wordAttrs)["TextStart"] = ts;
+//printf("Adding: [\"Word\"][%s][\"Text\"] = %s\n", wordstr, tmp.c_str());
+						newText = true;
+					}
+					else {
+						// verb morph
+						(*wordAttrs)["Morph"] = val;
+//printf("Adding: [\"Word\"][%s][\"Morph\"] = %s\n", wordstr, val);
+					}
+				}
+
+			}
+			if (!strncmp(token, "sync type=\"morph\"", 17)) {
+				for (ch = token+17; *ch; ch++) {
+					if (!strncmp(ch, "class=\"", 7)) {
+						valto = val;
+						for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
+							*valto++ = ch[i];
+						*valto = 0;
+						(*wordAttrs)["MorphClass"] = val;
+//printf("Adding: [\"Word\"][%s][\"MorphClass\"] = %s\n", wordstr, val);
+					}
+					if (!strncmp(ch, "value=\"", 7)) {
+						valto = val;
+						for (unsigned int i = 7; ch[i] != '\"' && i < 127; i++)
+							*valto++ = ch[i];
+						*valto = 0;
+						(*wordAttrs)["Morph"] = val;
+//printf("Adding: [\"Word\"][%s][\"Morph\"] = %s\n", wordstr, val);
+					}
+				}
+				newText = true;
+			}
+			// if not a strongs token, keep token in text
+			text += '<';
+			text += token;
+			text += '>';
+			if (needWordOut) {
+				char wstr[10];
+				sprintf(wstr, "%03d", word-2);
+				AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]);
+				needWordOut = false;
+				SWBuf strong = (*wAttrs)["Strongs"];
+				SWBuf morph = (*wAttrs)["Morph"];
+				SWBuf morphClass = (*wAttrs)["MorphClass"];
+				SWBuf wordText = (*wAttrs)["Text"];
+				SWBuf textSt = (*wAttrs)["TextStart"];
+				if (strong.size()) {
+					char gh = 0;
+					gh = isdigit(strong[0]) ? 0:strong[0];
+					if (!gh) {
+						if (vkey) {
+							gh = vkey->Testament() ? 'H' : 'G';
+						}
+					}
+					else strong << 1;
+
+					SWModule *sLex = 0;
+					if (gh == 'G') {
+						sLex = defaultGreekLex;
+					}
+					if (gh == 'H') {
+						sLex = defaultHebLex;
+					}
+					if (sLex) {
+						sLex->setKey(strong.c_str());
+						strong = sLex->RenderText();
+					}
+					SWBuf layer = (vkey)?vkey->getOSISRef():key->getText();
+					for (int i = 0; i < layer.size(); i++) {
+						if ((!isdigit(layer[i])) && (!isalpha(layer[i]))) {
+							layer[i] = '_';
+						}
+					}
+					if (textSt.size()) {
+						int textStr = atoi(textSt.c_str());
+						textStr += lastAppendLen;
+						SWBuf spanStart = "";
+						spanStart.appendFormatted("<div id=\"%s_%s\" class=\"word-layer\">%s<br/>%s</div>", layer.c_str(), wstr, strong.c_str(), morph.c_str());
+						spanStart.appendFormatted("<span onclick=\"wordInfo(\'%s_%s\', \'i2\');\" >", layer.c_str(), wstr);
+						text.insert(textStr, spanStart);
+						lastAppendLen = spanStart.length();
+					}
+				}
+
+			}
+			if (newText) {
+				textStart = text.length(); newText = false;
+			}
+			continue;
+		}
+		if (intoken) {
+			if (tokpos < 2045)
+				token[tokpos++] = *from;
+				token[tokpos+2] = 0;
+		}
+		else	{
+			text += *from;
+			lastspace = (*from == ' ');
+		}
+	}
+
+				char wstr[10];
+				sprintf(wstr, "%03d", word-1);
+				AttributeValue *wAttrs = &(module->getEntryAttributes()["Word"][wstr]);
+				needWordOut = false;
+				SWBuf strong = (*wAttrs)["Strongs"];
+				SWBuf morph = (*wAttrs)["Morph"];
+				SWBuf morphClass = (*wAttrs)["MorphClass"];
+				SWBuf wordText = (*wAttrs)["Text"];
+				SWBuf textSt = (*wAttrs)["TextStart"];
+				if (strong.size()) {
+					char gh = 0;
+					gh = isdigit(strong[0]) ? 0:strong[0];
+					if (!gh) {
+						if (vkey) {
+							gh = vkey->Testament() ? 'H' : 'G';
+						}
+					}
+					else strong << 1;
+
+					SWModule *sLex = 0;
+					if (gh == 'G') {
+						sLex = defaultGreekLex;
+					}
+					if (gh == 'H') {
+						sLex = defaultHebLex;
+					}
+					if (sLex) {
+						sLex->setKey(strong.c_str());
+						strong = sLex->RenderText();
+					}
+					SWBuf layer = (vkey)?vkey->getOSISRef():key->getText();
+					for (int i = 0; i < layer.size(); i++) {
+						if ((!isdigit(layer[i])) && (!isalpha(layer[i]))) {
+							layer[i] = '_';
+						}
+					}
+					if (textSt.size()) {
+						int textStr = atoi(textSt.c_str());
+						textStr += lastAppendLen;
+						SWBuf spanStart = "";
+						spanStart.appendFormatted("<div id=\"%s_%s\" class=\"word-layer\">%s<br/>%s</div>", layer.c_str(), wstr, strong.c_str(), morph.c_str());
+						spanStart.appendFormatted("<span onclick=\"wordInfo(\'%s_%s\', \'i2\');\" >", layer.c_str(), wstr);
+						text.insert(textStr, spanStart);
+					}
+				}
+
+	return 0;
+}
+
+SWORD_NAMESPACE_END



More information about the sword-cvs mailing list