1 2 package org.tigris.scarab.feeds; 3 4 import java.io.IOException ; 5 import java.text.DateFormat ; 6 import java.text.SimpleDateFormat ; 7 import java.util.ArrayList ; 8 import java.util.Date ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 12 import org.apache.torque.TorqueException; 13 import org.tigris.scarab.om.Activity; 14 import org.tigris.scarab.om.ActivitySet; 15 import org.tigris.scarab.om.Issue; 16 import org.tigris.scarab.tools.ScarabToolManager; 17 import org.tigris.scarab.util.ScarabLink; 18 19 import com.sun.syndication.feed.synd.SyndContent; 20 import com.sun.syndication.feed.synd.SyndContentImpl; 21 import com.sun.syndication.feed.synd.SyndEntry; 22 import com.sun.syndication.feed.synd.SyndEntryImpl; 23 import com.sun.syndication.feed.synd.SyndFeed; 24 import com.sun.syndication.feed.synd.SyndFeedImpl; 25 import com.sun.syndication.io.FeedException; 26 27 34 public class IssueFeed implements Feed{ 35 36 private Issue issue; 37 38 private ScarabLink scarabLink; 39 private ScarabToolManager scarabToolManager; 40 41 public IssueFeed(Issue issue,ScarabLink scarabLink,ScarabToolManager scarabToolManager) { 42 this.issue = issue; 43 this.scarabLink = scarabLink; 44 this.scarabToolManager = scarabToolManager; 45 } 46 47 public SyndFeed getFeed() throws IOException , FeedException, TorqueException, Exception { 48 49 SyndFeed feed = new SyndFeedImpl(); 50 51 String title = issue.getUniqueId() + ": " + issue.getDefaultText(); 52 feed.setTitle(title); 53 String link = scarabLink.getIssueIdAbsoluteLink(issue).toString(); 54 feed.setLink(link); 55 feed.setDescription(title); 56 57 List entries = new ArrayList (); 58 List allActivities = issue.getActivity(true); 59 60 61 for (Iterator i = allActivities.iterator(); i.hasNext();) { 62 SyndEntry entry; 63 SyndContent description; 64 65 Activity activity = (Activity)i.next(); 66 67 ActivitySet activitySet = activity.getActivitySet(); 68 Date date =activitySet.getCreatedDate(); 69 entry = new SyndEntryImpl(); 70 71 entry.setPublishedDate(date); 72 73 description = new SyndContentImpl(); 74 description.setType("text/html"); 75 76 StringBuffer desc = new StringBuffer (); 77 String activityDesc=activity.getDescription(); 78 desc.append("<b>Description:</b>" + activityDesc +"<br/>"); 79 desc.append("<b>Reason:</b>" + scarabToolManager.getActivityReason(activitySet,activity) +"<br/>"); 80 81 description.setValue(desc.toString()); 82 83 String entryTitle = createEntryTitle(activity); 84 entry.setTitle(entryTitle); 85 86 entry.setDescription(description); 87 88 entry.setLink(link+"?id="+entry.hashCode()); 91 92 entries.add(entry); 93 } 94 95 96 feed.setEntries(entries); 97 98 return feed; 99 } 100 101 107 private String createEntryTitle(Activity activity) { 108 String activityDesc=activity.getDescription(); 109 String entryTitle=null; 110 int maxTitleLength=64; 111 int activityLength=activityDesc.length(); 112 entryTitle=activityDesc.substring(0,(activityLength>=maxTitleLength)?maxTitleLength:activityLength); 113 return entryTitle; 114 } 115 116 } | Popular Tags |