@@ -276,10 +276,25 @@ Java_at_tomtasche_reader_background_CoreWrapper_createServer(JNIEnv *env, jclass
276276 s_server = odr::HttpServer (config);
277277}
278278
279- JNIEXPORT void JNICALL
279+ JNIEXPORT jobject JNICALL
280280Java_at_tomtasche_reader_background_CoreWrapper_hostFile (JNIEnv *env, jclass clazz, jstring prefix, jobject options) {
281281 __android_log_print (ANDROID_LOG_INFO, " smn" , " host file" );
282282
283+ jclass resultClass = env->FindClass (" at/tomtasche/reader/background/CoreWrapper$CoreResult" );
284+ jmethodID resultConstructor = env->GetMethodID (resultClass, " <init>" , " ()V" );
285+ jobject result = env->NewObject (resultClass, resultConstructor);
286+
287+ jfieldID errorField = env->GetFieldID (resultClass, " errorCode" , " I" );
288+
289+ jclass listClass = env->FindClass (" java/util/List" );
290+ jmethodID addMethod = env->GetMethodID (listClass, " add" , " (Ljava/lang/Object;)Z" );
291+
292+ jfieldID pageNamesField = env->GetFieldID (resultClass, " pageNames" , " Ljava/util/List;" );
293+ auto pageNames = (jobject) env->GetObjectField (result, pageNamesField);
294+
295+ jfieldID pagePathsField = env->GetFieldID (resultClass, " pagePaths" , " Ljava/util/List;" );
296+ auto pagePaths = (jobject) env->GetObjectField (result, pagePathsField);
297+
283298 std::string inputPathCpp = getStringField (env, options, " inputPath" );
284299 std::string prefixCpp = convertString (env, prefix);
285300
@@ -292,12 +307,29 @@ Java_at_tomtasche_reader_background_CoreWrapper_hostFile(JNIEnv *env, jclass cla
292307 htmlConfig.embed_shipped_resources = false ;
293308
294309 try {
295- s_server->serve_file (file, prefixCpp, odr::HtmlConfig ());
310+ odr::HtmlViews htmlViews = s_server->serve_file (file, prefixCpp, odr::HtmlConfig ());
311+
312+ for (const auto &view: htmlViews) {
313+ if (file.is_document_file () &&
314+ file.document_file ().document_type () != odr::DocumentType::text &&
315+ view.name () == " document" ) {
316+ continue ;
317+ }
318+
319+ jstring pageName = env->NewStringUTF (view.name ().c_str ());
320+ env->CallBooleanMethod (pageNames, addMethod, pageName);
321+
322+ std::string pagePathCpp = " http://localhost:29665/file/" + prefixCpp + " /" + view.path ();
323+ jstring pagePath = env->NewStringUTF (pagePathCpp.c_str ());
324+ env->CallBooleanMethod (pagePaths, addMethod, pagePath);
325+ }
296326 } catch (const std::exception &e) {
297327 __android_log_print (ANDROID_LOG_ERROR, " smn" , " Unhandled C++ exception: %s" , e.what ());
298328 } catch (...) {
299329 __android_log_print (ANDROID_LOG_ERROR, " smn" , " Unhandled C++ exception without further information" );
300330 }
331+
332+ return result;
301333}
302334
303335JNIEXPORT void JNICALL
0 commit comments