Class GoogleCodeSitemapGenerator

    • Field Detail

      • MAX_URLS_PER_SITEMAP

        public static final int MAX_URLS_PER_SITEMAP
        50000 URLs per sitemap maximum
        See Also:
        Constant Field Values
    • Constructor Detail

      • GoogleCodeSitemapGenerator

        public GoogleCodeSitemapGenerator(String baseUrl,
                                          File baseDir)
                                   throws MalformedURLException
        Configures the generator with a base URL and directory to write the sitemap files.
        Parameters:
        baseUrl - All URLs in the generated sitemap(s) should appear under this base URL
        baseDir - Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
        Throws:
        MalformedURLException -
      • GoogleCodeSitemapGenerator

        public GoogleCodeSitemapGenerator(URL baseUrl,
                                          File baseDir)
        Configures the generator with a base URL and directory to write the sitemap files.
        Parameters:
        baseUrl - All URLs in the generated sitemap(s) should appear under this base URL
        baseDir - Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
      • GoogleCodeSitemapGenerator

        public GoogleCodeSitemapGenerator(String baseUrl)
                                   throws MalformedURLException
        Configures the generator with a base URL and a null directory. The object constructed is not intended to be used to write to files. Rather, it is intended to be used to obtain XML-formatted strings that represent sitemaps.
        Parameters:
        baseUrl - All URLs in the generated sitemap(s) should appear under this base URL
        Throws:
        MalformedURLException
      • GoogleCodeSitemapGenerator

        public GoogleCodeSitemapGenerator(URL baseUrl)
        Configures the generator with a base URL and a null directory. The object constructed is not intended to be used to write to files. Rather, it is intended to be used to obtain XML-formatted strings that represent sitemaps.
        Parameters:
        baseUrl - All URLs in the generated sitemap(s) should appear under this base URL
    • Method Detail

      • builder

        public static SitemapGeneratorBuilder<GoogleCodeSitemapGenerator> builder(URL baseUrl,
                                                                                  File baseDir)
        Configures a builder so you can specify sitemap generator options
        Parameters:
        baseUrl - All URLs in the generated sitemap(s) should appear under this base URL
        baseDir - Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
        Returns:
        a builder; call .build() on it to make a sitemap generator
      • builder

        public static SitemapGeneratorBuilder<GoogleCodeSitemapGenerator> builder(String baseUrl,
                                                                                  File baseDir)
                                                                           throws MalformedURLException
        Configures a builder so you can specify sitemap generator options
        Parameters:
        baseUrl - All URLs in the generated sitemap(s) should appear under this base URL
        baseDir - Sitemap files will be generated in this directory as either "sitemap.xml" or "sitemap1.xml" "sitemap2.xml" and so on.
        Returns:
        a builder; call .build() on it to make a sitemap generator
        Throws:
        MalformedURLException -
      • addUrl

        public THIS addUrl(U url)
        Add one URL of the appropriate type to this sitemap. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or else write out one sitemap immediately.
        Parameters:
        url - the URL to add to this sitemap
        Returns:
        this
      • addUrls

        public THIS addUrls(Iterable<? extends U> urls)
        Add multiple URLs of the appropriate type to this sitemap, one at a time. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or write out one sitemap immediately.
        Parameters:
        urls - the URLs to add to this sitemap
        Returns:
        this
      • addUrls

        public THIS addUrls(U... urls)
        Add multiple URLs of the appropriate type to this sitemap, one at a time. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or write out one sitemap immediately.
        Parameters:
        urls - the URLs to add to this sitemap
        Returns:
        this
      • addUrls

        public THIS addUrls(String... urls)
                     throws MalformedURLException
        Add multiple URLs of the appropriate type to this sitemap, one at a time. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or write out one sitemap immediately.
        Parameters:
        urls - the URLs to add to this sitemap
        Returns:
        this
        Throws:
        MalformedURLException -
      • addUrl

        public THIS addUrl(String url)
                    throws MalformedURLException
        Add one URL of the appropriate type to this sitemap. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or else write out one sitemap immediately.
        Parameters:
        url - the URL to add to this sitemap
        Returns:
        this
        Throws:
        MalformedURLException -
      • addUrls

        public THIS addUrls(URL... urls)
        Add multiple URLs of the appropriate type to this sitemap, one at a time. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or write out one sitemap immediately.
        Parameters:
        urls - the URLs to add to this sitemap
        Returns:
        this
      • addUrl

        public THIS addUrl(URL url)
        Add one URL of the appropriate type to this sitemap. If we have reached the maximum number of URLs, we'll throw an exception if allowMultipleSitemaps is false, or write out one sitemap immediately.
        Parameters:
        url - the URL to add to this sitemap
        Returns:
        this
      • write

        public List<File> write()
        Write out remaining URLs; this method can only be called once. This is necessary so we can keep an accurate count for writeSitemapsWithIndex().
        Returns:
        a list of files we wrote out to disk
      • writeAsStrings

        public List<String> writeAsStrings()
        Writes out the sitemaps as a list of strings. Each string in the list is a formatted list of URLs. We return a list because the URLs may not all fit -- google specifies a maximum of 50,000 URLs in one sitemap.
        Returns:
        a list of XML-formatted strings
      • writeSitemapsWithIndex

        public void writeSitemapsWithIndex()
        After you've called write(), call this to generate a sitemap index of all sitemaps you generated.