3.3 Using the Snaps taglibs

There is a tag library available that makes information about the Snaps environment available to the host from within a JSP page. The prefix and URI to declare are <%@ taglib prefix="snaps" uri="http://www.eclipse.org/virgo/snaps" %>. You can now access an array of all the Snaps currently registered with the host. Each snap in the array has two values, the first is the context path the Snap is registered with, as given in the snaps manifest header. The second is an array of properties, if any, given in a property file in the snap. The file must be in the META-INF directory and have a name of snap.properties. The following code snippet shows all of these in use to produce links to each of the installed snaps.

<snaps:snaps var="snaps">
    <c:forEach var="snap" items="${snaps}">
        <a href="<c:url value="${snap.contextPath}${snap.properties['link.path']}"/>">

The first line uses the Snaps tag library to place the array of snaps into the snaps variable. Then a forEach loop goes through each snap. The content of the forEach loop is the really interesting bit. The first variable ${snap.contextPath} returns the context path of the snap. The two lookups are for properties ${snap.properties['something']}. They rely on the snap having the properties file in place with link.path and link.text defined in it. This shows the flexibility you have for defining your own contract between the host and its snaps. In this case each snap can contribute extra information about how links in a menu should be constructed.