• spring使用rssfeed


    spring使用rssfeed

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import mypackage.rss.view.RssFeedView;
    
    /**
     * 栏目稿件RSS订阅请求控制器类。
     *
     */
    @Controller
    @RequestMapping({"/rss/c/{columnId}"})
    public class ColumnStoriesRssController {
    
        @RequestMapping("")
        public ModelAndView feed() {
            ModelAndView modelAndView = new ModelAndView();
            // TODO 从本地缓存获取稿件数据
    
            modelAndView.addObject(RssFeedView.ITEMS_KEY, null);
            modelAndView.setView(new RssFeedView());
            return modelAndView;
        }
    }

     RSS Feed 视图类

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.jdom2.Element;
    import org.springframework.web.servlet.view.feed.AbstractRssFeedView;
    
    import mypackage.domain.model.NrCompoStory;
    import mypackage.domain.model.NrGalleryStory;
    import mypackage.domain.model.NrStory;
    import mypackage.domain.model.NrVideoStory;
    import mypackage.framework.infras.exception.UnexpectedException;
    import com.rometools.rome.feed.rss.Channel;
    import com.rometools.rome.feed.rss.Item;
    
    /**
     * RSS Feed 视图类。
     *
     */
    public class RssFeedView extends AbstractRssFeedView {
    
        /**
         * RSS稿件列表KEY
         */
        public static final String ITEMS_KEY = "RSS_ITEMS";
    
        /**
         * {@inheritDoc}
         */
        @Override
        protected Channel newFeed() {
            Channel channel = new Channel("rss_2.0");
            channel.setTitle("${title}");
            channel.setLink("${link}");
            channel.setEncoding("UTF-8");
            channel.setDescription("${description}");
            return channel;
        }
    
        /**
         * {@inheritDoc}
         */
        @Override
        protected List<Item> buildFeedItems(Map<String, Object> model,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
            @SuppressWarnings("unchecked")
            List<NrStory> stories = (List<NrStory>)model.get(ITEMS_KEY);
            List<Item> result = new ArrayList<Item>();
            if (stories != null) {
                for (NrStory story : stories) {
                    result.add(createItem(story));
                }
            }
    
            return result;
        }
    
        /**
         * 通过稿件创建RSS Item
         *
         * @param story 稿件
         * @return RSS Item
         */
        private Item createItem(NrStory story) {
            Item result = null;
            if (story instanceof NrCompoStory) {
                result = createCompoItem((NrCompoStory)story);
            } else if (story instanceof NrGalleryStory) {
                result = createGalleryItem((NrGalleryStory)story);
            } else if (story instanceof NrVideoStory) {
                result = createVideoItem((NrVideoStory)story);
            } else {
                throw new UnexpectedException("unknow story type.(" + story.getClass().getName() + ")");
            }
    
            return result;
        }
    
        /**
         * 通过图文稿件创建RSS Item
         *
         * @param story 稿件
         * @return RSS Item
         */
        private Item createCompoItem(NrCompoStory story) {
            Item result = new Item();
            result.setTitle("");
            result.setLink("");
            result.setDescription(null);
            result.setPubDate(null);
            Element element = null;
    
    
    //        <videoItems>
    //        <videoItem>
    //        (see detail in next page)
    //        </videoItem>
    //        …...
    //        </videoItems>
            result.setForeignMarkup(Arrays.asList(element));
    
            return result;
        }
    
        /**
         * 通过图集稿件创建RSS Item
         *
         * @param story 稿件
         * @return RSS Item
         */
        private Item createGalleryItem(NrGalleryStory story) {
    
    
            return null;
        }
    
        /**
         * 通过视频稿件创建RSS Item
         *
         * @param story 稿件
         * @return RSS Item
         */
        private Item createVideoItem(NrVideoStory story) {
    
    
            return null;
        }
    }
  • 相关阅读:
    mysql备份
    Linux 配置参考
    oracle补丁安装
    多智能体城市交通计算综合应用
    基于纳什均衡的多智能体强化学习交通信号控制
    多智能体强化学习在城市交通信号控制中的研究与应用- 笔记
    Sarsa与Q-learning
    Pandas笔记
    Python学习笔记
    Game Theory and Multi-agent Reinforcement Learning笔记 下
  • 原文地址:https://www.cnblogs.com/zhao1949/p/6931841.html
Copyright © 2020-2023  润新知