| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>3.3 Using the Snaps taglibs</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="Virgo Snaps User Guide"><link rel="up" href="ch03.html" title="3. Using Virgo Snaps in your application"><link rel="prev" href="ch03s02.html" title="3.2 Configuring a Snap"><link rel="next" href="ch03s04.html" title="3.4 Referencing Resources"><!--Begin Google Analytics code--><script type="text/javascript"> |
| var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| </script><script type="text/javascript"> |
| var pageTracker = _gat._getTracker("UA-2728886-3"); |
| pageTracker._setDomainName("none"); |
| pageTracker._setAllowLinker(true); |
| pageTracker._trackPageview(); |
| </script><!--End Google Analytics code--></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.3 Using the Snaps taglibs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s02.html">Prev</a> </td><th width="60%" align="center">3. Using Virgo Snaps in your application</th><td width="20%" align="right"> <a accesskey="n" href="ch03s04.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="using-snaps-taglibs"></a>3.3 Using the Snaps taglibs</h2></div></div></div><p> |
| 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 <code class="code"><%@ taglib prefix="snaps" uri="http://www.eclipse.org/virgo/snaps" |
| %></code>. 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 <code class="literal">META-INF |
| </code> directory and have a name of <code class="literal">snap.properties</code>. The following code snippet shows all of these |
| in use to produce links to each of the installed snaps. |
| </p><pre class="programlisting"> |
| <snaps:snaps var="snaps"> |
| <c:forEach var="snap" items="${snaps}"> |
| <a href="<c:url value="${snap.contextPath}${snap.properties['link.path']}"/>"> |
| ${snap.properties['link.text']}</a> |
| </c:forEach> |
| </snaps:snaps> |
| </pre><p> |
| The first line uses the Snaps tag library to place the array of snaps into the <code class="code">snaps</code> variable. Then a |
| <code class="code">forEach</code> loop goes through each snap. The content of the <code class="code">forEach</code> loop is the really interesting |
| bit. The first variable <code class="code">${snap.contextPath}</code> returns the context path of the snap. The two lookups are for |
| properties <code class="code">${snap.properties['something']}</code>. They rely on the snap having the properties file in place with |
| <code class="literal">link.path</code> and <code class="literal">link.text</code> 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. |
| </p></div><!--Begin LoopFuse code--><script src="http://loopfuse.net/webrecorder/js/listen.js" type="text/javascript"></script><script type="text/javascript"> |
| _lf_cid = "LF_48be82fa"; |
| _lf_remora(); |
| </script><!--End LoopFuse code--><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.2 Configuring a Snap </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 3.4 Referencing Resources</td></tr></table></div></body></html> |