Changeset 13274 in josm


Ignore:
Timestamp:
2018-01-03T23:17:07+01:00 (11 months ago)
Author:
Don-vip
Message:

fix #15730 - support WMS capabilities with embedded HTML in layer Abstract tag

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r13260 r13274  
    44import java.awt.HeadlessException;
    55import java.io.IOException;
     6import java.io.InputStream;
    67import java.io.StringReader;
    78import java.io.StringWriter;
     
    235236
    236237        final Response response = HttpClient.create(getCapabilitiesUrl).connect();
    237         String incomingData = null;
    238238
    239239        if (response.getResponseCode() >= 400) {
     
    241241        }
    242242
     243        parseCapabilities(serviceUrlStr, response.getContent());
     244    }
     245
     246    void parseCapabilities(String serviceUrlStr, InputStream contentStream) throws IOException, WMSGetCapabilitiesException {
     247        String incomingData = null;
    243248        try {
    244249            DocumentBuilder builder = Utils.newSafeDOMBuilder();
     
    247252                return new InputSource(new StringReader(""));
    248253            });
    249             Document document = builder.parse(response.getContent());
     254            Document document = builder.parse(contentStream);
    250255            Element root = document.getDocumentElement();
    251256
     
    369374        getChildrenStream(element)
    370375            .filter(child -> "CRS".equals(child.getNodeName()) || "SRS".equals(child.getNodeName()))
    371             .map(child -> (String) getContent(child))
     376            .map(child -> getContent(child))
    372377            .filter(crs -> !crs.isEmpty())
    373378            .map(crs -> crs.trim().toUpperCase(Locale.ENGLISH))
     
    421426            return missing;
    422427        else {
    423             String content = (String) getContent(child);
     428            String content = getContent(child);
    424429            return (!content.isEmpty()) ? content : empty;
    425430        }
    426431    }
    427432
    428     private static Object getContent(Element element) {
     433    private static String getContent(Element element) {
    429434        NodeList nl = element.getChildNodes();
    430435        StringBuilder content = new StringBuilder();
     
    433438            switch (node.getNodeType()) {
    434439                case Node.ELEMENT_NODE:
    435                     return node;
     440                    content.append(getContent((Element) node));
     441                    break;
    436442                case Node.CDATA_SECTION_NODE:
    437443                case Node.TEXT_NODE:
  • trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java

    r11974 r13274  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertTrue;
     6
     7import java.io.IOException;
     8import java.io.InputStream;
    59
    610import org.junit.Rule;
    711import org.junit.Test;
     12import org.openstreetmap.josm.TestUtils;
    813import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    914import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    3641        assertEquals("bar", exc.getIncomingData());
    3742    }
     43
     44    /**
     45     * Non-regression test for bug #15730.
     46     * @throws IOException if any I/O error occurs
     47     * @throws WMSGetCapabilitiesException never
     48     */
     49    @Test
     50    public void testTicket15730() throws IOException, WMSGetCapabilitiesException {
     51        try (InputStream is = TestUtils.getRegressionDataStream(15730, "capabilities.xml")) {
     52            WMSImagery wms = new WMSImagery();
     53            wms.parseCapabilities(null, is);
     54            assertEquals(1, wms.getLayers().size());
     55            assertTrue(wms.getLayers().get(0).abstr.startsWith("South Carolina  NAIP Imagery 2017    Resolution: 100CM "));
     56        }
     57    }
    3858}
Note: See TracChangeset for help on using the changeset viewer.