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

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

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

    posts - 262,  comments - 221,  trackbacks - 0

    一個RSS頻道通常被我們叫做Feed,假如現在我們收集的RSS Feed越來越多,我想分享出去。那么可以做的辦法有什么呢?手工把這些Feed的地址一個個copy出來,然后發送嗎?這樣太麻煩了。

    OPML(Outline Processor Markup Language)協議正是用于解決這樣問題的。利用OPML協議,我們可以通過閱讀器把已經訂閱的頻道導出為OPML協議規定的格式,從而作為
    一個文件分享出去。

    Informa中同樣提供了對于OPML文件的解析,目前支持的版本是1.1版本。

    ★OPMLParser



    OPMLParser中同樣提供了類似FeedParser的多種數據源支持的解析,可以分別從URL,文件,字節流,字符流中讀入OPML文件,這個類的核心方法是parse(Dcoument)。

        private static synchronized Collection<FeedIF> parse(Document doc)
                
    throws ParseException {

            logger.debug(
    "start parsing.");
            
    // Get the root element (must be opml)
            Element root = doc.getRootElement();
            String rootElement 
    = root.getName().toLowerCase();
            
    // Decide which parser to use
            if (rootElement.startsWith("opml")) {
                String opmlVersion 
    = root.getAttribute("version").getValue();
                
    if (opmlVersion.indexOf("1.1">= 0{
                    logger.info(
    "Collection uses OPML root element (Version 1.1).");
                    
    return OPML_1_1_Parser.parse(root);
                }

            }


            
    // did not match anything
            throw new UnsupportedFormatException("Unsupported OPML root element ["
                    
    + rootElement + "].");
        }


    可以看到這個類又是一個中介類,簡單地分析協議的版本然后委托給相應的解析器。目前由于OPML協議解析器只支持1.1版本,所以只有一個OPML_1_1_Parser

    ★OPML_1_1_Parser

        static Collection<FeedIF> parse(Element root) {

            Collection
    <FeedIF> feedColl = new ArrayList<FeedIF>();

            Date dateParsed 
    = new Date();
            logger.debug(
    "start parsing.");

            
    // Lower the case of these tags to simulate case-insensitive parsing
            ParserUtils.matchCaseOfChildren(root, "body");

            
    // Get the head element (only one should occur)
            
    //    Element headElem = root.getChild("head");
            
    //    String title = headElem.getChildTextTrim("title");

            
    // Get the body element (only one occurs)
            Element bodyElem = root.getChild("body");

            
    // 1..n outline elements
            ParserUtils.matchCaseOfChildren(bodyElem, "outline");
            List feeds 
    = bodyElem.getChildren("outline");
            Iterator i 
    = feeds.iterator();
            
    while (i.hasNext()) {
                Element feedElem 
    = (Element) i.next();
                
    // get title attribute
                Attribute attrTitle = feedElem.getAttribute("title");
                String strTitle 
    = "[No Title]";
                
    if (attrTitle != null{
                    strTitle 
    = attrTitle.getValue();
                }

                FeedIF feed 
    = new Feed(strTitle);
                
    if (logger.isDebugEnabled()) {
                    logger.debug(
    "Feed element found (" + strTitle + ").");
                }

                
    // get text attribute
                Attribute attrText = feedElem.getAttribute("text");
                String strText 
    = "[No Text]";
                
    if (attrText != null{
                    strText 
    = attrText.getValue();
                }

                feed.setText(strText);
                
    // get attribute type (for example: 'rss')
                Attribute attrType = feedElem.getAttribute("type");
                String strType 
    = "text/xml";
                
    if (attrType != null{
                    strType 
    = attrType.getValue();
                }

                feed.setContentType(strType);

                
    // TODO: handle attribute version (for example: 'RSS')

                
    // get attribute xmlUrl
                Attribute attrXmlUrl = feedElem.getAttribute("xmlUrl");
                
    if (attrXmlUrl != null && attrXmlUrl.getValue() != null{
                    feed.setLocation(ParserUtils.getURL(attrXmlUrl.getValue()));
                }

                
    // get attribute htmllUrl
                Attribute attrHtmlUrl = feedElem.getAttribute("htmlUrl");
                
    if (attrHtmlUrl != null && attrHtmlUrl.getValue() != null{
                    feed.setSite(ParserUtils.getURL(attrHtmlUrl.getValue()));
                }

                
    // set current date
                feed.setDateFound(dateParsed);
                
    // add feed to collection
                feedColl.add(feed);
            }


            
    return feedColl;
        }


    OPML協議的結構如下:

     A.根節點是<opml version="1.x">元素
     B.子節點<head>元素,該元素包含了title,dateCreated,dateModified,ownerName等屬性
     C.子節點<body>元素,該元素包含了0..若干個<outline>元素,該元素是可嵌套的



    -------------------------------------------------------------
    生活就像打牌,不是要抓一手好牌,而是要盡力打好一手爛牌。
    posted on 2010-01-02 20:56 Paul Lin 閱讀(345) 評論(0)  編輯  收藏 所屬分類: J2SE
    <2010年1月>
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    常用鏈接

    留言簿(21)

    隨筆分類

    隨筆檔案

    BlogJava熱點博客

    好友博客

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 美女被爆羞羞网站免费| 亚洲精品成人无码中文毛片不卡| 亚洲人成中文字幕在线观看| 另类专区另类专区亚洲| 女人让男人免费桶爽30分钟| 97久久国产亚洲精品超碰热| 曰曰鲁夜夜免费播放视频| 91亚洲自偷在线观看国产馆| 久久精品无码专区免费青青| 亚洲人成依人成综合网| 久久精品一本到99热免费| 亚洲精品精华液一区二区| 日韩一级视频免费观看| 国产亚洲高清在线精品不卡| 亚洲精品你懂的在线观看| 性做久久久久久久免费看| 美女又黄又免费的视频| 亚洲一卡2卡三卡4卡有限公司| 精品女同一区二区三区免费播放| 日韩一级在线播放免费观看| a级毛片毛片免费观看久潮| 国产精品四虎在线观看免费| 亚洲欧洲日韩国产一区二区三区| 手机看黄av免费网址| 亚洲专区一路线二| 成人性生活免费视频| 亚洲成在人线在线播放无码| 中文字幕日韩亚洲| 亚洲国产成人精品无码区花野真一 | 亚洲AV日韩AV永久无码下载| 99久9在线|免费| 亚洲欧美自偷自拍另类视| 人人揉揉香蕉大免费不卡| 999国内精品永久免费观看| 亚洲毛片αv无线播放一区| 久9热免费精品视频在线观看| 色一情一乱一伦一视频免费看| 亚洲男人天堂av| 四虎永久成人免费影院域名| 四虎在线视频免费观看视频| 久久精品亚洲中文字幕无码网站|