Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jollyday API - How do I create a HolidayManager instance from a URL?

Tags:

java

Quick Introduction:
For those who don't know; Jollyday is an API to help you handle holiday-aware code. It allows you to retrieve public holidays from pre-built configurations. You can even create your own Holiday Configuration in an XML file and load it into the API, which is exactly what I'm trying to do.


I have created my own holiday configuration in an XML file and I want to load it into Jollyday.

The Official Jollyday Documentation (for version 0.5.1) shows an example of this being done with the following code...

URL url = new URL("file:some/path/MyHolidays.xml");
HolidayManager m = HolidayManager.getInstance(url);

The Problem

When I try to use this code, it will not compile because the HolidayManager class does not have a getInstance(URL) method.

Here is a screenshot of all the overloaded variations of HolidayManager.getInstance() (as seen from IntelliJ IDEA).

Screenshot of intelliJ showing all of the HolidayManager.getInstance method variations

The documentation appears to be incorrect.

Further Information

"Are you using the correct version of the API?"

Yes, I am using version 0.5.1 which I downloaded with gradle. This is the same version as was used in the documentation.

The Question

Is it possible to create a HolidayManager instance using a URL?
If so, how is it done?

like image 522
byxor Avatar asked Sep 06 '25 03:09

byxor


1 Answers

Is it possible to create a HolidayManager instance using a URL?

  • Yes, but the URL has to be wrapped in a ManagerParameter first.

The documentation appears to be incorrect.

  • The documentation became slightly outdated when the code migrated from SourceForge to GitHub in late 2011.

  • If you look at the GitHub Commit History of HolidayManager, you can see that the HolidayManager.getInstance(URL) method was removed in this commit.

Working Example

URL url = new URL("file:some/path/MyHolidays.xml");
UrlManagerParameter urlManParam = new UrlManagerParameter(url, new Properties());
HolidayManager holidayManager = HolidayManager.getInstance(urlManParam);

This will work exactly as you expected, it just takes a few extra lines. You should use nicer variable names too, I just wanted to keep it short.

Don't forget to import the following classes:

import de.jollyday.HolidayManager;
import de.jollyday.parameter.UrlManagerParameter;
import java.net.URL;
import java.util.Properties;

You can now load Custom Holiday Configurations into Jollyday. Enjoy!

like image 155
byxor Avatar answered Sep 07 '25 22:09

byxor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!