[GIS] Get the list of layers in a store from geoserver

geoserveropenlayers-2

Is there a way to get the all the layers present in a store in geoserver?

My JS file contains code for each layer present in a store. So when I publish a new layer in geoserver I have to manually include the code of the new layer in JS. But what I want is to put a for loop in JS with the layer names present in a store, like

for(i<=all layers present in store)                 
{
   var wmslayer2 = new OpenLayers.Layer.WMS("Layer2","http://localhost:8080/geoserver/wms", 
   {'layers': '**cite:layer[i]**', 'format':'image/png', 'transparent':'true'},
   {'opacity': 1.0, 'isBaseLayer': false, 'visibility': true}); 
}

Best Answer

The restconfig api allows you to do this:

http://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html

You can request data be sent back in JSON as well which is handy from javascript code. The WMS caps has the same info but it is a huge xml document... so expensive to parse on the client side.