Add beanshell use. Use new optional field RULE in table INFO. Value "beanshell" makes to use interpreter for processing of a script which put into the field URL. If there is no field RULE or its value differs from "beanshell", content of the field URL used as before.

This commit is contained in:
ilasica 2015-02-09 10:25:18 +03:00
parent e96d0a05a1
commit cd3dc04880
2 changed files with 24 additions and 4 deletions

View file

@ -30,7 +30,7 @@ import bsh.Interpreter;
public class TileSourceManager { public class TileSourceManager {
private static final Log log = PlatformUtil.getLog(TileSourceManager.class); private static final Log log = PlatformUtil.getLog(TileSourceManager.class);
private static final String RULE_BEANSHELL = "beanshell"; public static final String RULE_BEANSHELL = "beanshell";
public static final String RULE_YANDEX_TRAFFIC = "yandex_traffic"; public static final String RULE_YANDEX_TRAFFIC = "yandex_traffic";
private static final String RULE_WMS = "wms_tile"; private static final String RULE_WMS = "wms_tile";

View file

@ -12,6 +12,7 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
@ -19,6 +20,7 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import bsh.Interpreter;
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;
@ -33,7 +35,7 @@ public class SQLiteTileSource implements ITileSource {
private ITileSource base; private ITileSource base;
private String urlTemplate = null; private String urlTemplate = null;
private String name; private String name;
private SQLiteConnection db; private SQLiteConnection db = null;
private final File file; private final File file;
private int minZoom = 1; private int minZoom = 1;
private int maxZoom = 17; private int maxZoom = 17;
@ -41,7 +43,8 @@ public class SQLiteTileSource implements ITileSource {
private boolean timeSupported = false; private boolean timeSupported = false;
private int expirationTimeMillis = -1; // never private int expirationTimeMillis = -1; // never
private boolean isEllipsoid = false; private boolean isEllipsoid = false;
private String rule = null;
static final int tileSize = 256; static final int tileSize = 256;
private OsmandApplication ctx; private OsmandApplication ctx;
private boolean onlyReadonlyAvailable = false; private boolean onlyReadonlyAvailable = false;
@ -101,6 +104,7 @@ public class SQLiteTileSource implements ITileSource {
return base != null ? base.getTileSize() : tileSize; return base != null ? base.getTileSize() : tileSize;
} }
Interpreter bshInterpreter = null;
@Override @Override
public String getUrlToLoad(int x, int y, int zoom) { public String getUrlToLoad(int x, int y, int zoom) {
if (zoom > maxZoom) if (zoom > maxZoom)
@ -109,7 +113,22 @@ public class SQLiteTileSource implements ITileSource {
if(db == null || db.isReadOnly() || urlTemplate == null){ if(db == null || db.isReadOnly() || urlTemplate == null){
return null; return null;
} }
return MessageFormat.format(urlTemplate, zoom+"", x+"", y+""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
if(TileSourceManager.RULE_BEANSHELL.equalsIgnoreCase(rule)){
try {
if(bshInterpreter == null){
bshInterpreter = new Interpreter();
bshInterpreter.eval(urlTemplate);
}
return (String) bshInterpreter.eval("getTileUrl("+zoom+","+x+","+y+");");
} catch (bsh.EvalError e) {
log.error(e.getMessage(), e);
return null;
}
}
else {
return MessageFormat.format(urlTemplate, zoom+"", x+"", y+""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
} }
@Override @Override
@ -414,6 +433,7 @@ public class SQLiteTileSource implements ITileSource {
} }
public void closeDB(){ public void closeDB(){
bshInterpreter = null;
if(db != null){ if(db != null){
db.close(); db.close();
db = null; db = null;