<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java Source

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
    該組件實現分為以下幾個部分ChannelEItem,ChannelItem,RssBuildFactory,RssComponentBean
    /*
     * ChannelEItem.java
     * Copyright (C) 2009  <JustinLei@gmail.com>
     *
     *        This program is free software; you can redistribute it and/or modify
     *        it under the terms of the GNU General Public License as published by
     *      the Free Software Foundation; either version 2 of the License, or
     *     (at your option) any later version.
     *
     *       This program is distributed in the hope that it will be useful,
     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *        GNU General Public License for more details.
     *
     
    */
    package org.lambdasoft.components.rss.ejb;

    /**
     * 
    @author lei.tang (justinlei@gmail.com)
     * @date
     * 
    @version
     
    */
    public class ChannelEItem extends ChannelItem{
        
    private static final long serialVersionUID = 1L;
        
    private String enclosure;// 流媒體文件

        
    public String getEnclosure() {
            
    return enclosure;
        }

        
    public void setEnclosure(String enclosure) {
            
    this.enclosure = enclosure;
        }
    }

    /*
     * ChannelItem.java
     * Copyright (C) 2009  <JustinLei@gmail.com>
     *
     *        This program is free software; you can redistribute it and/or modify
     *        it under the terms of the GNU General Public License as published by
     *      the Free Software Foundation; either version 2 of the License, or
     *     (at your option) any later version.
     *
     *       This program is distributed in the hope that it will be useful,
     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *        GNU General Public License for more details.
     *
     
    */
    package org.lambdasoft.components.rss.ejb;

    import java.io.Serializable;
    import java.util.Date;

    /**
     * 
    @author lei.tang (justinlei@gmail.com)
     * @date
     * 
    @version
     
    */
    public class ChannelItem implements Serializable{
        
    private static final long serialVersionUID = 1L;
        
    private String title;// Rss文件中Item的標題
        private String link;// Rss文件中Item對應的連接
        private String description;// Item的描述
        private Date pubDate;// Item發布的時間
        private String author;// Item作者
        private String category;// Item所屬的頻道范疇

        
    public String getTitle() {
            
    return title;
        }

        
    public void setTitle(String title) {
            
    this.title = title;
        }

        
    public String getLink() {
            
    return link;
        }

        
    public void setLink(String link) {
            
    this.link = link;
        }

        
    public String getDescription() {
            
    return description;
        }

        
    public void setDescription(String description) {
            
    this.description = description;
        }

        
    public Date getPubDate() {
            
    return pubDate;
        }

        
    public void setPubDate(Date pubDate) {
            
    this.pubDate = pubDate;
        }

        
    public String getAuthor() {
            
    return author;
        }

        
    public void setAuthor(String author) {
            
    this.author = author;
        }

        
    public String getCategory() {
            
    return category;
        }

        
    public void setCategory(String category) {
            
    this.category = category;
        }
    }

    /*
     * RssBuildFactory.java
     * Copyright (C) 2009  <JustinLei@gmail.com>
     *
     *        This program is free software; you can redistribute it and/or modify
     *        it under the terms of the GNU General Public License as published by
     *      the Free Software Foundation; either version 2 of the License, or
     *     (at your option) any later version.
     *
     *       This program is distributed in the hope that it will be useful,
     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *        GNU General Public License for more details.
     *
     
    */
    package org.lambdasoft.components.rss.ejb;

    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;

    import com.sun.syndication.feed.synd.SyndCategory;
    import com.sun.syndication.feed.synd.SyndCategoryImpl;
    import com.sun.syndication.feed.synd.SyndContent;
    import com.sun.syndication.feed.synd.SyndContentImpl;
    import com.sun.syndication.feed.synd.SyndEnclosure;
    import com.sun.syndication.feed.synd.SyndEnclosureImpl;
    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;
    import com.sun.syndication.io.FeedException;
    import com.sun.syndication.io.SyndFeedOutput;

    /**
     * 
    @author lei.tang (justinlei@gmail.com)
     * @date
     * 
    @version
     
    */
    public class RssBuildFactory {
        
    private SyndFeed feed;
        @SuppressWarnings(
    "unchecked")
        
    private List entries;
        
    private SyndEntry entry;

        @SuppressWarnings(
    "unchecked")
        
    public RssBuildFactory() {
            feed 
    = new SyndFeedImpl();
            feed.setFeedType(
    "rss_2.0");
            entries 
    = new ArrayList();
        }

        
    /**
         * 創建一個頻道
         * 
         * 
    @param title 頻道標題
         * 
    @param link 頻道對應的連接
         * 
    @param description 頻道描述
         * 
    @param language 頻道所用語言
         * 
    @param pubDate 頻道發布時期
         * 
    @param copyright 版權所有
         * 
    @throws Exception
         
    */
        
    public void buildChannel(String title, String link, String description,
                String language, Date pubDate, String copyright)
                
    throws RuntimeException {
            feed.setTitle(title);
            feed.setLink(link);
            feed.setDescription(description);
            feed.setLanguage(language);
            feed.setPublishedDate(pubDate);
            feed.setCopyright(copyright);
        }

        
    /**
         * 添加頻道的子內容
         * 
         * 
    @param item
         *            [email={
    @link]{@link[/email] ChannelItem}
         * 
    @throws Exception
         
    */
        @SuppressWarnings(
    "unchecked")
        
    public void buildItems(ChannelItem item) throws RuntimeException {
            entry 
    = new SyndEntryImpl();
            
    // 設置新聞標題
            entry.setTitle(item.getTitle());
            
    // 設置新聞的連接地址
            entry.setLink(item.getLink());
            
    // 設置新聞簡介
            SyndContent content = new SyndContentImpl();
            content.setType(
    "text/plain");
            content.setValue(item.getDescription());
            entry.setDescription(content);
            
    // 設置發布時間
            entry.setPublishedDate(item.getPubDate());
            
    // 設置頻道所屬的范圍
            SyndCategory cate = new SyndCategoryImpl();
            cate.setName(item.getCategory());
            List cateList 
    = new ArrayList();
            cateList.add(cate);
            entry.setCategories(cateList);
            
    // 設置作者
            entry.setAuthor(item.getAuthor());
            
    // 將新聞項添加至數組中
            entries.add(entry);
        }

        
    /**
         * 添加頻道的內容項
         * 
         * 
    @param item
         *            [email={
    @link]{@link[/email] ChannelEItem}此類繼承自ChannelItem類
         * 
    @throws Exception
         
    */
        @SuppressWarnings(
    "unchecked")
        
    public void buildItems(ChannelEItem item) throws RuntimeException {
            entry 
    = new SyndEntryImpl();
            
    // 設置新聞標題
            entry.setTitle(item.getTitle());
            
    // 設置新聞的連接地址
            entry.setLink(item.getLink());
            
    // 設置新聞簡介
            SyndContent content = new SyndContentImpl();
            content.setValue(item.getDescription());
            entry.setDescription(content);
            
    // 設置發布時間
            entry.setPublishedDate(item.getPubDate());
            
    // 設置頻道所屬的范圍
            SyndCategory cate = new SyndCategoryImpl();
            cate.setName(item.getCategory());
            List cateList 
    = new ArrayList();
            cateList.add(cate);
            entry.setCategories(cateList);
            
    // 設置作者
            entry.setAuthor(item.getAuthor());
            
    // 設置流媒體播放文件
            SyndEnclosure en = new SyndEnclosureImpl();
            en.setUrl(item.getEnclosure());
            List enList 
    = new ArrayList();
            enList.add(en);
            entry.setEnclosures(enList);
            
    // 將新聞項添加至數組中
            entries.add(entry);
        }

        
    /**
         * 生成XML文件
         * 
         * 
    @param outputStream
         * 
    @throws Exception
         
    */
        
    public String buildChannel() throws IOException {
            feed.setEntries(entries);
            SyndFeedOutput output 
    = new SyndFeedOutput();
            Writer writer;
            ByteArrayOutputStream outputStream 
    = new ByteArrayOutputStream();
            writer 
    = new OutputStreamWriter(outputStream, "UTF-8");
            
    try {
                output.output(feed, writer);
                
    return new String(outputStream.toByteArray());
            } 
    catch (FeedException e) {
                
    throw new IOException();
            }
        }
    }


    /*
     * RssComponentBean.java
     * Copyright (C) 2009  <JustinLei@gmail.com>
     *
     *        This program is free software; you can redistribute it and/or modify
     *        it under the terms of the GNU General Public License as published by
     *      the Free Software Foundation; either version 2 of the License, or
     *     (at your option) any later version.
     *
     *       This program is distributed in the hope that it will be useful,
     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *        GNU General Public License for more details.
     *
     
    */
    package org.lambdasoft.components.rss.ejb;

    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    import javax.interceptor.Interceptors;

    import org.lambdasoft.components.application.RssComponent;
    import org.lambdasoft.components.application.param.RssBuildParam;
    import org.lambdasoft.ejb.interceptors.EjbCheckParamInterceptor;

    /**
     * 
    @author lei.tang (justinlei@gmail.com)
     * @date 
     * 
    @version
     
    */
    @Stateless
    @Remote
    @Interceptors({EjbCheckParamInterceptor.
    class})
    public class RssComponentBean implements RssComponent{
        
    public String buildChannel(RssBuildParam rssBuildParam) throws Exception{
            
    if(rssBuildParam.getChannelEItems() == null)
                
    return null;
            RssBuildFactory builder 
    = new RssBuildFactory();
            
    for (ChannelEItem channelEItem : rssBuildParam.getChannelEItems()) {
                builder.buildItems(channelEItem);
            }
            builder.buildChannel(rssBuildParam.getTitle(),rssBuildParam.getLink(), rssBuildParam.getDescription(),
                    rssBuildParam.getLanguage(), rssBuildParam.getPubDate(), rssBuildParam.getCopyright());
            
    return builder.buildChannel();
        }
    }
    posted on 2009-12-18 15:24 JustinLei 閱讀(1074) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产一区二区三区免费观在线| 国产精品手机在线亚洲| 久久久久免费精品国产| 亚洲精品无码成人AAA片| 亚美影视免费在线观看| 狠狠亚洲婷婷综合色香五月排名 | 成年女人色毛片免费看| 最近2019中文字幕免费直播| 免费的一级黄色片| 国产亚洲精品高清在线| 97久久国产亚洲精品超碰热| 日亚毛片免费乱码不卡一区| 亚洲精品NV久久久久久久久久| 91亚洲va在线天线va天堂va国产 | 日韩免费高清一级毛片在线| 亚洲色大成网站www永久网站| 特级做A爰片毛片免费看无码| 精品久久香蕉国产线看观看亚洲| 国产精品亚洲专区在线观看| 一个人免费观看视频www| 久久久久亚洲精品无码网址色欲| 最近2019中文字幕免费直播 | 亚洲综合激情另类小说区| 国产乱妇高清无乱码免费| 亚洲熟妇无码乱子AV电影| 免费A级毛片无码视频| 国产亚洲精品a在线无码| 久久A级毛片免费观看| 中文字幕无码精品亚洲资源网久久| 四虎影在线永久免费四虎地址8848aa| 亚洲精品视频免费| 91亚洲国产在人线播放午夜| 精品国产免费观看| 中国一级毛片免费看视频| 亚洲国产美女福利直播秀一区二区 | aa毛片免费全部播放完整| 亚洲高清无在码在线电影不卡| 成人影片麻豆国产影片免费观看| 亚洲欧洲国产视频| 国产jizzjizz视频全部免费| 久久免费视频网站|