Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r14535 r14565 51 51 static final Pattern SERVICE_EXCEPTION_PATTERN = Pattern.compile("(?s).+<ServiceException[^>]*>(.+)</ServiceException>.+"); 52 52 static final Pattern CDATA_PATTERN = Pattern.compile("(?s)\\s*<!\\[CDATA\\[(.+)\\]\\]>\\s*"); 53 static final Pattern JSON_PATTERN = Pattern.compile("\\{\"message\":\"(.+)\"\\}"); 53 54 protected final Tile tile; 54 55 private volatile URL url; … … 321 322 @Override 322 323 public String detectErrorMessage(String data) { 323 Matcher m = SERVICE_EXCEPTION_PATTERN.matcher(data); 324 return m.matches() ? removeCdata(Utils.strip(m.group(1))) : super.detectErrorMessage(data); 324 Matcher xml = SERVICE_EXCEPTION_PATTERN.matcher(data); 325 Matcher json = JSON_PATTERN.matcher(data); 326 return xml.matches() ? removeCdata(Utils.strip(xml.group(1))) 327 : json.matches() ? Utils.strip(json.group(1)) 328 : super.detectErrorMessage(data); 325 329 } 326 330 -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
r14311 r14565 174 174 } 175 175 176 /** 177 * Tests that {@code TMSCachedTileLoaderJob#JSON_PATTERN} is correct. 178 */ 179 @Test 180 public void testJsonPattern() { 181 testJson("Tile does not exist", 182 "{\"message\":\"Tile does not exist\"}"); 183 } 184 176 185 private static void testServiceException(String expected, String xml) { 177 186 test(TMSCachedTileLoaderJob.SERVICE_EXCEPTION_PATTERN, expected, xml); … … 182 191 } 183 192 184 private static void test(Pattern pattern, String expected, String xml) { 185 Matcher m = pattern.matcher(xml); 186 assertTrue(xml, m.matches()); 193 private static void testJson(String expected, String json) { 194 test(TMSCachedTileLoaderJob.JSON_PATTERN, expected, json); 195 } 196 197 private static void test(Pattern pattern, String expected, String text) { 198 Matcher m = pattern.matcher(text); 199 assertTrue(text, m.matches()); 187 200 assertEquals(expected, Utils.strip(m.group(1))); 188 201 }
Note:
See TracChangeset
for help on using the changeset viewer.