FileDocCategorySizeDatePackage
TorrentListener.javaAPI DocAzureus 3.0.3.43286Mon Sep 17 05:58:04 BST 2007com.aelitis.azureus.ui.swt.browser.listener

TorrentListener

public class TorrentListener extends com.aelitis.azureus.ui.swt.browser.msg.AbstractMessageListener

Fields Summary
public static final String
DEFAULT_LISTENER_ID
public static final String
OP_LOAD_TORRENT_OLD
public static final String
OP_LOAD_TORRENT
private com.aelitis.azureus.core.AzureusCore
core
Constructors Summary
public TorrentListener(com.aelitis.azureus.core.AzureusCore core)


	   
		this(DEFAULT_LISTENER_ID, core);
	
public TorrentListener(String id, com.aelitis.azureus.core.AzureusCore core)

		super(id);
		this.core = core;
	
public TorrentListener()

		this(AzureusCoreFactory.getSingleton());
	
Methods Summary
public voidhandleMessage(com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage message)

		if (OP_LOAD_TORRENT.equals(message.getOperationId())
				|| OP_LOAD_TORRENT_OLD.equals(message.getOperationId())) {
			Map decodedMap = message.getDecodedMap();
			String url = MapUtils.getMapString(decodedMap, "url", null);
			boolean playNow = MapUtils.getMapBoolean(decodedMap, "play-now", false);
			if (url != null) {
				TorrentUIUtilsV3.loadTorrent(core, url, message.getReferer(), playNow);
			} else {
				loadTorrentByB64(core, message, MapUtils.getMapString(decodedMap,
						"b64", null));
			}
		} else {
			throw new IllegalArgumentException("Unknown operation: "
					+ message.getOperationId());
		}
	
public static booleanloadTorrentByB64(com.aelitis.azureus.core.AzureusCore core, java.lang.String b64)

		return loadTorrentByB64(core, null, b64);
	
private static booleanloadTorrentByB64(com.aelitis.azureus.core.AzureusCore core, com.aelitis.azureus.ui.swt.browser.msg.BrowserMessage message, java.lang.String b64)

param
mapString
since
3.0.1.7

		if (b64 == null) {
			return false;
		}

		byte[] decodedTorrent = Base64.decode(b64);

		File tempTorrentFile;
		try {
			tempTorrentFile = File.createTempFile("AZU", ".torrent");
			tempTorrentFile.deleteOnExit();
			String filename = tempTorrentFile.getAbsolutePath();
			FileUtil.writeBytesAsFile(filename, decodedTorrent);

			TOTorrent torrent = TorrentUtils.readFromFile(tempTorrentFile, false);
			// Security: Only allow torrents from whitelisted trackers
			if (!PlatformTorrentUtils.isPlatformTracker(torrent)) {
				Debug.out("stopped loading torrent because it's not in whitelist");
				return false;
			}

			String savePath = COConfigurationManager.getStringParameter("Default save path");
			if (savePath == null || savePath.length() == 0) {
				savePath = ".";
			}

			core.getGlobalManager().addDownloadManager(filename, savePath);
		} catch (Throwable t) {
			if (message != null) {
				message.debug("loadUrl error", t);
			} else {
				Debug.out(t);
			}
			return false;
		}
		return true;
	
public voidsetShell(org.eclipse.swt.widgets.Shell shell)