- Timestamp:
- 2016-07-06T22:51:51+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java
r10179 r10520 84 84 formats.setSelectedItem(wms.getPreferredFormats()); 85 85 } catch (MalformedURLException ex) { 86 Main.error(ex, false); 86 87 JOptionPane.showMessageDialog(getParent(), tr("Invalid service URL."), 87 88 tr("WMS Error"), JOptionPane.ERROR_MESSAGE); 88 89 } catch (IOException ex) { 90 Main.error(ex, false); 89 91 JOptionPane.showMessageDialog(getParent(), tr("Could not retrieve WMS layer list."), 90 92 tr("WMS Error"), JOptionPane.ERROR_MESSAGE); … … 93 95 String title = tr("WMS Error"); 94 96 String message = tr("Could not parse WMS layer list."); 95 Main.error("Could not parse WMS layer list. Incoming data:\n"+incomingData); 96 if (incomingData != null 97 && (incomingData.startsWith("<html>") || incomingData.startsWith("<HTML>")) 98 && (incomingData.endsWith("</html>") || incomingData.endsWith("</HTML>"))) { 97 Main.error(ex, "Could not parse WMS layer list. Incoming data:\n"+incomingData); 98 if ((incomingData.startsWith("<html>") || incomingData.startsWith("<HTML>")) 99 && (incomingData.endsWith("</html>") || incomingData.endsWith("</HTML>"))) { 99 100 GuiHelper.notifyUserHtmlError(AddWMSLayerPanel.this, title, message, incomingData); 100 101 } else { 102 if (ex.getMessage() != null) { 103 message += '\n' + ex.getMessage(); 104 } 101 105 JOptionPane.showMessageDialog(getParent(), message, title, JOptionPane.ERROR_MESSAGE); 102 106 } -
trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
r10404 r10520 40 40 private final String incomingData; 41 41 42 /** 43 * Constructs a new {@code WMSGetCapabilitiesException} 44 * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 45 * @param incomingData the answer from WMS server 46 */ 42 47 public WMSGetCapabilitiesException(Throwable cause, String incomingData) { 43 48 super(cause); … … 45 50 } 46 51 52 /** 53 * Constructs a new {@code WMSGetCapabilitiesException} 54 * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method 55 * @param incomingData the answer from the server 56 * @since 10520 57 */ 58 public WMSGetCapabilitiesException(String message, String incomingData) { 59 super(message); 60 this.incomingData = incomingData; 61 } 62 63 /** 64 * Returns the answer from WMS server. 65 * @return the answer from WMS server 66 */ 47 67 public String getIncomingData() { 48 68 return incomingData; … … 160 180 }); 161 181 Document document = builder.parse(new InputSource(new StringReader(incomingData))); 182 Element root = document.getDocumentElement(); 183 184 // Check if the request resulted in ServiceException 185 if ("ServiceException".equals(root.getTagName())) { 186 throw new WMSGetCapabilitiesException(root.getTextContent(), incomingData); 187 } 162 188 163 189 // Some WMS service URLs specify a different base URL for their GetMap service 164 Element child = getChild( document.getDocumentElement(), "Capability");190 Element child = getChild(root, "Capability"); 165 191 child = getChild(child, "Request"); 166 192 child = getChild(child, "GetMap"); … … 197 223 } 198 224 199 Element capabilityElem = getChild( document.getDocumentElement(), "Capability");225 Element capabilityElem = getChild(root, "Capability"); 200 226 List<Element> children = getChildren(capabilityElem, "Layer"); 201 227 layers = parseLayers(children, new HashSet<String>()); … … 327 353 private static List<Element> getChildren(Element parent, String name) { 328 354 List<Element> retVal = new ArrayList<>(); 329 for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { 330 if (child instanceof Element && name.equals(child.getNodeName())) { 331 retVal.add((Element) child); 355 if (parent != null) { 356 for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { 357 if (child instanceof Element && name.equals(child.getNodeName())) { 358 retVal.add((Element) child); 359 } 332 360 } 333 361 }
Note:
See TracChangeset
for help on using the changeset viewer.