int main(int argc, char **argv) { if (argc != 2) { cerr << "\nusage: " << *argv << " <modName>\n" << endl; exit(-1); } SWMgr library(new MarkupFilterMgr(FMT_XHTML)); library.setGlobalOption("Headings", "On"); SWModule *module = library.getModule(argv[1]); if (!module) { cerr << "\nCouldn't find module: " << argv[1] << "\n" << endl; exit(-2); } module->setKey("Ps.3.1"); outputCurrentVerse(module); module->setKey("Mark.1.14"); outputCurrentVerse(module); cout << "\nWhitespace tests around headings:\n"; ((VerseKey *)module->getKey())->setIntros(true); *module = TOP; // module heading cout << module->renderText() << "\n"; (*module)++; // testament heading cout << module->renderText() << "\n"; (*module)++; // book heading cout << module->renderText() << "\n"; (*module)++; // chapter heading cout << module->renderText() << "\n"; (*module)++; // verse body module->renderText(); SWBuf header = module->getEntryAttributes()["Heading"]["Preverse"]["0"]; cout << module->renderText(header) << endl; cout << "[ " << module->getKeyText() << " ] " << module->renderText() << "\n"; (*module)++; // verse body module->renderText(); header = module->getEntryAttributes()["Heading"]["Preverse"]["0"]; cout << module->renderText(header) << endl; cout << "[ " << module->getKeyText() << " ] " << module->renderText() << "\n"; return 0; }
const char *SWModule_getEntryAttributes(SWHANDLE hmodule, const char *level1, const char *level2, const char *level3) { SWModule *module = (SWModule *)hmodule; static SWBuf retval; module->renderText(); retval = module->getEntryAttributes()[level1][level2][level3].c_str(); return (retval.length()) ? (const char*)retval.c_str() : NULL; }
const char *SWModule_getFootnoteRefList(SWHANDLE hmodule, const char *key, const char *note) { SWModule *module = (SWModule *)hmodule; static SWBuf refList; module->popError(); module->setKey(key); module->renderText(); refList = module->getEntryAttributes()["Footnote"][note]["refList"].c_str(); return (refList) ? (const char*)refList.c_str() : NULL; }
const char *SWModule_getFootnoteType(SWHANDLE hmodule, const char *key, const char *note) { SWModule *module = (SWModule *)hmodule; static SWBuf type; module->popError(); module->setKey(key); module->renderText(); type = module->getEntryAttributes()["Footnote"][note]["type"].c_str(); return (type) ? (const char*)type.c_str() : NULL; }
const char *SWModule_getPreverseHeader(SWHANDLE hmodule, const char *key, int pvHeading) { SWModule *module = (SWModule *)hmodule; static SWBuf preverseHeading; char buf[12]; sprintf(buf, "%i", pvHeading); module->setKey(key); module->renderText(); preverseHeading = module->getEntryAttributes()["Heading"]["Preverse"][buf].c_str(); return (preverseHeading.length()) ? (const char*)preverseHeading.c_str() : NULL; }
const char *SWModule_getFootnoteBody(SWHANDLE hmodule, const char *key, const char *note) { SWModule *module = (SWModule *)hmodule; static SWBuf body; module->popError(); module->setKey(key); module->renderText(); body = module->getEntryAttributes()["Footnote"][note]["body"].c_str(); SWKey *keybuf = module->getKey();; module->renderFilter(body, keybuf); return (body) ? (const char*)body.c_str() : NULL; }
std::string SwordPluginAPI::getVerses(const std::string& moduleName, const std::string& key, const std::string& single) { /*Get verses from a specific module (e.g. "ESV"). Set your biblepassage in key e.g. "James 1:19" */ std::stringstream passage; std::stringstream tmpPassage; std::stringstream out; SWModule *module = displayLibrary->getModule(moduleName.c_str()); /* if (!module || !(strcmp(module->Type(), "Biblical Texts") == 0 || strcmp(module->Type(), "Commentaries") == 0)) { PDL_JSException(parms, "getVerses: Module isn't verse driven (no bible or commentary). Currently BibleZ HD doesn't support Generic Books and Lexicons / Dictionaries!"); return PDL_TRUE; } */ //module->setKey(key); //VerseKey *vk = (VerseKey*)module->getKey(); VerseKey *vk = dynamic_cast<VerseKey *>(module->getKey()); //vk->AutoNormalize(false); vk->Headings(true); vk->setText(key.c_str()); ListKey verses = VerseKey().ParseVerseList(key.c_str(), "", true); passage << "{\"bookName\": \"" << vk->getBookName() << "\", \"cnumber\": \"" << vk->Chapter() << "\", \"vnumber\": \"" << vk->Verse() << "\", \"passageSingle\" : \"" << vk->getBookName() << " " << vk->Chapter() << ":" << vk->Verse() << "\", \"passage\" : \"" << vk->getBookName() << " " << vk->Chapter() << "\", \"abbrev\": \"" << vk->getBookAbbrev() << "\"}"; if (single == "true") { verses = VerseKey().ParseVerseList(key.c_str(), "", true); } else { tmpPassage << vk->getBookName() << " " << vk->Chapter(); verses = VerseKey().ParseVerseList(tmpPassage.str().c_str(), "", true); } AttributeTypeList::iterator i1; AttributeList::iterator i2; AttributeValue::iterator i3; out << "["; for (verses = TOP; !verses.Error(); verses++) { vk->setText(verses); if (strcmp(module->RenderText(), "") != 0) { //headingOn = 0; out << "{\"content\": \"" << convertString(module->RenderText()) << "\", "; out << "\"vnumber\": \"" << vk->Verse() << "\", "; out << "\"cnumber\": \"" << vk->Chapter() << "\""; out << ", \"heading\": \"" << convertString(module->getEntryAttributes()["Heading"]["Preverse"]["0"].c_str()) << "\""; for (i1 = module->getEntryAttributes().begin(); i1 != module->getEntryAttributes().end(); i1++) { if (strcmp(i1->first, "Footnote") == 0) { out << ", \"footnotes\": ["; for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) { out << "{"; for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) { out << "\"" << i3->first << "\": \"" << convertString(i3->second.c_str()) << "\""; //footnotesOn = 1; if (i3 != --i2->second.end()) { out << ", "; } } out << "}"; if (i2 != --i1->second.end()) { out << ", "; } } out << "]"; } /*else if (strcmp(i1->first, "Word") == 0) { out << ", \"words\": ["; for (i2 = i1->second.begin(); i2 != i1->second.end(); i2++) { out << "{"; for (i3 = i2->second.begin(); i3 != i2->second.end(); i3++) { out << "\"" << i3->first << "\": \"" << convertString(i3->second.c_str()) << "\""; if (i3 != --i2->second.end()) { out << ", "; } } out << "}"; if (i2 != --i1->second.end()) { out << ", "; } } out << "]"; } */ } if (vk->Chapter() == 1 && vk->Verse() == 1) { vk->setChapter(0); vk->setVerse(0); out << ", \"intro\": \"" << convertString(module->RenderText()) << "\""; } out << "}"; ListKey helper = verses; helper++; if (!helper.Error()) { out << ", "; } } } out << "]"; /*if (out.str() == "[]") { PDL_JSException(parms, "getVerses: Chapter is not available in this module!"); return PDL_FALSE; }*/ out << "<#split#>" << passage.str(); return out.str(); }
/* * Class: org_crosswire_android_sword_SWModule * Method: getEntryAttribute * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getEntryAttribute (JNIEnv *env, jobject me, jstring level1JS, jstring level2JS, jstring level3JS, jboolean filteredJS) { init(); const char *level1 = env->GetStringUTFChars(level1JS, NULL); const char *level2 = env->GetStringUTFChars(level2JS, NULL); const char *level3 = env->GetStringUTFChars(level3JS, NULL); bool filtered = (filteredJS == JNI_TRUE); jclass clazzString = env->FindClass("java/lang/String"); jobjectArray ret = 0; SWModule *module = getModule(env, me); if (module) { module->renderText(); // force parse vector<SWBuf> results; sword::AttributeTypeList &entryAttribs = module->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; } ret = (jobjectArray) env->NewObjectArray(results.size(), clazzString, NULL); SWLog::getSystemLog()->logDebug("getEntryAttributes: size returned: %d", results.size()); for (int i = 0; i < results.size(); i++) { if (filtered) { env->SetObjectArrayElement(ret, i, env->NewStringUTF(assureValidUTF8(module->renderText(results[i].c_str())))); } else { env->SetObjectArrayElement(ret, i, env->NewStringUTF(assureValidUTF8(results[i].c_str()))); } } } env->ReleaseStringUTFChars(level3JS, level3); env->ReleaseStringUTFChars(level2JS, level2); env->ReleaseStringUTFChars(level1JS, level1); return (ret) ? ret : (jobjectArray) env->NewObjectArray(0, clazzString, NULL); }