ROMEがRSSクラスを更新するのは何が更に最適化することができる地方が更新するのがまだ少し遅いことを発見します

2404 ワード

package org.zjut.romefunction;

/**
 * this class is update the news;
 * @author xuhaimin
 * 
 */

import java.util.Date;
import java.util.Iterator;
import org.zjut.DAOFactory.DAOFactory;
import org.zjut.PO.Feed;
import org.zjut.PO.Item;
import org.zjut.PO.Rss;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;

public class UpdateItems {

	public void perform(Rss rss) {
		System.out.println(rss.getId());

		SyndFeed syndfeed = new ParseRss().getSyndFeed(rss);

		String title = syndfeed.getTitle();
		Feed feed = DAOFactory.getIntance().createFeedDAO().getFeedByTitle(
				title);
		Date maxdate = getMaxDate(title);
		Iterator intor = syndfeed.getEntries().iterator();
		while (intor.hasNext()) {
			SyndEntry synden = (SyndEntry) intor.next();
			Date date = synden.getPublishedDate();
			if (date == null)
				continue;
			if (date.after(maxdate)) {
				System.err.println(" " + feed.getTitle() + "  "
						+ maxdate);
				System.err.println(" rss  " + date);

				/**
				 *    
				 */
				Item item = new Item();
				item.setTitle(synden.getTitle());
				String description=synden.getDescription().getValue().replaceAll("<[.[^<]]*>","");
				if(description==null||description.equals(""))
					item.setDescription(" , ");
				item.setDescription(description);
				item.setAuthor(synden.getAuthor());
				item.setSource("");
				item.setPubDate(synden.getPublishedDate());
				item.setLink(synden.getLink());
				item.setFeed(feed);

				System.err.println("@  " + feed.getTitle()
						+ " ..........................................");
				DAOFactory.getIntance().createItemDAO().saveItem(item);
			} else {
				break;
			}
		}
	}

	public Date getMaxDate(String title) {
		Feed feed = DAOFactory.getIntance().createFeedDAO().getFeedByTitle(
				title);
		Long feedid = feed.getId();
		Date date = org.zjut.HibernateUtil.Util.maxDate(feedid);
		return date;
	}

}