Custom JSP tags library lets you deal with YouTube API right in your JSP pages.
Tag YouTubeData lets you request YouTube RSS feed and proceed it in your JSP page. For example:
<%@ taglib uri="taglib.tld" prefix="y" %> <y:YouTubeData uri="http://gdata.youtube.com/feeds/api/standardfeeds/most_recent" id="A" /> here tag requests data feed from YouTube and saves the parsed data in the page scope. The structure for the feed url
is described here.
For example:
You can cache the requested data. Optional tag's attribute ttl describes a caching time in seconds. So all the subsequent requests (it is an application level cache) for the same url will be served right from cache. Now you can loop over the requested data and do some processing. Tag ForEachVide iterates over the requested data. On the each loop's step you can access to the page scope variable
described in the parameter video. This variable describes one entry in YouTube data feed.
The following code demonstrates access to the various attributes of video entries:
<y:ForEachVideo data="A" id="vb"> <p><b>Id: <%=vb.getId()%></b> <br>Published: <%=vb.getPublished()%> <br>Updated: <%=vb.getUpdated()%> <br>Recorded: <%=vb.getRecorded()%> <br>Location: <%=vb.getLocation()%> <br>Geo Data: <%=vb.getPoint().getLatitude()%> <%=vb.getPoint().getLongitude()%> <br>Author: <%=vb.getAuthor().getName()%> <%=vb.getAuthor().getUri()%> <br>Duration: <%=vb.getDuration()%> <br>Statistics: <%=vb.getStatistics()%> <br>Comments: <%=vb.getComment().getFeedLink()%> <%=vb.getComment().getCountHint()%> <br>Title: <%=vb.getTitle()%> <br>Content: <%=vb.getContent()%> <br>Rating: <%=vb.getRating().getMin()%> <%=vb.getRating().getMax()%> <%=vb.getRating().getNumRaters()%> <%=vb.getRating().getAverage()%> <br>Links: <% for (int j=0; j<vb.getLink().size(); j++) { com.cj.youtube.LinkBean lb = (com.cj.youtube.LinkBean)vb.getLink().elementAt(j); %> <br> <%=lb.getRel()%> <%=lb.getType()%> <%=lb.getHref()%> <% } %> <br>Categories: <% for (int k=0; k<vb.getCategory().size(); k++) { com.cj.youtube.CategoryBean cb = (com.cj.youtube.CategoryBean)vb.getCategory().elementAt(k); %> <br> <%=cb.getScheme()%> <%=cb.getLabel()%> <%=cb.getTerm()%> <%=cb.getValue()%> <% } %> <br>Player: <%=vb.getMedia().getPlayer()%> <br>Media title: <%=vb.getMedia().getTitle()%> <br>Media description: <%=vb.getMedia().getDescription()%> <br>Media keywords: <%=vb.getMedia().getKeywords()%> <br>Media Categories: <% for (int l=0; l<vb.getMedia().getCategory().size(); l++) { com.cj.youtube.CategoryBean cb = (com.cj.youtube.CategoryBean)vb.getMedia().getCategory().elementAt(l); %> <br> <%=cb.getScheme()%> <%=cb.getLabel()%> <%=cb.getTerm()%> <%=cb.getValue()%> <% } %> <br>Thumbnails: <% for (int m=0; m<vb.getMedia().getThumbnail().size(); m++) { com.cj.youtube.ThumbnailBean tb = (com.cj.youtube.ThumbnailBean)vb.getMedia().getThumbnail().elementAt(m); %> <br> <%=tb.getUrl()%> <%=tb.getWidth()%> <%=tb.getHeight()%> <%=tb.getTime()%> <% } %> <br>Media content: <% for (int n=0; n<vb.getMedia().getContent().size(); n++) { com.cj.youtube.ContentBean cb = (com.cj.youtube.ContentBean)vb.getMedia().getContent().elementAt(n); %> <br> <%=cb.getUrl()%> <%=cb.getType()%> <%=cb.getMedium()%> <%=cb.getIsDefault()%> <%=cb.getExpression()%> <%=cb.getDuration()%> <%=cb.getFormat()%> <% } %> </y:ForEachVideo> the code above just prints all the data from YouTube feed. You can use this as example and request by the similar manner the attributes you need in your application. The names for functions are mnemonically, so getPlayer() returns URL for the player, getTitle() returns title for the video etc. Tags are: YouTubeData Tag lets you request and parse YouTube data feed. Attributes are: 1) url Describes a data feed url
ForEachVideo Body tag evaluates own body for the each entry in the given YouTube data feed. Attributes are: 1) data Describes a name for page scope variable with the parsed data feed
getVideoId Body tag gets YouTube ID from a video URL, presented as tag's body. Attributes are: 1) id Optional attribute. Describes a name for your page scope variable (type is
java.lang.String). This object will keep the requested data. Without this attribute tag simply prints
the requested data.
for downloading: Library: youtubemashtag.jar Description: taglib.tld See also Coldtags suite - the largest collection of custom JSP tags. |
Also in Coldtags:
|