/*
* Copyright Massimiliano Dessi' (desmax74@yahoo.it)
*
* Licensed under Apache License Version 2.0
* (http://www.apache.org/licenses/LICENSE-2.0),
*
* for commercial use, under
* GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*/
package org.magicbox.service;
import java.text.ParseException;
import java.util.List;
import javolution.util.FastList;
import org.magicbox.domain.Annuncio;
import org.magicbox.util.Constant;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
/**
* Implementazione interfaccia di richiesta feeds di un determinato tipo
*
* @author Massimiliano Dessi' (desmax74@yahoo.it)
* @since jdk 1.6.0
* @version 3.0
*/
public class FeedServiceImpl implements FeedService {
public SyndFeed getFeed(String feedType) throws ParseException {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(feedType);
feed.setTitle(title);
feed.setLink(link);
feed.setDescription(description);
feed.setEntries(getEntries());
return feed;
}
public void setAnnunciService(AnnunciService annunciService) {
this.annunciService = annunciService;
}
public void setDescription(String description) {
this.description = description;
}
public void setTitle(String title) {
this.title = title;
}
public void setLink(String link) {
this.link = link;
}
@SuppressWarnings("unchecked")
private List getEntries() throws ParseException {
List entries = new FastList();
List<Annuncio> annunci = annunciService.getAnnunci(Constant.TYPE_FEED);
SyndEntry entry;
SyndContent description;
for (Annuncio annuncio : annunci) {
entry = new SyndEntryImpl();
entry.setTitle(annuncio.getTitolo());
// entry.setLink("http://www.jroller.com/page/desmax");
entry.setPublishedDate(annuncio.getData());
description = new SyndContentImpl();
description.setType(Constant.FEED_TEXT);
description.setValue(annuncio.getContenuto());
entry.setDescription(description);
entries.add(entry);
}
return entries;
}
private AnnunciService annunciService;
private String title;
private String description;
private String link;
}