Ignore:
Timestamp:
2010-09-02T14:10:35+02:00 (14 years ago)
Author:
yellowbkpk
Message:

Be a little more loose with Service URL checking. Fix the projection check.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/AddWMSLayerPanel.java

    r22941 r22942  
    214214        serviceUrl = null;
    215215        try {
    216             if (serviceUrlStr.endsWith("?")) {
    217                 // It's the root of the URL. We need to append the GetCapabilities
    218                 // query parameters
     216            if (!serviceUrlStr.trim().contains("capabilities")) {
     217                // If the url doesn't already have GetCapabilities, add it in
    219218                serviceUrl = new URL(serviceUrlStr + "VERSION=1.1.1&SERVICE=WMS&REQUEST=GetCapabilities");
    220             } else if (serviceUrlStr.toLowerCase().contains("getcapabilities")) {
    221                 // The URL already contains the GetCapabilities query parameters
     219            } else {
     220                // Otherwise assume it's a good URL and let the subsequent error
     221                // handling systems deal with problems
    222222                serviceUrl = new URL(serviceUrlStr);
    223             } else {
    224                 JOptionPane.showMessageDialog(this, tr("Invalid service URL."),
    225                         tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
    226                 return;
    227223            }
    228224        } catch (HeadlessException e) {
     
    233229            return;
    234230        }
     231
     232        System.out.println("Connecting to: " + serviceUrl);
    235233
    236234        String incomingData;
     
    252250        }
    253251
     252        System.out.println(incomingData);
     253
    254254        Document document;
    255255        try {
     
    272272        }
    273273
    274         treeRootNode.setUserObject(serviceUrl.getHost());
    275         Element capabilityElem = getChild(document.getDocumentElement(), "Capability");
    276         List<Element> children = getChildren(capabilityElem, "Layer");
    277         List<LayerDetails> layers = parseLayers(children, new HashSet<String>());
    278 
    279         updateTreeList(layers);
     274        try {
     275            treeRootNode.setUserObject(serviceUrl.getHost());
     276            Element capabilityElem = getChild(document.getDocumentElement(), "Capability");
     277            List<Element> children = getChildren(capabilityElem, "Layer");
     278            List<LayerDetails> layers = parseLayers(children, new HashSet<String>());
     279            updateTreeList(layers);
     280        } catch(Exception e) {
     281            JOptionPane.showMessageDialog(this, tr("Could not parse WMS layer list."),
     282                    tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
     283            e.printStackTrace();
     284            return;
     285        }
    280286    }
    281287
     
    358364        for (Projection proj : Projection.allProjections) {
    359365            if (proj instanceof ProjectionSubPrefs) {
    360                 return ((ProjectionSubPrefs) proj).getPreferencesFromCode(crs) == null;
     366                if (((ProjectionSubPrefs) proj).getPreferencesFromCode(crs) == null) {
     367                    return true;
     368                }
    361369            } else {
    362                 return proj.toCode().equals(crs);
     370                if (proj.toCode().equals(crs)) {
     371                    return true;
     372                }
    363373            }
    364374        }
Note: See TracChangeset for help on using the changeset viewer.