Over a million developers have joined DZone.

Taglib For Rss V 0.1

·
// jsp taglibrary for rss


// the java code
package com.ranjan.feedreader;

/**
 * Created by IntelliJ IDEA.
 * User: Rapid
 * Date: Oct 9, 2006
 * Time: 3:18:23 PM
 * To change this template use File | Settings | File Templates.
 */
import java.net.URL;
import java.util.Iterator;
import java.util.HashMap;

import com.sun.syndication.feed.module.Module;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
import javax.servlet.jsp.JspContext;

import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspException;

/* this tag should return the RSS feed as it is 
 *it's purpose is to retrieve rss feeds 
 *
 */

public class FeedReader extends TagSupport{

    private String url = null;

    

    
    
    SyndFeedInput input ;
    URL feedUrl;
    SyndFeed feed ;
    String html ;
    

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    
    public int doStartTag() throws JspException {

        return EVAL_BODY_INCLUDE;    //To change body of overridden methods use File | Settings | File Templates.
    }

    public int doEndTag() throws JspException {




            try  {

    

                feedUrl  = new URL(url);

                input  = new SyndFeedInput();
                
                feed = input.build(new XmlReader(feedUrl));
/*
                String metaRSS = "Title: " + feed.getTitle() + "\n" +
                "Author: " + feed.getAuthor()  + "\n" +
                 "Description: " + feed.getDescription()  + "\n" +
                 "Pub date: " + feed.getPublishedDate()  + "\n" +
                 "Copyright: " + feed.getCopyright() ;

                 pageContext.getOut().write( metaRSS );
*/
               
                  html =       

                        "" +
                        "" +
                            "" + 
                        "" +
                            "" +
                            "" + 
                        "" +
                         "" +
                            "" + 
                        "" +
                        
                                        
                        "" +
                            "
" + feed.getTitle() + "
" + feed.getDescription() + "
" + feed.getCopyright() + "
" ; for( Iterator iter = feed.getEntries().iterator(); iter.hasNext(); ){ html += "" + "" + "" ; //((SyndEntry)iter.next()).getLink().toString() } html += "
" + ((SyndEntry)iter.next()).getTitle() + "" + "
" + "" + "" ; pageContext.getOut().write( html ); } catch (Exception ex) { ex.printStackTrace(); System.out.println("ERROR: " + ex.getMessage()); } return EVAL_PAGE; //To change body of overridden methods use File | Settings | File Templates. } } ////////////////////////////////////////////////// // the tld file ////////////////////////////////////////////////// 1.0 rss /WEB-INF/tlds/rss rss com.ranjan.feedreader.FeedReader empty url true false
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}