Ignore:
Timestamp:
2011-01-28T00:49:15+01:00 (13 years ago)
Author:
framm
Message:

Add a "blacklisted" property to imagery layers; set this property from a
compiled-in list of regular expressions; disable blacklisted entries in
the Imagery menu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r3720 r3826  
    66
    77/**
    8  * Class that stores info about a WMS server.
     8 * Class that stores info about an image background layer.
    99 *
    1010 * @author Frederik Ramm <frederik@remote.org>
    1111 */
    1212public class ImageryInfo implements Comparable<ImageryInfo> {
     13
    1314    public enum ImageryType {
    1415        WMS("wms"),
     
    2627    }
    2728
     29    private final static String[] BLACKLIST_REGEXES = {
     30        // These entries are for Google tile servers (names and IPV4 numbers)
     31        ".*\\.google\\.com/.*",
     32        ".*209\\.85\\.2\\d\\d.*",
     33        ".*209\\.85\\.1[3-9]\\d.*",
     34        ".*209\\.85\\.12[89].*"
     35    };
     36
    2837    String name;
    29     String url=null;
     38    String url = null;
    3039    String cookies = null;
    3140    public final String eulaAcceptanceRequired;
     
    3342    double pixelPerDegree = 0.0;
    3443    int maxZoom = 0;
     44    private boolean blacklisted = false;
    3545
    3646    public ImageryInfo(String name) {
     
    4151    public ImageryInfo(String name, String url) {
    4252        this.name=name;
    43         setURL(url);
     53        setUrl(url);
    4454        this.eulaAcceptanceRequired = null;
    4555    }
     
    4757    public ImageryInfo(String name, String url, String eulaAcceptanceRequired) {
    4858        this.name=name;
    49         setURL(url);
     59        setUrl(url);
    5060        this.eulaAcceptanceRequired = eulaAcceptanceRequired;
    5161    }
     
    5363    public ImageryInfo(String name, String url, String eulaAcceptanceRequired, String cookies) {
    5464        this.name=name;
    55         setURL(url);
     65        setUrl(url);
    5666        this.cookies=cookies;
    5767        this.eulaAcceptanceRequired = eulaAcceptanceRequired;
     
    6070    public ImageryInfo(String name, String url, String cookies, double pixelPerDegree) {
    6171        this.name=name;
    62         setURL(url);
     72        setUrl(url);
    6373        this.cookies=cookies;
    6474        this.pixelPerDegree=pixelPerDegree;
     
    7181        String e4 = null;
    7282        if(url != null && !url.isEmpty()) {
    73             e2 = getFullURL();
     83            e2 = getFullUrl();
    7484        }
    7585        if(cookies != null && !cookies.isEmpty()) {
     
    110120        this.name=array.get(0);
    111121        if(array.size() >= 2) {
    112             setURL(array.get(1));
     122            setUrl(array.get(1));
    113123        }
    114124        if(array.size() >= 3) {
     
    160170    }
    161171
    162     public void setURL(String url) {
     172    public void setUrl(String url) {
     173
     174        // determine if URL is on blacklist and flag accordingly.
     175        blacklisted = false;
     176        for (String blacklistRegex : BLACKLIST_REGEXES) {
     177            if (url.matches(blacklistRegex)) {
     178                blacklisted = true;
     179                System.err.println("layer '" + name + "' uses blacklisted URL");
     180                break;
     181            }
     182        }
     183
    163184        for (ImageryType type : ImageryType.values()) {
    164185            if (url.startsWith(type.getUrlString() + ":")) {
     
    182203    }
    183204
    184     public String getURL() {
     205    public String getUrl() {
    185206        return this.url;
    186207    }
     
    198219    }
    199220
    200     public String getFullURL() {
     221    public String getFullUrl() {
    201222        return imageryType.getUrlString() + ":" + url;
    202223    }
     
    229250        return url != null && url.contains("{") && url.contains("}");
    230251    }
     252
     253    public boolean isBlacklisted() {
     254        return blacklisted;
     255    }
    231256}
Note: See TracChangeset for help on using the changeset viewer.