Package com.netflix.recipes.rss.impl

Examples of com.netflix.recipes.rss.impl.RSSImpl


    /**
     * Parses the RSS feeds and return back a POJO
     */
    private RSS parseRSS(String url, String rss) {
        // Error case
        if (rss == null) return new RSSImpl();
       
        RSS rssItems = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder db = dbf.newDocumentBuilder();
            try {
                InputSource is = new InputSource(new StringReader(rss));
                Document dom = db.parse(is);
                Element docEle = dom.getDocumentElement();
               
                List<RSSItem> items = new ArrayList<RSSItem>();
                String title = docEle.getElementsByTagName("title").item(0).getTextContent();
                NodeList nl  = docEle.getElementsByTagName("item");
                if (nl != null && nl.getLength() > 0) {
                    for (int i = 0 ; i < nl.getLength(); i++) {
                        Element el = (Element) nl.item(i);
                        items.add(new RSSItemImpl(el.getElementsByTagName("title").item(0).getTextContent(), el.getElementsByTagName("link").item(0).getTextContent(), el.getElementsByTagName("description").item(0).getTextContent()));
                    }
                }
                rssItems = new RSSImpl(url, title, items);
               
            } catch (SAXException e) {
                logger.error("Exception occurred during parsing the RSS feed", e);
            } catch (IOException e) {
                logger.error("Exception occurred during fetching the RSS feed", e);
            }
        } catch (ParserConfigurationException e) {
            logger.error("Exception occurred during parsing the RSS feed", e);
        }

        if (rssItems == null) {
            rssItems = new RSSImpl();
        }
        return rssItems;
    }
View Full Code Here

TOP

Related Classes of com.netflix.recipes.rss.impl.RSSImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.