最有用的东西,看看这个start就全有了

 接上回书

今天刚巧有空,就把代码传上来看看,开发这个rss阅读的东东,真正有价值的地方只有几行而已,其他都是些swing的应用,画都画的出来。
/**
 * 
 
*/

package  alex.rssbrowse.control;

import  alex.rssbrowse.view. * ;

import  com.sun.syndication.feed.synd.SyndFeed;
import  com.sun.syndication.feed.synd.SyndEntry;
import  com.sun.syndication.io.SyndFeedInput;
import  com.sun.syndication.io.XmlReader;

import  java.net. * ;
import  java.util. * ;

/**
 * 
@author dozhan
 * 
 
*/

public   class  Start  {

    
// just first test
    public static void test() {
        String str 
= "http://blog.csdn.net/zdsdiablo/Rss.aspx";

        
boolean ok = false;
        
try {

            URL feedUrl 
= new URL(str);

            SyndFeedInput input 
= new SyndFeedInput();

            SyndFeed feed 
= input.build(new XmlReader(feedUrl));

            ListIterator lit 
= feed.getEntries().listIterator();
            
while (lit.hasNext()) {
                SyndEntry se 
= (SyndEntry) lit.next();

                System.out.println(
"题目:" + se.getTitle());
                System.out.println(
"作者:" + se.getAuthor());
                System.out.println(
"备注:" + se.getDescription().getValue());

            }

            
// System.out.println(feed);

            ok 
= true;
        }
 catch (Exception ex) {
            ex.printStackTrace();
            System.out.println(
"ERROR: " + ex.getMessage());
        }


        
if (!ok) {
            System.out.println();
            System.out
                    .println(
"FeedReader reads and prints any RSS/Atom feed type.");
            System.out
                    .println(
"The first parameter must be the URL of the feed to read.");
            System.out.println();
        }

    }


    
public static void main(String[] args) {
        System.out.println(
"Start...");

        IOConfiguration.init();

        GUIBuilder gui 
= new GUIBuilder();

        gui.setVisible(
true);

    }

}


测试的时候把main里面的东西都去掉,然后去运行那个test()就能发现,爽啊,网上的东西都能读到啊。
如果读不到,可能是你要设置一下代理才行

下面这段代码是我把代理的配置放到了一个xml文件里,只做测试的话可以手写一个配置上去
package  alex.rssbrowse.control;

import  java.io.FileWriter;
import  java.io.IOException;
import  java.util.Properties;

import  org.jdom.Document;
import  org.jdom.Element;
import  org.jdom.JDOMException;
import  org.jdom.input.SAXBuilder;
import  org.jdom.output.Format;
import  org.jdom.output.XMLOutputter;

/**
 * 
@author dozhan
 * 
 
*/

public   class  IOConfiguration  {

    
public static String HOST = "proxyHost";

    
public static String PORT = "proxyPort";

    
public static String SET = "proxySet";
    
    
public static String path ="alex/rssbrowse/res/user.xml";

    
public static void init() {
        Properties prop 
= System.getProperties();
        
if (getProxyConfiguration(SET).equalsIgnoreCase("true")) {
            String host 
= getProxyConfiguration(HOST);
            String port 
= getProxyConfiguration(PORT);
            
if (host != null && port != null{
                prop.put(
"http.proxyHost", host);
                prop.put(
"http.proxyPort", port);
            }

        }

        
else{
            prop.put(
"http.proxyHost""");
            prop.put(
"http.proxyPort""");
        }

    }


    
public static String getProxyConfiguration(String child) {
        SAXBuilder builder 
= new SAXBuilder();

        
try {
            Document read_doc 
= builder.build(path);

            Element stu 
= read_doc.getRootElement();

            Element proxy 
= stu.getChild("proxy");
            
if (proxy != null && child != null{
                Element proxyHost 
= proxy.getChild(child);
                
if (proxyHost != null{
                    
return proxyHost.getText();
                }

            }


        }
 catch (JDOMException e1) {
            e1.printStackTrace();
        }
 catch (IOException e1) {
            e1.printStackTrace();
        }

        
return "";

    }


    
public static void setProxyConfiguration(String child, String newText) {
        SAXBuilder builder 
= new SAXBuilder();

        
try {
            Document document 
= builder.build(path);

            Element stu 
= document.getRootElement();

            Element proxy 
= stu.getChild("proxy");
            
if (proxy != null && child != null{
                Element proxyHost 
= proxy.getChild(child);
                
if (proxyHost != null{
                    proxyHost.setText(newText);
                }

            }
            
            
            XMLOutputter xmlOut 
= new XMLOutputter(Format.getPrettyFormat());            
            xmlOut.output(document, System.out);
            FileWriter writer 
= new FileWriter(path);
            xmlOut.output(document, writer);
            writer.close();
            
        }
 catch (JDOMException e1) {
            e1.printStackTrace();
        }
 catch (IOException e1) {
            e1.printStackTrace();
        }

        IOConfiguration.init();

    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值