Putting a legend in my map


I can find a legend for each zoom at OSM-Server at the right side (http://www.openstreetmap.org).

Now I want to integrate this legend in my application (for information: using JMapViever).

Where can I find this legend for using local?
What is the best to integrate?

Thx in advance!!

You can try to dig into the website source code of osm.org


Please pay attention to any (free) licence that is used for that sourcecode.