diff --git a/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapGenerator.java b/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapGenerator.java index 45b8c83..0e70f2a 100644 --- a/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapGenerator.java +++ b/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapGenerator.java @@ -31,7 +31,7 @@ public class GoogleLinkSitemapGenerator extends SitemapGenerator> entry : url.getAlternates().entrySet()) { + for (final Entry> entry : url.getAlternates().entrySet()) { tagSb.append(" innerEntry : entry.getValue().entrySet()){ diff --git a/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapUrl.java b/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapUrl.java index 11d6e2f..600f9a9 100644 --- a/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapUrl.java +++ b/src/main/java/com/redfin/sitemapgenerator/GoogleLinkSitemapUrl.java @@ -1,10 +1,11 @@ package com.redfin.sitemapgenerator; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; /** * One configurable Google Link URL. To configure, use {@link Options} @@ -18,14 +19,14 @@ public class GoogleLinkSitemapUrl extends WebSitemapUrl { /** Options to configure URLs with alternates */ public static class Options extends AbstractSitemapUrlOptions { - private final Map> alternates; + private final Map> alternates; - private static Map> convertAlternates(final Map> alternates) - throws MalformedURLException { + private static Map> convertAlternates(final Map> alternates) + throws URISyntaxException { - final Map> converted = new LinkedHashMap>(); - for (final String key : alternates.keySet()) { - converted.put(new URL(key), new LinkedHashMap(alternates.get(key))); + final Map> converted = new LinkedHashMap>(); + for (final Map.Entry> entry : alternates.entrySet()) { + converted.put(new URI(entry.getKey()), new LinkedHashMap(entry.getValue())); } return converted; } @@ -38,7 +39,7 @@ public class GoogleLinkSitemapUrl extends WebSitemapUrl { * the value is a generic Map<String, String> holding the attributes of * the link (e.g. hreflang, media, ...) */ - public Options(final String url, final Map> alternates) throws MalformedURLException { + public Options(final String url, final Map> alternates) throws URISyntaxException, MalformedURLException { this(new URL(url), convertAlternates(alternates)); } @@ -51,13 +52,13 @@ public class GoogleLinkSitemapUrl extends WebSitemapUrl { * the value is a generic Map<String, String> holding the attributes of * the link (e.g. hreflang, media, ...) */ - public Options(final URL url, final Map> alternates) { + public Options(final URL url, final Map> alternates) { super(url, GoogleLinkSitemapUrl.class); - this.alternates = new LinkedHashMap>(alternates); + this.alternates = new LinkedHashMap>(alternates); } } - private final Map> alternates; + private final Map> alternates; /** * Constructor specifying the URL and the alternates configurations with Options object @@ -78,7 +79,7 @@ public class GoogleLinkSitemapUrl extends WebSitemapUrl { * the value is a generic Map<String, String> holding the attributes of * the link (e.g. hreflang, media, ...) */ - public GoogleLinkSitemapUrl(final String url, final Map> alternates) throws MalformedURLException { + public GoogleLinkSitemapUrl(final String url, final Map> alternates) throws URISyntaxException, MalformedURLException { this(new Options(url, alternates)); } @@ -90,11 +91,11 @@ public class GoogleLinkSitemapUrl extends WebSitemapUrl { * the value is a generic Map<String, String> holding the attributes of * the link (e.g. hreflang, media, ...) */ - public GoogleLinkSitemapUrl(final URL url, final Map> alternates) { + public GoogleLinkSitemapUrl(final URL url, final Map> alternates) { this(new Options(url, alternates)); } - public Map> getAlternates() { + public Map> getAlternates() { return this.alternates; }