📄 corefeed.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* 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.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.core;
import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
/**
* Thread that wraps a {@link com.sun.syndication.io.SyndFeedInput} as is
* responsible for downloading and maintaining the current status of the feed.
* <p>
* The feed may be in one of 4 states :-
* <ul>
* <li>Loading. The feed is currently being downloaded from the source site.</li>
* <li>Loaded. The feed has successfuly been downloaded from the source site.</li>
* <li>Empty. The feed has successfuly been downloaded but was empty.</li>
* <li>Failed To Load. The feed failed to load.</li>
* </ul>
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.7 $
*/
public class CoreFeed extends Thread {
final static Log log = LogFactory.getLog(CoreFeed.class);
/**
* Loading. The feed is currently being downloaded from the source site.
*/
public final static int STATUS_LOADING = 0;
/**
* Loaded. The feed has successfuly been downloaded from the source site.
*/
public final static int STATUS_LOADED = 1;
/**
* Empty. The feed has successfuly been downloaded but was empty.
*/
public final static int STATUS_EMPTY = 2;
/**
* Failed To Load. The feed failed to load.
*/
public final static int STATUS_FAILED_TO_LOAD = 3;
// Private instance variables
private String feedName;
private SyndFeed feed;
private int status;
private SyndFeedInput input;
private URL url;
/**
* Constructor.
*
* @param feedName feed name
* @param input feed input
* @param url location
*/
public CoreFeed(String feedName, SyndFeedInput input, URL url) {
super("FeedLoader" + url.toExternalForm());
this.url = url;
this.feedName = feedName;
this.input = input;
this.status = STATUS_LOADING;
start();
}
/**
* Get the feed name.
*
* @return feed
*/
public String getFeedName() {
return feedName;
}
/**
* Get the feed object. This will only be available once the feed has
* successfuly been downloaded otherwise <code>null</code> will be returned.
*
* @return feed
*/
public SyndFeed getFeed() {
return feed;
}
/**
* Get the feed status. See class documentation for details.
*
* @return status
*/
public int getStatus() {
return status;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
try {
if (log.isInfoEnabled())
log.info("Loading feed " + url);
status = STATUS_LOADING;
feed = input.build(new XmlReader(url));
if (log.isInfoEnabled())
log.info("Loaded feed " + url);
status = STATUS_LOADED;
} catch (Exception e) {
status = STATUS_FAILED_TO_LOAD;
if(log.isDebugEnabled()) {
// We don't care so much about this error because feeds are now dynamic
// so its likey this will happen alot if we have not provided feeds for specific tiles
log.error("Failed to retrieve feed from " + url + ". ", e);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -