Add a JNI method to check if an url exists and is a redirection.

This commit is contained in:
Matthieu Gautier 2019-08-13 11:10:56 +02:00
parent 858c2fecbe
commit 6ab52e2b9e
2 changed files with 25 additions and 0 deletions

View File

@ -224,6 +224,21 @@ JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getMimeType(
return mimeType;
}
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_checkUrl(
JNIEnv* env, jobject obj, jstring url)
{
jstring finalUrl;
std::string cUrl = jni2c(url, env);
try {
auto entry = READER->getEntryFromEncodedPath(cUrl);
entry = entry.getFinalEntry();
finalUrl = c2jni(entry.getPath(), env);
} catch (std::exception& e) {
finalUrl = c2jni("", env);
}
return finalUrl;
}
JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getContent(
JNIEnv* env, jobject obj, jobject url, jobject titleObj, jobject mimeTypeObj, jobject sizeObj)
{

View File

@ -38,6 +38,16 @@ public class JNIKiwixReader
public native String getMimeType(String url);
/**
* Check if a url exists and is a redirect or not.
*
* Return an empty string if the url doesn't exist in the reader.
* Return the url of the "final" entry.
* - equal to the input url if the entry is not a redirection.
* - different if the url is a redirection (and the webview should redirect to it).
*/
public native String checkUrl(String url);
/**
* Get the content of a article.
*