Coverage Report - org.mule.example.launcher.rss.EntryReceiver
 
Classes in this File Line Coverage Branch Coverage Complexity
EntryReceiver
0%
0/29
0%
0/14
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.example.launcher.rss;
 8  
 
 9  
 import java.util.Iterator;
 10  
 import java.util.List;
 11  
 
 12  
 import net.htmlparser.jericho.Element;
 13  
 import net.htmlparser.jericho.HTMLElementName;
 14  
 import net.htmlparser.jericho.Source;
 15  
 import net.htmlparser.jericho.TagType;
 16  
 
 17  
 import org.apache.commons.lang.StringEscapeUtils;
 18  
 import org.mule.api.annotations.param.Payload;
 19  
 
 20  
 import com.sun.syndication.feed.synd.SyndEnclosure;
 21  
 import com.sun.syndication.feed.synd.SyndEntry;
 22  
 import com.sun.syndication.feed.synd.SyndFeed;
 23  
 
 24  
 public class EntryReceiver
 25  
 {
 26  
     /**
 27  
          * 
 28  
          */
 29  
     public EntryReceiver()
 30  0
     {
 31  0
     }
 32  
 
 33  
     @SuppressWarnings("rawtypes")
 34  
     public String processFeed(@Payload SyndFeed feed) throws Exception
 35  
     {
 36  0
         StringBuilder feedXml = new StringBuilder();
 37  0
         feedXml.append("<muleforge-extensions>");
 38  
 
 39  0
         for (Iterator it = feed.getEntries().iterator(); it.hasNext();)
 40  
         {
 41  0
             SyndEntry entry = (SyndEntry) it.next();
 42  0
             processItem(feedXml, entry);
 43  0
         }
 44  0
         feedXml.append("</muleforge-extensions>");
 45  
 
 46  0
         return feedXml.toString();
 47  
     }
 48  
 
 49  
     private void processItem(StringBuilder feedXml, SyndEntry entry)
 50  
     {
 51  0
         feedXml.append("<muleforge-extension>");
 52  0
         feedXml.append("<title>" + StringEscapeUtils.escapeXml(entry.getTitle()) + "</title>");
 53  0
         feedXml.append("<link>" + StringEscapeUtils.escapeXml(entry.getLink()) + "</link>");
 54  0
         if (!entry.getEnclosures().isEmpty())
 55  
         {
 56  0
             feedXml.append("<image-url>"
 57  
                            + StringEscapeUtils.escapeXml(((SyndEnclosure) entry.getEnclosures().get(0)).getUrl())
 58  
                            + "</image-url>");
 59  
         }
 60  0
         parseDescription(feedXml, entry);
 61  0
         feedXml.append("</muleforge-extension>");
 62  0
     }
 63  
 
 64  
     private void parseDescription(StringBuilder feedXml, SyndEntry entry)
 65  
     {
 66  0
         Source source = new Source(entry.getDescription().getValue());
 67  
 
 68  0
         List<Element> anchors = source.getAllElements(HTMLElementName.A);
 69  0
         if (anchors != null)
 70  
         {
 71  0
             for (Element a : anchors)
 72  
             {
 73  0
                 if ("documentation-url".equalsIgnoreCase(a.getAttributeValue("id")))
 74  
                 {
 75  0
                     feedXml.append("<documentation-url>"
 76  
                                    + StringEscapeUtils.escapeXml(a.getAttributeValue("href"))
 77  
                                    + "</documentation-url>");
 78  
                 }
 79  0
                 else if ("source-url".equalsIgnoreCase(a.getAttributeValue("id")))
 80  
                 {
 81  0
                     feedXml.append("<source-url>" + StringEscapeUtils.escapeXml(a.getAttributeValue("href"))
 82  
                                    + "</source-url>");
 83  
                 }
 84  0
                 else if ("download-url".equalsIgnoreCase(a.getAttributeValue("id")))
 85  
                 {
 86  0
                     feedXml.append("<download-url>"
 87  
                                    + StringEscapeUtils.escapeXml(a.getAttributeValue("href"))
 88  
                                    + "</download-url>");
 89  
                 }
 90  
             }
 91  
         }
 92  
 
 93  0
     }
 94  
 }