RSSReader.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
omschaub.aztrackerfind.main |
![]() |
![]() |
AZCVSUpdater |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Created on Jan 5, 2005
* Created by omschaub
*
*/
package omschaub.aztrackerfind.main;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderException;
import org.gudy.azureus2.plugins.utils.xml.rss.RSSChannel;
import org.gudy.azureus2.plugins.utils.xml.rss.RSSFeed;
import org.gudy.azureus2.plugins.utils.xml.rss.RSSItem;
import org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentException;
import org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentNode;
/**
* @author omschaub
*
*/
public class RSSReader {
static TreeItem item_server;
static TreeItem item_rssitem;
static TreeItem item_torrent_hash;
static TreeItem item_torrent_size;
static TreeItem item_torrent_seed;
static TreeItem item_torrent_leech;
static TreeItem item_torrent_desc;
static TreeItem item_torrent_link;
public static void parseRSS(final String rss_url, final PluginInterface pluginInterface){
Map args = new HashMap();
try {
RSSFeed feed = pluginInterface.getUtilities().getRSSFeed(new URL(rss_url));
RSSChannel[] channels = feed.getChannels();
for (int i = 0 ; i < channels.length ; i++)
{
final RSSChannel channel = channels[i];
View.display.asyncExec(new Runnable (){
public void run () {
if(View.rss_info != null && !View.rss_info.isDisposed()){
TreeItem items[] = View.rss_info.getItems();
for (int j = 0 ; j < items.length ; j++)
{
if(items[j].getText().startsWith(channel.getTitle()))
{
System.out.println("Duplicate!");
return;
}
}
item_server = new TreeItem(View.rss_info,SWT.NULL);
if (View.rss_info.getItemCount()%2==0) {
item_server.setBackground(View.gray_color);
}
item_server.setText(channel.getTitle() +
" (" + rss_url + ") ");
}
RSSItem[] items = channel.getItems();
if(items.length == 0)
{
item_rssitem = new TreeItem(item_server,SWT.NULL);
item_rssitem.setText("RSS Feed active but no torrents present");
item_rssitem.setBackground(item_server.getBackground());
}
for (int j=0;j<items.length;j++){
RSSItem item = items[j];
if(View.rss_info != null && !View.rss_info.isDisposed()){
item_rssitem = new TreeItem(item_server,SWT.NULL);
item_rssitem.setText(item.getTitle());
item_rssitem.setBackground(item_server.getBackground());
item_torrent_desc = new TreeItem(item_rssitem,SWT.NULL);
item_torrent_desc.setText(" [description] " + item.getDescription());
item_torrent_desc.setBackground(item_rssitem.getBackground());
item_torrent_link = new TreeItem(item_rssitem,SWT.NULL);
item_torrent_link.setText(" [link] " + item.getLink());
item_torrent_link.setBackground(item_rssitem.getBackground());
//popup menu
Menu popupmenu_bookmark = new Menu(View.rss_info.getParent());
final MenuItem InsertTorrent = new MenuItem(popupmenu_bookmark, SWT.PUSH);
InsertTorrent.setText("Add Torrent to Azureus");
InsertTorrent.addListener(SWT.Selection, new Listener() {
public void handleEvent (Event e){
try {
// Check is the table is not disposed
if(View.rss_info == null || View.rss_info.isDisposed())
return;
//Get the selection
TreeItem[] items = View.rss_info.getSelection();
//If an item is selected (single click selects at least one)
if(items.length == 1) {
//Grab selected item
int place = 0;
TreeItem item = items[0];
String torrent_URL = item.getText();
try
{
TreeItem parent_torrent = item.getParentItem();
if(parent_torrent.getText().startsWith("Azureus BitTorrent"))
{
place = 1;
}
}
catch (Exception nullpoint) {
System.out.println("too high!");
place = 2;
}
if(place == 0)
{
InsertTorrent.setEnabled(true);
TreeItem item_parent = item.getParentItem();
TreeItem[] items_children = item_parent.getItems();
for(int i = 0 ; i < items_children.length ; i++){
if(items_children[i].getText().startsWith(" [link]")){
//System.out.println("LINK! " + items_children[i].getText().substring(8,items_children[i].getText().length()));
String link = items_children[i].getText().substring(8,items_children[i].getText().length());
link = link.substring(0,link.indexOf("?"));
Downloader.torrent_getter(link,pluginInterface);
}
}
}
else if (place == 1)
{
InsertTorrent.setEnabled(true);
TreeItem[] items_children = item.getItems();
for(int i = 0 ; i < items_children.length ; i++){
if(items_children[i].getText().startsWith(" [link]")){
//System.out.println("LINK! " + items_children[i].getText().substring(8,items_children[i].getText().length()));
Downloader.torrent_getter(items_children[i].getText().substring(8,items_children[i].getText().length()),pluginInterface);
}
}
}
else if (place == 2)
{
InsertTorrent.setEnabled(false);
//insert message!
Shell shell = new Shell(View.display);
MessageBox messageBox = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
messageBox.setText("Selection Error");
messageBox.setMessage("You have choosen a Tracker, please select a torrent from the tracker to load into Azureus");
int response = messageBox.open();
switch (response){
case SWT.YES:
shell.dispose();
break;
}
}
//Downloader.torrent_getter(torrent_URL,pluginInterface);
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
View.rss_info.setMenu( popupmenu_bookmark);
}
SimpleXMLParserDocumentNode node = item.getNode();
if(View.rss_info != null && !View.rss_info.isDisposed()){
item_torrent_hash = new TreeItem(item_rssitem,SWT.NULL);
item_torrent_hash.setText( " [hash] " + node.getChild(
"torrent_sha1" ).getValue());
item_torrent_hash.setBackground(item_rssitem.getBackground());
item_torrent_size = new TreeItem(item_rssitem,SWT.NULL);
item_torrent_size.setText( " [size] " + node.getChild(
"torrent_size" ).getValue());
item_torrent_size.setBackground(item_rssitem.getBackground());
item_torrent_seed = new TreeItem(item_rssitem,SWT.NULL);
item_torrent_seed.setText( " [seeders] " + node.getChild(
"torrent_seeders" ).getValue());
item_torrent_seed.setBackground(item_rssitem.getBackground());
item_torrent_leech = new TreeItem(item_rssitem,SWT.NULL);
item_torrent_leech.setText( " [leechers] " + node.getChild(
"torrent_leechers" ).getValue());
item_torrent_leech.setBackground(item_rssitem.getBackground());
}
}
}
});
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ResourceDownloaderException e) {
System.out.println("RSS Connection Error: Connection error while contacting " + rss_url );
} catch (SimpleXMLParserDocumentException e) {
System.out.println("Error parsing xml feed document for " + rss_url);
//e.printStackTrace();
}
}
//EOF
}
The table below shows all metrics for RSSReader.java.




