@Test public void testGetGraphicFormatDetect() { final List<String> strings = Arrays.asList(ImageIO.getReaderMIMETypes()); PJsonObject styleJson = new PJsonObject(new JSONObject(), "style"); for (String supportedMimetype: strings) { Set<String> compatibleMimetypes = findCompatibleMimeTypes(supportedMimetype); for (String mimeType: compatibleMimetypes) { if (StringUtils.isEmpty(mimeType)) { continue; } styleJson.getInternalObj().put(JsonStyleParserHelper.JSON_GRAPHIC_FORMAT, mimeType); final String graphicFormat = helper.getGraphicFormat( "http: assertTrue(graphicFormat + " is not supported", strings.contains(graphicFormat)); } } }
@VisibleForTesting String getGraphicFormat(final String externalGraphicFile, final PJsonObject styleJson) { String mimeType = null; if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_FORMAT))) { mimeType = styleJson.getString(JSON_GRAPHIC_FORMAT); } else { Matcher matcher = DATA_FORMAT_PATTERN.matcher(externalGraphicFile); if (matcher.find()) { mimeType = matcher.group(1); } if (mimeType == null) { int separatorPos = externalGraphicFile.lastIndexOf("."); if (separatorPos >= 0) { mimeType = "image/" + externalGraphicFile.substring(separatorPos + 1).toLowerCase(); } } if (mimeType == null) { try { URI uri; try { uri = new URI(externalGraphicFile); } catch (URISyntaxException e) { uri = new File(externalGraphicFile).toURI(); } ClientHttpResponse httpResponse = this.requestFactory.createRequest( uri, HEAD).execute(); List<String> contentTypes = httpResponse.getHeaders().get("Content-Type"); if (contentTypes != null && contentTypes.size() == 1) { String contentType = contentTypes.get(0); int index = contentType.lastIndexOf(";"); mimeType = index >= 0 ? contentType.substring(0, index) : contentType; } else { LOGGER.info("No content type found for: {}", externalGraphicFile); } } catch (IOException e) { throw new RuntimeException("Unable to get a mime type for the external graphic", e); } } } mimeType = toSupportedMimeType(mimeType); return mimeType; }
JsonStyleParserHelper { @VisibleForTesting String getGraphicFormat(final String externalGraphicFile, final PJsonObject styleJson) { String mimeType = null; if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_FORMAT))) { mimeType = styleJson.getString(JSON_GRAPHIC_FORMAT); } else { Matcher matcher = DATA_FORMAT_PATTERN.matcher(externalGraphicFile); if (matcher.find()) { mimeType = matcher.group(1); } if (mimeType == null) { int separatorPos = externalGraphicFile.lastIndexOf("."); if (separatorPos >= 0) { mimeType = "image/" + externalGraphicFile.substring(separatorPos + 1).toLowerCase(); } } if (mimeType == null) { try { URI uri; try { uri = new URI(externalGraphicFile); } catch (URISyntaxException e) { uri = new File(externalGraphicFile).toURI(); } ClientHttpResponse httpResponse = this.requestFactory.createRequest( uri, HEAD).execute(); List<String> contentTypes = httpResponse.getHeaders().get("Content-Type"); if (contentTypes != null && contentTypes.size() == 1) { String contentType = contentTypes.get(0); int index = contentType.lastIndexOf(";"); mimeType = index >= 0 ? contentType.substring(0, index) : contentType; } else { LOGGER.info("No content type found for: {}", externalGraphicFile); } } catch (IOException e) { throw new RuntimeException("Unable to get a mime type for the external graphic", e); } } } mimeType = toSupportedMimeType(mimeType); return mimeType; } }
JsonStyleParserHelper { @VisibleForTesting String getGraphicFormat(final String externalGraphicFile, final PJsonObject styleJson) { String mimeType = null; if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_FORMAT))) { mimeType = styleJson.getString(JSON_GRAPHIC_FORMAT); } else { Matcher matcher = DATA_FORMAT_PATTERN.matcher(externalGraphicFile); if (matcher.find()) { mimeType = matcher.group(1); } if (mimeType == null) { int separatorPos = externalGraphicFile.lastIndexOf("."); if (separatorPos >= 0) { mimeType = "image/" + externalGraphicFile.substring(separatorPos + 1).toLowerCase(); } } if (mimeType == null) { try { URI uri; try { uri = new URI(externalGraphicFile); } catch (URISyntaxException e) { uri = new File(externalGraphicFile).toURI(); } ClientHttpResponse httpResponse = this.requestFactory.createRequest( uri, HEAD).execute(); List<String> contentTypes = httpResponse.getHeaders().get("Content-Type"); if (contentTypes != null && contentTypes.size() == 1) { String contentType = contentTypes.get(0); int index = contentType.lastIndexOf(";"); mimeType = index >= 0 ? contentType.substring(0, index) : contentType; } else { LOGGER.info("No content type found for: {}", externalGraphicFile); } } catch (IOException e) { throw new RuntimeException("Unable to get a mime type for the external graphic", e); } } } mimeType = toSupportedMimeType(mimeType); return mimeType; } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); }
JsonStyleParserHelper { @VisibleForTesting String getGraphicFormat(final String externalGraphicFile, final PJsonObject styleJson) { String mimeType = null; if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_FORMAT))) { mimeType = styleJson.getString(JSON_GRAPHIC_FORMAT); } else { Matcher matcher = DATA_FORMAT_PATTERN.matcher(externalGraphicFile); if (matcher.find()) { mimeType = matcher.group(1); } if (mimeType == null) { int separatorPos = externalGraphicFile.lastIndexOf("."); if (separatorPos >= 0) { mimeType = "image/" + externalGraphicFile.substring(separatorPos + 1).toLowerCase(); } } if (mimeType == null) { try { URI uri; try { uri = new URI(externalGraphicFile); } catch (URISyntaxException e) { uri = new File(externalGraphicFile).toURI(); } ClientHttpResponse httpResponse = this.requestFactory.createRequest( uri, HEAD).execute(); List<String> contentTypes = httpResponse.getHeaders().get("Content-Type"); if (contentTypes != null && contentTypes.size() == 1) { String contentType = contentTypes.get(0); int index = contentType.lastIndexOf(";"); mimeType = index >= 0 ? contentType.substring(0, index) : contentType; } else { LOGGER.info("No content type found for: {}", externalGraphicFile); } } catch (IOException e) { throw new RuntimeException("Unable to get a mime type for the external graphic", e); } } } mimeType = toSupportedMimeType(mimeType); return mimeType; } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); Style createStyle(final List<Rule> styleRules); @Nullable PointSymbolizer createPointSymbolizer(final PJsonObject styleJson); }
JsonStyleParserHelper { @VisibleForTesting String getGraphicFormat(final String externalGraphicFile, final PJsonObject styleJson) { String mimeType = null; if (!StringUtils.isEmpty(styleJson.optString(JSON_GRAPHIC_FORMAT))) { mimeType = styleJson.getString(JSON_GRAPHIC_FORMAT); } else { Matcher matcher = DATA_FORMAT_PATTERN.matcher(externalGraphicFile); if (matcher.find()) { mimeType = matcher.group(1); } if (mimeType == null) { int separatorPos = externalGraphicFile.lastIndexOf("."); if (separatorPos >= 0) { mimeType = "image/" + externalGraphicFile.substring(separatorPos + 1).toLowerCase(); } } if (mimeType == null) { try { URI uri; try { uri = new URI(externalGraphicFile); } catch (URISyntaxException e) { uri = new File(externalGraphicFile).toURI(); } ClientHttpResponse httpResponse = this.requestFactory.createRequest( uri, HEAD).execute(); List<String> contentTypes = httpResponse.getHeaders().get("Content-Type"); if (contentTypes != null && contentTypes.size() == 1) { String contentType = contentTypes.get(0); int index = contentType.lastIndexOf(";"); mimeType = index >= 0 ? contentType.substring(0, index) : contentType; } else { LOGGER.info("No content type found for: {}", externalGraphicFile); } } catch (IOException e) { throw new RuntimeException("Unable to get a mime type for the external graphic", e); } } } mimeType = toSupportedMimeType(mimeType); return mimeType; } JsonStyleParserHelper(
            @Nullable final Configuration configuration,
            @Nonnull final ClientHttpRequestFactory requestFactory,
            @Nonnull final StyleBuilder styleBuilder,
            final boolean allowNullSymbolizer); Style createStyle(final List<Rule> styleRules); @Nullable PointSymbolizer createPointSymbolizer(final PJsonObject styleJson);  }