diff options
Diffstat (limited to 'bindings/corba')
-rw-r--r-- | bindings/corba/Makefile.am | 2 | ||||
-rw-r--r-- | bindings/corba/java/Makefile | 12 | ||||
-rw-r--r-- | bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java | 9 | ||||
-rw-r--r-- | bindings/corba/omniorbcpp/Makefile | 46 | ||||
-rw-r--r-- | bindings/corba/omniorbcpp/server.cpp | 117 | ||||
-rw-r--r-- | bindings/corba/omniorbcpp/swordorb-impl.cpp | 493 | ||||
-rw-r--r-- | bindings/corba/omniorbcpp/swordorb-impl.hpp | 114 | ||||
-rw-r--r-- | bindings/corba/omniorbcpp/testclient.cpp | 114 | ||||
-rw-r--r-- | bindings/corba/orbitcpp/swordorb-impl.cpp | 40 | ||||
-rw-r--r-- | bindings/corba/orbitcpp/swordorb-impl.hpp | 11 | ||||
-rw-r--r-- | bindings/corba/swordorb.idl | 11 |
11 files changed, 950 insertions, 19 deletions
diff --git a/bindings/corba/Makefile.am b/bindings/corba/Makefile.am index b626afd..b2dff05 100644 --- a/bindings/corba/Makefile.am +++ b/bindings/corba/Makefile.am @@ -1,3 +1,3 @@ EXTRA_DIST = swordorb.idl -SUBDIRS = orbitcpp java +SUBDIRS = orbitcpp omniorbcpp java diff --git a/bindings/corba/java/Makefile b/bindings/corba/java/Makefile index e342a9c..c4ae46c 100644 --- a/bindings/corba/java/Makefile +++ b/bindings/corba/java/Makefile @@ -1,9 +1,17 @@ +#CHANGE THESE TO MATCH YOUR SYSTEM TOMCAT_HOME=/opt/tomcat -#SERVLET_LIB=${TOMCAT_HOME}/common/lib/servlet-api.jar -SERVLET_LIB=${TOMCAT_HOME}/lib/servlet-api.jar instdir=${TOMCAT_HOME}/webapps/swordweb + +# Typically you'll point this to your home directory, e.g. #instdir=/home/swordweb/livehtml/webapp #instdir=/home/scribe/src/swordweb/webapp + +SERVLET_LIB=${TOMCAT_HOME}/lib/servlet-api.jar + +# Older tomcat uses this path +#SERVLET_LIB=${TOMCAT_HOME}/common/lib/servlet-api.jar + + all: src/org/crosswire/sword/orb/SWMgr.java classes/org/crosswire/sword/orb/SwordOrb.class src/org/crosswire/sword/orb/SWMgr.java: ../swordorb.idl diff --git a/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java b/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java index d6987e9..1816c77 100644 --- a/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java +++ b/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java @@ -249,17 +249,18 @@ System.out.println("ORB found in session"); ModInfo[] modInfoList = mgr.getModInfoList(); System.out.println("sequence size: " + modInfoList.length); SWModule module; -/* for (int i = 0; i < modInfoList.length; i++) { - System.out.println(modInfoList[i].name + ": " + modInfoList[i].category + ": " + modInfoList[i].language); + System.out.println(modInfoList[i].name + ": " + modInfoList[i].category + ": " + modInfoList[i].language + ": " + modInfoList[i].description); +/* module = mgr.getModuleByName(modInfoList[i].name); module.setKeyText("jas1:19"); System.out.println(module.getRenderText()); - } */ + } +/* module = mgr.getModuleByName("WHNU"); module.setKeyText("rev.22.21"); - System.out.println(new String(module.getRawEntry().getBytes("iso8859-1"), "UTF-8")); + System.out.println(module.getRawEntry()); /* boolean lucene = module.hasSearchFramework(); SearchHit[] searchResults = module.search("God love world", (lucene)?SearchType.LUCENE:SearchType.MULTIWORD, 0, ""); diff --git a/bindings/corba/omniorbcpp/Makefile b/bindings/corba/omniorbcpp/Makefile new file mode 100644 index 0000000..021f0dd --- /dev/null +++ b/bindings/corba/omniorbcpp/Makefile @@ -0,0 +1,46 @@ +all: server testclient + +PREFIX = $(shell grep ^prefix ../../../Makefile|cut -f3 -d' ') + +#sword stuff +CXXFLAGS += $(shell PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig pkg-config --cflags sword) +CFLAGS += $(shell PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig pkg-config --cflags sword) +LIBS += $(shell PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig pkg-config --libs sword) + +#orbit stuff +CFLAGS += $(shell orbit2-config --cflags) +CFLAGS += $(shell PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig pkg-config --cflags omniORB4) +CXXFLAGS += $(shell PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig pkg-config --cflags omniORB4) +LIBS += $(shell PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig pkg-config --libs omniORB4) + +LIBS += -L/usr/lib64 + +#comment out for release +CXXFLAGS += -g -O0 +CFLAGS += -g -O0 +LDFLAGS += -g -O0 +#----------------------------------------------------------------------------- + + +server: server.cpp swordorb-impl.o swordorb-stubs.o + $(CXX) $(CXXFLAGS) -I. -o server server.cpp swordorb-impl.o swordorb-stubs.o $(LIBS) + +testclient: testclient.cpp swordorb-impl.cpp swordorb-stubs.o + $(CXX) $(CXXFLAGS) -I. -o testclient testclient.cpp swordorb-stubs.o $(LIBS) + +swordorb-impl.o: swordorb.h swordorb-impl.cpp + $(CXX) $(CXXFLAGS) -I. -c swordorb-impl.cpp + + +swordorb.h: ./../swordorb.idl + omniidl -bcxx -Wbh=.h -Wbs=-stubs.cpp ./../swordorb.idl + +swordorb-stubs.o: swordorb-stubs.cpp + $(CC) $(CFLAGS) -I. -c swordorb-stubs.cpp + +clean: + rm -f *.h *-stubs.cpp *.cc *.o *.c server testclient + +install: + mkdir -p $(PREFIX)/bin + cp -f server $(PREFIX)/bin/swordorbserver diff --git a/bindings/corba/omniorbcpp/server.cpp b/bindings/corba/omniorbcpp/server.cpp new file mode 100644 index 0000000..8f33d23 --- /dev/null +++ b/bindings/corba/omniorbcpp/server.cpp @@ -0,0 +1,117 @@ +/* + * 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 "swordorb-impl.hpp" +#include <iostream> +#include <swmgr.h> +#include "../orbitcpp/webmgr.hpp" + +SWConfig *sysConf = 0; +WebMgr *swordMgr = 0; + +class CleanStatics { +public: + CleanStatics() {} + ~CleanStatics() { + if (swordMgr) + delete swordMgr; + + if (sysConf) + delete sysConf; + } +} cleanStatics; + + + + +int main (int argc, char** argv) +{ + try { + + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-sysConf")) { + if ((i+1) < argc) + sysConf = new SWConfig(argv[i+1]); + } + } + + swordMgr = new WebMgr(sysConf); + + + const char* options[][2] = { + { "nativeCharCodeSet", "UTF-8" } + , { 0, 0 } + }; + + + // Initialise the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options); + + // Obtain a reference to the root POA. + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); + + // We allocate the objects on the heap. Since these are reference + // counted objects, they will be deleted by the POA when they are no + // longer needed. +// swordorb_SWModule_i* myswordorb_SWModule_i = new swordorb_SWModule_i(); + swordorb_SWMgr_i* myswordorb_SWMgr_i = new swordorb_SWMgr_i(swordMgr); + + + // Activate the objects. This tells the POA that the objects are + // ready to accept requests. + // PortableServer::ObjectId_var myswordorb_SWModule_iid = poa->activate_object(myswordorb_SWModule_i); + PortableServer::ObjectId_var myswordorb_SWMgr_iid = poa->activate_object(myswordorb_SWMgr_i); + + + { + // IDL interface: swordorb::SWMgr + CORBA::Object_var ref = myswordorb_SWMgr_i->_this(); + CORBA::String_var sior(orb->object_to_string(ref)); + std::cout << (char*)sior << std::endl; + } + + + + // Obtain a POAManager, and tell the POA to start accepting + // requests on its objects. + PortableServer::POAManager_var pman = poa->the_POAManager(); + pman->activate(); + + orb->run(); + orb->destroy(); + } + catch(CORBA::TRANSIENT&) { + std::cerr << "Caught system exception TRANSIENT -- unable to contact the " + << "server." << std::endl; + } + catch(CORBA::SystemException& ex) { + std::cerr << "Caught a CORBA::" << ex._name() << std::endl; + } + catch(CORBA::Exception& ex) { + std::cerr << "Caught CORBA::Exception: " << ex._name() << std::endl; + } + catch(omniORB::fatalException& fe) { + std::cerr << "Caught omniORB::fatalException:" << std::endl; + std::cerr << " file: " << fe.file() << std::endl; + std::cerr << " line: " << fe.line() << std::endl; + std::cerr << " mesg: " << fe.errmsg() << std::endl; + } + return 0; +} + diff --git a/bindings/corba/omniorbcpp/swordorb-impl.cpp b/bindings/corba/omniorbcpp/swordorb-impl.cpp new file mode 100644 index 0000000..e33d879 --- /dev/null +++ b/bindings/corba/omniorbcpp/swordorb-impl.cpp @@ -0,0 +1,493 @@ +/* + * 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 <iostream> +#include <vector> + +#include <swordorb-impl.hpp> + +#include <swmgr.h> +#include <versekey.h> +#include <treekeyidx.h> +#include <swbuf.h> +#include <localemgr.h> +#include <utilstr.h> + + +using sword::VerseKey; +using sword::SWBuf; +using sword::TreeKeyIdx; + + +sword::RawText NULLMod("/dev/null", SWNULL, SWNULL); + + + + +swordorb_SWModule_i::swordorb_SWModule_i(sword::SWModule *delegate) +{ + this->delegate = delegate; +} + +void swordorb_SWModule_i::terminateSearch() { + delegate->terminateSearch = true; +} + +swordorb::SearchHitList* swordorb_SWModule_i::search(const char* istr, swordorb::SearchType srchType, ::CORBA::Long flags, const char* scope) { + int stype = 2; + sword::ListKey lscope; + if (srchType == swordorb::REGEX) stype = 0; + if (srchType == swordorb::PHRASE) stype = -1; + if (srchType == swordorb::MULTIWORD) stype = -2; + if (srchType == swordorb::ENTRYATTR) stype = -3; + if (srchType == swordorb::LUCENE) stype = -4; + sword::ListKey result; + + if ((scope) && (strlen(scope)) > 0) { + sword::SWKey *p = delegate->CreateKey(); + sword::VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); + if (!parser) { + delete p; + parser = new VerseKey(); + } + *parser = delegate->getKeyText(); + lscope = parser->ParseVerseList(scope, *parser, true); + result = delegate->Search(istr, stype, flags, &lscope); + delete parser; + } + else result = delegate->Search(istr, stype, flags); + + swordorb::SearchHitList *retVal = new swordorb::SearchHitList; + int count = 0; + for (result = sword::TOP; !result.Error(); result++) count++; + retVal->length(count); + int i = 0; + + // if we're sorted by score, let's re-sort by verse, because Java can always re-sort by score + result = sword::TOP; + if ((count) && (long)result.getElement()->userData) + result.sort(); + + for (result = sword::TOP; !result.Error(); result++) { + (*retVal)[i].modName = CORBA::string_dup(assureValidUTF8(delegate->Name())); + (*retVal)[i].key = CORBA::string_dup(assureValidUTF8((const char *)result)); + (*retVal)[i++].score = (long)result.getElement()->userData; + } + + return retVal; +} + +::CORBA::Char swordorb_SWModule_i::error() { + return delegate->Error(); +} + +::CORBA::Long swordorb_SWModule_i::getEntrySize(){ + return delegate->getEntrySize(); +} + +swordorb::StringList* swordorb_SWModule_i::getEntryAttribute(const char* level1, const char* level2, const char* level3, ::CORBA::Boolean filtered){ + delegate->RenderText(); // force parse + std::vector<SWBuf> results; + swordorb::StringList *retVal = new swordorb::StringList; + + sword::AttributeTypeList &entryAttribs = delegate->getEntryAttributes(); + sword::AttributeTypeList::iterator i1Start, i1End; + sword::AttributeList::iterator i2Start, i2End; + sword::AttributeValue::iterator i3Start, i3End; + + if ((level1) && (*level1)) { + i1Start = entryAttribs.find(level1); + i1End = i1Start; + if (i1End != entryAttribs.end()) + i1End++; + } + else { + i1Start = entryAttribs.begin(); + i1End = entryAttribs.end(); + } + for (;i1Start != i1End; i1Start++) { + if ((level2) && (*level2)) { + i2Start = i1Start->second.find(level2); + i2End = i2Start; + if (i2End != i1Start->second.end()) + i2End++; + } + else { + i2Start = i1Start->second.begin(); + i2End = i1Start->second.end(); + } + for (;i2Start != i2End; i2Start++) { + if ((level3) && (*level3)) { + i3Start = i2Start->second.find(level3); + i3End = i3Start; + if (i3End != i2Start->second.end()) + i3End++; + } + else { + i3Start = i2Start->second.begin(); + i3End = i2Start->second.end(); + } + for (;i3Start != i3End; i3Start++) { + results.push_back(i3Start->second); + } + if (i3Start != i3End) + break; + } + if (i2Start != i2End) + break; + } + + retVal->length(results.size()); + for (int i = 0; i < results.size(); i++) { + if (filtered) { + (*retVal)[i] = CORBA::string_dup(assureValidUTF8(delegate->RenderText(results[i].c_str()))); + } + else { + (*retVal)[i] = CORBA::string_dup(assureValidUTF8(results[i].c_str())); + } + } + + return retVal; +} + +swordorb::StringList* swordorb_SWModule_i::parseKeyList(const char* keyText){ + sword::VerseKey *parser = dynamic_cast<VerseKey *>(delegate->getKey()); + swordorb::StringList *retVal = new swordorb::StringList; + if (parser) { + sword::ListKey result; + result = parser->ParseVerseList(keyText, *parser, true); + int count = 0; + for (result = sword::TOP; !result.Error(); result++) { + count++; + } + retVal->length(count); + count = 0; + for (result = sword::TOP; !result.Error(); result++) { + (*retVal)[count++] = CORBA::string_dup(assureValidUTF8((const char *)result)); + } + } + else { + retVal->length(1); + (*retVal)[0] = CORBA::string_dup(assureValidUTF8(keyText)); + } + + return retVal; +} + +void swordorb_SWModule_i::setKeyText(const char* keyText) { + sword::SWKey *key = delegate->getKey(); + sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); + if (vkey && (*keyText=='+' ||*keyText=='-')) { + if (!stricmp(keyText+1, "book")) { + vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1)); + return; + } + else if (!stricmp(keyText+1, "chapter")) { + vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1)); + return; + } + } + + delegate->KeyText(keyText); +} + +char* swordorb_SWModule_i::getKeyText(){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->KeyText())); +} + +::CORBA::Boolean swordorb_SWModule_i::hasKeyChildren(){ + sword::SWKey *key = delegate->getKey(); + bool retVal = false; + + TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); + if (tkey) { + retVal = tkey->hasChildren(); + } + return retVal; +} + + +swordorb::StringList* swordorb_SWModule_i::getKeyChildren(){ + sword::SWKey *key = delegate->getKey(); + swordorb::StringList *retVal = new swordorb::StringList; + int count = 0; + + sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); + if (vkey) { + retVal->length(7); + SWBuf num; + num.appendFormatted("%d", vkey->getTestament()); + (*retVal)[0] = CORBA::string_dup(num.c_str()); + num = ""; + num.appendFormatted("%d", vkey->getBook()); + (*retVal)[1] = CORBA::string_dup(num.c_str()); + num = ""; + num.appendFormatted("%d", vkey->getChapter()); + (*retVal)[2] = CORBA::string_dup(num.c_str()); + num = ""; + num.appendFormatted("%d", vkey->getVerse()); + (*retVal)[3] = CORBA::string_dup(num.c_str()); + num = ""; + num.appendFormatted("%d", vkey->getChapterMax()); + (*retVal)[4] = CORBA::string_dup(num.c_str()); + num = ""; + num.appendFormatted("%d", vkey->getVerseMax()); + (*retVal)[5] = CORBA::string_dup(num.c_str()); + (*retVal)[6] = CORBA::string_dup(vkey->getBookName()); + } + else { + TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); + if (tkey) { + if (tkey->firstChild()) { + do { + count++; + } + while (tkey->nextSibling()); + tkey->parent(); + } + retVal->length(count); + count = 0; + if (tkey->firstChild()) { + do { + (*retVal)[count++] = CORBA::string_dup(assureValidUTF8(tkey->getLocalName())); + } + while (tkey->nextSibling()); + tkey->parent(); + } + } + } + return retVal; +} + +char* swordorb_SWModule_i::getKeyParent(){ + sword::SWKey *key = delegate->getKey(); + SWBuf retVal = ""; + + TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); + if (tkey) { + if (tkey->parent()) { + retVal = tkey->getText(); + } + } + return CORBA::string_dup(assureValidUTF8((const char *)retVal)); +} + +char* swordorb_SWModule_i::getName(){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->Name())); +} + +char* swordorb_SWModule_i::getDescription(){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->Description())); +} + +char* swordorb_SWModule_i::getCategory(){ + SWBuf type = delegate->Type(); + SWBuf cat = delegate->getConfigEntry("Category"); + if (cat.length() > 0) + type = cat; + return CORBA::string_dup(assureValidUTF8((char *)type.c_str())); +} + +void swordorb_SWModule_i::previous(){ + delegate->decrement(); +} + +void swordorb_SWModule_i::next(){ + delegate->increment(); +} + +void swordorb_SWModule_i::begin(){ + delegate->setPosition(sword::TOP); +} + +char* swordorb_SWModule_i::getStripText(){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->StripText())); +} + +char* swordorb_SWModule_i::getRenderText(){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->RenderText())); +} + +char* swordorb_SWModule_i::getRawEntry(){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->getRawEntry())); +} + +void swordorb_SWModule_i::setRawEntry(const char* entryBuffer){ + delegate->setEntry(entryBuffer); +} + +char* swordorb_SWModule_i::getConfigEntry(const char* key){ + return CORBA::string_dup(assureValidUTF8(((char *)delegate->getConfigEntry(key)) ? (char *)delegate->getConfigEntry(key):SWNULL)); +} + +void swordorb_SWModule_i::deleteSearchFramework(){ + delegate->deleteSearchFramework(); +} + +::CORBA::Boolean swordorb_SWModule_i::hasSearchFramework(){ + return (delegate->hasSearchFramework() && delegate->isSearchOptimallySupported("God", -4, 0, 0)); +} + + +// ------------------------------------------------------------------------- + + +swordorb_SWMgr_i::swordorb_SWMgr_i(WebMgr *delegate) +{ + this->delegate = delegate; +} + +// Methods corresponding to IDL attributes and operations +swordorb::ModInfoList* swordorb_SWMgr_i::getModInfoList() { + + swordorb::ModInfoList *milist = new swordorb::ModInfoList; + sword::SWModule *module = 0; + + int size = 0; + for (sword::ModMap::iterator it = delegate->Modules.begin(); it != delegate->Modules.end(); it++) { + if ((!(it->second->getConfigEntry("CipherKey"))) || (*(it->second->getConfigEntry("CipherKey")))) + size++; + } + +// if (size > 183) size = 183; + milist->length(size); + int i = 0; + for (sword::ModMap::iterator it = delegate->Modules.begin(); it != delegate->Modules.end(); it++) { + module = it->second; + if ((!(module->getConfigEntry("CipherKey"))) || (*(module->getConfigEntry("CipherKey")))) { + SWBuf type = module->Type(); + SWBuf cat = module->getConfigEntry("Category"); + if (cat.length() > 0) + type = cat; + (*milist)[i].name = CORBA::string_dup(assureValidUTF8(module->Name())); + (*milist)[i].description = CORBA::string_dup(assureValidUTF8(module->Description())); + (*milist)[i].category = CORBA::string_dup(assureValidUTF8(type.c_str())); + (*milist)[i++].language = CORBA::string_dup(assureValidUTF8(module->Lang())); + if (i >= size) break; + } + } + return milist; +} + +swordorb::SWModule_ptr swordorb_SWMgr_i::getModuleByName(const char* name){ + SWModuleMap::iterator it; + swordorb::SWModule_ptr retVal; + sword::SWModule *mod = delegate->Modules[name]; + it = moduleImpls.find((mod)?name:SWNULL); + if (it == moduleImpls.end()) { + moduleImpls[(mod)?name:SWNULL] = new swordorb_SWModule_i((mod)?mod:&NULLMod); + it = moduleImpls.find((mod)?name:SWNULL); + } + if (it != moduleImpls.end()) { + retVal = it->second->_this(); + } + return swordorb::SWModule::_duplicate(retVal); +} + +char* swordorb_SWMgr_i::getPrefixPath(){ + return CORBA::string_dup(assureValidUTF8(delegate->prefixPath)); +} + +char* swordorb_SWMgr_i::getConfigPath(){ + return CORBA::string_dup(assureValidUTF8(delegate->configPath)); +} + +void swordorb_SWMgr_i::setGlobalOption(const char* option, const char* value){ + delegate->setGlobalOption(option, value); +} + +char* swordorb_SWMgr_i::getGlobalOption(const char* option){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->getGlobalOption(option))); +} + +char* swordorb_SWMgr_i::getGlobalOptionTip(const char* option){ + return CORBA::string_dup(assureValidUTF8((char *)delegate->getGlobalOptionTip(option))); +} + +char* swordorb_SWMgr_i::filterText(const char* filterName, const char* text){ + SWBuf buf = text; + delegate->setGlobalOption("Greek Accents", "Off"); + char errStatus = delegate->filterText(filterName, buf); + return CORBA::string_dup(assureValidUTF8((char *)buf.c_str())); +} + +swordorb::StringList* swordorb_SWMgr_i::getGlobalOptions(){ + sword::StringList options = delegate->getGlobalOptions(); + swordorb::StringList *retVal = new swordorb::StringList; + int count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + count++; + } + retVal->length(count); + count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + (*retVal)[count++] = CORBA::string_dup(assureValidUTF8(it->c_str())); + } + return retVal; +} + +swordorb::StringList* swordorb_SWMgr_i::getGlobalOptionValues(const char* option){ + sword::StringList options = delegate->getGlobalOptionValues(option); + swordorb::StringList *retVal = new swordorb::StringList; + int count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + count++; + } + retVal->length(count); + count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + (*retVal)[count++] = CORBA::string_dup(assureValidUTF8(it->c_str())); + } + return retVal; +} + +void swordorb_SWMgr_i::setCipherKey(const char* modName, const char* key){ + delegate->setCipherKey(modName, key); +} + +void swordorb_SWMgr_i::terminate(){ + exit(0); +} + +::CORBA::Boolean swordorb_SWMgr_i::testConnection(){ + return true; +} + +void swordorb_SWMgr_i::setJavascript(::CORBA::Boolean val){ + delegate->setJavascript(val); +} + +swordorb::StringList* swordorb_SWMgr_i::getAvailableLocales(){ + sword::StringList localeNames = LocaleMgr::getSystemLocaleMgr()->getAvailableLocales(); + swordorb::StringList *retVal = new swordorb::StringList; + int count = 0; + for (sword::StringList::iterator it = localeNames.begin(); it != localeNames.end(); it++) { + count++; + } + retVal->length(count); + count = 0; + for (sword::StringList::iterator it = localeNames.begin(); it != localeNames.end(); it++) { + (*retVal)[count++] = CORBA::string_dup(assureValidUTF8(it->c_str())); + } + return retVal; +} + +void swordorb_SWMgr_i::setDefaultLocale(const char* name){ + LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(name); +} + + diff --git a/bindings/corba/omniorbcpp/swordorb-impl.hpp b/bindings/corba/omniorbcpp/swordorb-impl.hpp new file mode 100644 index 0000000..400bcc3 --- /dev/null +++ b/bindings/corba/omniorbcpp/swordorb-impl.hpp @@ -0,0 +1,114 @@ +/* + * 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. + * + */ + +#ifndef SWORDORB_IMPL_H +#define SWORDORB_IMPL_H + +#include "swordorb.h" +#include "../orbitcpp/webmgr.hpp" +#include <swmodule.h> +#include <swmgr.h> +#include <rawtext.h> +#include <string> +#include <map> + + +static const char *SWNULL = "<SWNULL>"; +extern sword::RawText NULLMod; + + +class swordorb_SWModule_i: public POA_swordorb::SWModule { +private: + sword::SWModule *delegate; + // Make sure all instances are built on the heap by making the + // destructor non-public + //virtual ~swordorb_SWModule_i(); +public: + // standard constructor + swordorb_SWModule_i(sword::SWModule *delegate); + virtual ~swordorb_SWModule_i() {} + + // methods corresponding to defined IDL attributes and operations + void terminateSearch(); + swordorb::SearchHitList* search(const char* istr, swordorb::SearchType srchType, ::CORBA::Long flags, const char* scope); + ::CORBA::Char error(); + ::CORBA::Long getEntrySize(); + swordorb::StringList* getEntryAttribute(const char* level1, const char* level2, const char* level3, ::CORBA::Boolean filtered); + swordorb::StringList* parseKeyList(const char* keyText); + void setKeyText(const char* key); + char* getKeyText(); + ::CORBA::Boolean hasKeyChildren(); + swordorb::StringList* getKeyChildren(); + char* getKeyParent(); + char* getName(); + char* getDescription(); + char* getCategory(); + void previous(); + void next(); + void begin(); + char* getStripText(); + char* getRenderText(); + char* getRawEntry(); + void setRawEntry(const char* entryBuffer); + char* getConfigEntry(const char* key); + void deleteSearchFramework(); + ::CORBA::Boolean hasSearchFramework(); + +}; + + +// ---------------------------------------------------------------------------------- + +typedef std::map<std::string, swordorb_SWModule_i *> SWModuleMap; + +// ---------------------------------------------------------------------------------- + + +class swordorb_SWMgr_i: public POA_swordorb::SWMgr { +private: + WebMgr *delegate; + SWModuleMap moduleImpls; + // Make sure all instances are built on the heap by making the + // destructor non-public + //virtual ~swordorb_SWMgr_i(); +public: + // standard constructor + swordorb_SWMgr_i(WebMgr *delegate); + virtual ~swordorb_SWMgr_i() {}; + + // methods corresponding to defined IDL attributes and operations + swordorb::ModInfoList* getModInfoList(); + swordorb::SWModule_ptr getModuleByName(const char* name); + char* getPrefixPath(); + char* getConfigPath(); + void setGlobalOption(const char* option, const char* value); + char* getGlobalOption(const char* option); + char* getGlobalOptionTip(const char* option); + char* filterText(const char* filterName, const char* text); + swordorb::StringList* getGlobalOptions(); + swordorb::StringList* getGlobalOptionValues(const char* option); + void setCipherKey(const char* modName, const char* key); + void terminate(); + ::CORBA::Boolean testConnection(); + void setJavascript(::CORBA::Boolean val); + swordorb::StringList* getAvailableLocales(); + void setDefaultLocale(const char* name); + +}; + + +#endif diff --git a/bindings/corba/omniorbcpp/testclient.cpp b/bindings/corba/omniorbcpp/testclient.cpp new file mode 100644 index 0000000..ad7345d --- /dev/null +++ b/bindings/corba/omniorbcpp/testclient.cpp @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: f; c-basic-offset: 4 -*- */ + +/* + * 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 "swordorb.h" +#include <iostream> +#include <swbuf.h> + +int main (int argc, char *argv[]) +{ + if (argc != 2) + { + std::cerr << "Usage:" << std::endl + << " " << argv[0] << " IOR" << std::endl + << std::endl; + return -1; + } + + try { + + + const char* options[][2] = { + { "nativeCharCodeSet", "UTF-8" } + , { 0, 0 } + }; + + + // Initialise the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options); +// CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4"); + + // Get a reference to the server from the IOR passed on the + // command line + CORBA::Object_var obj = orb->string_to_object(argv[1]); + swordorb::SWMgr_var mgr = swordorb::SWMgr::_narrow(obj); + + swordorb::SWModule_ptr module; + swordorb::ModInfoList *modInfoList; + + 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"; + for (int i = 0; i < modInfoList->length(); i++) { + std::cout << (*modInfoList)[i].name << ": " << (*modInfoList)[i].category << ": " << (*modInfoList)[i].language << "\n"; +/* + if (!strncmp((*modInfoList)[i].category, "Bibl", 4)) { + module = mgr->getModuleByName((*modInfoList)[i].name); + module->setKeyText("jas1:19"); + std::cout << module->getRenderText() << "\n"; + } + std::cout << "\n"; +*/ + } +/* + swordorb::StringList *localeNames = mgr->getAvailableLocales(); + for (int i = 0; i < localeNames->length(); i++) { + std::cout << (*localeNames)[i] << "\n"; + } +*/ + mgr->setDefaultLocale("de"); + mgr->setJavascript(true); + mgr->setGlobalOption("Textual Variants", "Secondary Reading"); + mgr->setGlobalOption("Footnotes", "On"); + module = mgr->getModuleByName("NASB"); +/* + module->setKeyText("jas.1.19"); + swordorb::StringList *attr = module->getEntryAttribute("Footnote", "", "body", true); + std::cout << "length: " << attr->length() << "\n"; + for (int i = 0; i < attr->length(); i++) { + std::cout << (*attr)[i] << "\n"; + } +*/ + int i = 0; + for (module->setKeyText("gen.2.8"); !module->error() && i < 3; module->next(), i++) { + std::cout << "KeyText: " << module->getKeyText() << "\n"; + std::cout << "Text: " << module->getRenderText() << "\n"; + } +/* + swordorb::SearchHitList *searchResults; + bool lucene = module->hasSearchFramework(); + searchResults = module->search("David", (lucene)?swordorb::LUCENE:swordorb::MULTIWORD, 0, ""); + for (int i = 0; i < searchResults->length(); i++) { + std::cout << (*searchResults)[i].key << "\n"; + } + + mgr->setGlobalOption("Greek Accents", "Off"); + std::cout << "\nFiltered text: " << mgr->filterText("Greek Accents", "ὁ θεὸς") << "\n"; +*/ + + + } catch(const CORBA::Exception& ex) { + std::cout << "exception: " << ex._name() << std::endl; + } + + return 0; +} diff --git a/bindings/corba/orbitcpp/swordorb-impl.cpp b/bindings/corba/orbitcpp/swordorb-impl.cpp index da1819c..13763be 100644 --- a/bindings/corba/orbitcpp/swordorb-impl.cpp +++ b/bindings/corba/orbitcpp/swordorb-impl.cpp @@ -135,6 +135,14 @@ char *SWMgr_impl::filterText(const char *filterName, const char *text) throw(COR return CORBA::string_dup((char *)buf.c_str()); } + + + +// ------------------------------------------------------------------------ + + + + char *SWModule_impl::getCategory() throw(CORBA::SystemException) { SWBuf type = delegate->Type(); SWBuf cat = delegate->getConfigEntry("Category"); @@ -218,7 +226,6 @@ StringList *SWModule_impl::getEntryAttribute(const char *level1, const char *lev delegate->RenderText(); // force parse std::vector<SWBuf> results; StringList *retVal = new StringList; - int count = 0; sword::AttributeTypeList &entryAttribs = delegate->getEntryAttributes(); sword::AttributeTypeList::iterator i1Start, i1End; @@ -273,13 +280,29 @@ StringList *SWModule_impl::getEntryAttribute(const char *level1, const char *lev (*retVal)[i] = CORBA::string_dup(delegate->RenderText(results[i].c_str())); } else { - (*retVal)[count++] = CORBA::string_dup(results[i].c_str()); + (*retVal)[i] = CORBA::string_dup(results[i].c_str()); } } return retVal; } +void SWModule_impl::setKeyText(const char *key) throw(CORBA::SystemException) { + sword::SWKey *key = delegate->getKey(); + sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); + if (vkey && (*keyText=='+' ||*keyText=='-')) { + if (!stricmp(keyText+1, "book")) { + vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1)); + return; + } + else if (!stricmp(keyText+1, "chapter")) { + vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1)); + return; + } + } + + delegate->KeyText(key); +} StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) { sword::SWKey *key = delegate->getKey(); @@ -288,18 +311,18 @@ StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) { sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { - retVal->length(6); + retVal->length(7); SWBuf num; - num.appendFormatted("%d", vkey->Testament()); + num.appendFormatted("%d", vkey->getTestament()); (*retVal)[0] = CORBA::string_dup(num.c_str()); num = ""; - num.appendFormatted("%d", vkey->Book()); + num.appendFormatted("%d", vkey->getBook()); (*retVal)[1] = CORBA::string_dup(num.c_str()); num = ""; - num.appendFormatted("%d", vkey->Chapter()); + num.appendFormatted("%d", vkey->getChapter()); (*retVal)[2] = CORBA::string_dup(num.c_str()); num = ""; - num.appendFormatted("%d", vkey->Verse()); + num.appendFormatted("%d", vkey->getVerse()); (*retVal)[3] = CORBA::string_dup(num.c_str()); num = ""; num.appendFormatted("%d", vkey->getChapterMax()); @@ -307,6 +330,7 @@ StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) { num = ""; num.appendFormatted("%d", vkey->getVerseMax()); (*retVal)[5] = CORBA::string_dup(num.c_str()); + (*retVal)[6] = CORBA::string_dup(vkey->getBookName()); } else { TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); @@ -334,7 +358,7 @@ StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) { CORBA::Boolean SWModule_impl::hasKeyChildren() throw(CORBA::SystemException) { sword::SWKey *key = delegate->getKey(); - bool retVal = ""; + bool retVal = false; TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); if (tkey) { diff --git a/bindings/corba/orbitcpp/swordorb-impl.hpp b/bindings/corba/orbitcpp/swordorb-impl.hpp index a0801fe..3acc1b8 100644 --- a/bindings/corba/orbitcpp/swordorb-impl.hpp +++ b/bindings/corba/orbitcpp/swordorb-impl.hpp @@ -31,6 +31,7 @@ namespace swordorb { static const char *SWNULL = "<SWNULL>"; extern sword::RawText NULLMod; + //Inherit from abstract Skeleton: class SWModule_impl : public POA_swordorb::SWModule { sword::SWModule *delegate; @@ -59,13 +60,17 @@ public: char *getRawEntry() throw(CORBA::SystemException) { return CORBA::string_dup((char *)delegate->getRawEntry()); } void setRawEntry(const char *entryBuffer) throw(CORBA::SystemException) { delegate->setEntry(entryBuffer); } char *getConfigEntry(const char *key) throw(CORBA::SystemException) { return CORBA::string_dup(((char *)delegate->getConfigEntry(key)) ? (char *)delegate->getConfigEntry(key):SWNULL); } - void deleteSearchFramework() throw(CORBA::SystemException) { return delegate->deleteSearchFramework(); } + void deleteSearchFramework() throw(CORBA::SystemException) { delegate->deleteSearchFramework(); } CORBA::Boolean hasSearchFramework() throw(CORBA::SystemException) { return (delegate->hasSearchFramework() && delegate->isSearchOptimallySupported("God", -4, 0, 0)); } }; +// ---------------------------------------------------------------------------------- + typedef std::map<std::string, SWModule_impl *> SWModuleMap; +// ---------------------------------------------------------------------------------- + class SWMgr_impl : public POA_swordorb::SWMgr { WebMgr *delegate; SWModuleMap moduleImpls; @@ -90,7 +95,7 @@ public: void setDefaultLocale(const char *name) throw(CORBA::SystemException); }; -}; // namespace hellomodule +}; -#endif //_ORBIT_CPP_IDL_helloworld_IMPL_HH +#endif diff --git a/bindings/corba/swordorb.idl b/bindings/corba/swordorb.idl index 673681c..0952b27 100644 --- a/bindings/corba/swordorb.idl +++ b/bindings/corba/swordorb.idl @@ -57,15 +57,24 @@ typedef sequence<SearchHit> SearchHitList; interface SWModule { void terminateSearch(); - SearchHitList search(in string istr, in SearchType searchType, in long flags, in string scope); + SearchHitList search(in string istr, in SearchType srchType, in long flags, in string scope); char error(); long getEntrySize(); StringList getEntryAttribute(in string level1, in string level2, in string level3, in boolean filtered); StringList parseKeyList(in string keyText); + + // Special values handled for VerseKey modules: [+-][book|chapter] + // (e.g. "+chapter" will increment the VerseKey 1 chapter) void setKeyText(in string key); + string getKeyText(); boolean hasKeyChildren(); + + // This method returns child nodes for a genbook, + // but has special handling if called on a VerseKey module: + // [0..6] [testament, book, chapter, verse, chapterMax, verseMax, bookName] StringList getKeyChildren(); + string getKeyParent(); string getName(); string getDescription(); |