BiscoWeb / sitemapgen4j

Automatically exported from code.google.com/p/sitemapgen4j
0 stars 0 forks source link

wsg.writeSitemapsWithIndex() #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This may not be a bug/issue/problem. 

I sought to generate a site map-with-index per the example in the documentation

Example code from documentation:
WebSitemapGenerator wsg = new WebSitemapGenerator("http://www.example.com", 
myDir);
for (int i = 0; i < 60000; i++) 
wsg.addUrl("http://www.example.com/doc"+i+".html");
wsg.write();
wsg.writeSitemapsWithIndex(); // generate the sitemap_index.xml

What steps will reproduce the problem?
1. Instantiate WebSiteMapGenerator
2. add urls
3. call wsg.write()
4. call wsg.writeSiteMapWithIndex()

Expected Result
===================
Code generates sitemap.xml and site map index xml file.

Actual Results
=====================

Exception while exeecuting task 'Generate Site Map' (999) 
java.lang.RuntimeException: No URLs added, sitemap index would be empty; you 
must add some URLs with addUrls

Issue: 
-I don't see a place where the api requires/allows you to 'add a url' between 
the write() and the wsg.writeSitemapsWithIndex();

-I have a very small data set: one url. This does not seem relevant to the 
problem.

Version
===========
Version 1.0.1

Appendix A. Code
=====================

         WebSitemapGenerator wsg = new WebSitemapGenerator(BASE_URL, myDir);

         for (Post post : posts)
         {
            ChangeFreq changeFreq = ChangeFreq.HOURLY;
            WebSitemapUrl url = new WebSitemapUrl.Options(BASE_URL + ELEMENT_URL + post.getID())
                    .lastMod(post.getThreadActivityDate())
                    .priority(1.0)
                    .changeFreq(changeFreq).build();

            wsg.addUrl(url);

         }
         wsg.write();
         wsg.writeSitemapsWithIndex();

Original issue reported on code.google.com by milbr...@gmail.com on 13 Jul 2010 at 12:46

GoogleCodeExporter commented 9 years ago
A follow-up:

I believe the error occurs in the following situation:
a) Use the default constructor:
WebSitemapGenerator wsg = new WebSitemapGenerator(BASE_URL, myDir);

b) number total urls  < maxUrls per file (e.g. 6 vs. 50000)

I worked around the situation by doing the following:
* using the 'builder' method for constructing SiteMapGenerator options.
* specify a low value for the 'maxUrls' (e.g. 2)

Result:
The Library generated correctly site map and site map index xml files .

Original comment by milbr...@gmail.com on 13 Jul 2010 at 8:17

GoogleCodeExporter commented 9 years ago
Me too!
I found the max value for  'maxUrls' is 231.

Original comment by azure.i....@gmail.com on 16 Feb 2011 at 9:10

GoogleCodeExporter commented 9 years ago
I will say it is a bug as nothing says that it can't exist a sitemapIndex if 
only one sitemap file has been generated.
As a fix, I propose the following patch.

Original comment by stephane...@gmail.com on 6 May 2011 at 3:40

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
how to apply patch 

Original comment by ankur.bh...@gmail.com on 30 Jul 2014 at 1:01

GoogleCodeExporter commented 9 years ago
This has been fixed in sitemapgen4j v1.0.2 (now hostet on github: 
https://github.com/dfabulich/sitemapgen4j)

Original comment by m.k...@irregular.at on 20 Mar 2015 at 10:00