StringList *SWModule_impl::getKeyChildren() throw(CORBA::SystemException) { sword::SWKey *key = delegate->getKey(); StringList *retVal = new StringList; int count = 0; sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { retVal->length(6); SWBuf num; num.appendFormatted("%d", vkey->Testament()); (*retVal)[0] = CORBA::string_dup(num.c_str()); num = ""; num.appendFormatted("%d", vkey->Book()); (*retVal)[1] = CORBA::string_dup(num.c_str()); num = ""; num.appendFormatted("%d", vkey->Chapter()); (*retVal)[2] = CORBA::string_dup(num.c_str()); num = ""; num.appendFormatted("%d", vkey->Verse()); (*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()); } 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(tkey->getLocalName()); } while (tkey->nextSibling()); tkey->parent(); } } } return retVal; }
void printTree(TreeKeyIdx treeKey, TreeKeyIdx *target = 0, int level = 1) { if (!target) target = &treeKey; unsigned long currentOffset = target->getOffset(); std::cout << ((currentOffset == treeKey.getOffset()) ? "==>" : ""); for (int i = 0; i < level; i++) std::cout << "\t"; std::cout << treeKey.getLocalName() << "/\n"; if (treeKey.firstChild()) { printTree(treeKey, target, level+1); treeKey.parent(); } if (treeKey.nextSibling()) printTree(treeKey, target, level); }
/* * Class: org_crosswire_android_sword_SWModule * Method: getKeyChildren * Signature: ()[Ljava/lang/String; */ JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyChildren (JNIEnv *env, jobject me) { init(); jclass clazzString = env->FindClass("java/lang/String"); jobjectArray ret; SWModule *module = getModule(env, me); if (module) { sword::SWKey *key = module->getKey(); int count = 0; sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); if (vkey) { ret = (jobjectArray) env->NewObjectArray(7, clazzString, NULL); SWBuf num; num.appendFormatted("%d", vkey->getTestament()); env->SetObjectArrayElement(ret, 0, env->NewStringUTF(assureValidUTF8(num.c_str()))); num = ""; num.appendFormatted("%d", vkey->getBook()); env->SetObjectArrayElement(ret, 1, env->NewStringUTF(assureValidUTF8(num.c_str()))); num = ""; num.appendFormatted("%d", vkey->getChapter()); env->SetObjectArrayElement(ret, 2, env->NewStringUTF(assureValidUTF8(num.c_str()))); num = ""; num.appendFormatted("%d", vkey->getVerse()); env->SetObjectArrayElement(ret, 3, env->NewStringUTF(assureValidUTF8(num.c_str()))); num = ""; num.appendFormatted("%d", vkey->getChapterMax()); env->SetObjectArrayElement(ret, 4, env->NewStringUTF(assureValidUTF8(num.c_str()))); num = ""; num.appendFormatted("%d", vkey->getVerseMax()); env->SetObjectArrayElement(ret, 5, env->NewStringUTF(assureValidUTF8(num.c_str()))); env->SetObjectArrayElement(ret, 6, env->NewStringUTF(assureValidUTF8(vkey->getBookName()))); } else { TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); if (tkey) { if (tkey->firstChild()) { do { count++; } while (tkey->nextSibling()); tkey->parent(); } ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); count = 0; if (tkey->firstChild()) { do { env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(tkey->getLocalName()))); } while (tkey->nextSibling()); tkey->parent(); } } } return ret; } }