Drop beanshell for android 9+. Replaced by rnd pattern.
This commit is contained in:
parent
2ecb2a556a
commit
df68cc70b3
1 changed files with 46 additions and 18 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus;
|
||||||
import android.database.sqlite.SQLiteDiskIOException;
|
import android.database.sqlite.SQLiteDiskIOException;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.os.Build;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
@ -24,6 +25,8 @@ import java.nio.ByteBuffer;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import bsh.Interpreter;
|
import bsh.Interpreter;
|
||||||
|
|
||||||
|
@ -53,6 +56,8 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
private OsmandApplication ctx;
|
private OsmandApplication ctx;
|
||||||
private boolean onlyReadonlyAvailable = false;
|
private boolean onlyReadonlyAvailable = false;
|
||||||
|
|
||||||
|
private static final Pattern RND_PATTERN =
|
||||||
|
Pattern.compile(".*(\\{rnd:([0-9a-zA-Z-_~:\\/?#\\[\\]@!$&'\\(\\)*+,;=]+)\\}).*");
|
||||||
|
|
||||||
|
|
||||||
public SQLiteTileSource(OsmandApplication ctx, File f, List<TileSourceTemplate> toFindUrl){
|
public SQLiteTileSource(OsmandApplication ctx, File f, List<TileSourceTemplate> toFindUrl){
|
||||||
|
@ -112,26 +117,49 @@ public class SQLiteTileSource implements ITileSource {
|
||||||
if (zoom > maxZoom)
|
if (zoom > maxZoom)
|
||||||
return null;
|
return null;
|
||||||
SQLiteConnection db = getDatabase();
|
SQLiteConnection db = getDatabase();
|
||||||
if(db == null || db.isReadOnly() || urlTemplate == null){
|
if (db == null || db.isReadOnly() || urlTemplate == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)){
|
String urlTemplate = this.urlTemplate;
|
||||||
try {
|
try {
|
||||||
if(bshInterpreter == null){
|
Matcher matcher = RND_PATTERN.matcher(urlTemplate);
|
||||||
bshInterpreter = new Interpreter();
|
if (matcher.matches()) {
|
||||||
bshInterpreter.eval(urlTemplate);
|
int i = 0;
|
||||||
|
String rndString = matcher.group(1);
|
||||||
|
String valuesString = matcher.group(2);
|
||||||
|
if (!Algorithms.isEmpty(valuesString)) {
|
||||||
|
String[] valuesArray = valuesString.split(",");
|
||||||
|
if (valuesArray.length > 0) {
|
||||||
|
i = ((x + y) % valuesArray.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (String) bshInterpreter.eval("getTileUrl("+zoom+","+x+","+y+");");
|
urlTemplate = urlTemplate.replace(rndString, i + "");
|
||||||
} catch (bsh.EvalError e) {
|
return MessageFormat.format(urlTemplate, zoom + "", x + "", y + "");
|
||||||
LOG.debug("getUrlToLoad Error" + e.getMessage());
|
|
||||||
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
|
} else if (TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)) {
|
||||||
LOG.error(e.getMessage(), e);
|
if (Build.VERSION.SDK_INT >= 28) {
|
||||||
return null;
|
Toast.makeText(ctx, "Beanshell is not supported on Android 9+ anymore. Use {rnd:1,2,3,a,b,c} pattern instead.", Toast.LENGTH_LONG).show();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (bshInterpreter == null) {
|
||||||
|
bshInterpreter = new Interpreter();
|
||||||
|
bshInterpreter.eval(urlTemplate);
|
||||||
|
}
|
||||||
|
return (String) bshInterpreter.eval("getTileUrl(" + zoom + "," + x + "," + y + ");");
|
||||||
|
} catch (bsh.EvalError e) {
|
||||||
|
LOG.debug("getUrlToLoad Error" + e.getMessage());
|
||||||
|
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
LOG.error(e.getMessage(), e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return MessageFormat.format(urlTemplate, zoom + "", x + "", y + "");
|
||||||
}
|
}
|
||||||
}
|
} catch (IllegalArgumentException e) {
|
||||||
else {
|
LOG.error("Cannot build url for template: " + urlTemplate, e);
|
||||||
return MessageFormat.format(urlTemplate, zoom+"", x+"", y+""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue