📄 sfplugindetailsloaderimpl.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SFPluginDetailsLoaderImpl.java
package org.gudy.azureus2.pluginsimpl.update.sf.impl2;
import com.aelitis.azureus.core.versioncheck.VersionCheckClient;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.html.*;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.platform.*;
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;
import org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl;
import org.gudy.azureus2.pluginsimpl.update.sf.*;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.update.sf.impl2:
// SFPluginDetailsImpl
public class SFPluginDetailsLoaderImpl
implements SFPluginDetailsLoader, ResourceDownloaderListener
{
private static final LogIDs LOGID;
private static final String site_prefix_default = "http://azureus.sourceforge.net/";
private static String site_prefix;
private static String base_url_params;
private static String page_url;
private static SFPluginDetailsLoaderImpl singleton;
private static AEMonitor class_mon = new AEMonitor("SFPluginDetailsLoader:class");
private static final int RELOAD_MIN_TIME = 0x36ee80;
protected boolean plugin_ids_loaded;
protected long plugin_ids_loaded_at;
protected List plugin_ids;
protected Map plugin_map;
protected List listeners;
protected ResourceDownloaderFactory rd_factory;
protected AEMonitor this_mon;
public static SFPluginDetailsLoader getSingleton()
{
SFPluginDetailsLoaderImpl sfplugindetailsloaderimpl;
class_mon.enter();
if (singleton == null)
singleton = new SFPluginDetailsLoaderImpl();
sfplugindetailsloaderimpl = singleton;
class_mon.exit();
return sfplugindetailsloaderimpl;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
protected SFPluginDetailsLoaderImpl()
{
listeners = new ArrayList();
rd_factory = ResourceDownloaderFactoryImpl.getSingleton();
this_mon = new AEMonitor("SFPluginDetailsLoader");
reset();
}
protected String getRelativeURLBase()
{
return site_prefix;
}
protected void loadPluginList()
throws SFPluginDetailsException
{
try
{
ResourceDownloader dl = rd_factory.create(new URL(page_url));
dl = rd_factory.getRetryDownloader(dl, 5);
dl.addListener(this);
Properties details = new Properties();
InputStream is = dl.download();
details.load(is);
is.close();
for (Iterator it = details.keySet().iterator(); it.hasNext();)
{
String plugin_id = (String)it.next();
String data = (String)details.get(plugin_id);
int pos = 0;
List bits = new ArrayList();
do
{
if (pos >= data.length())
break;
int p1 = data.indexOf(';', pos);
if (p1 == -1)
{
bits.add(data.substring(pos).trim());
break;
}
bits.add(data.substring(pos, p1).trim());
pos = p1 + 1;
} while (true);
if (bits.size() < 3)
{
Logger.log(new LogEvent(LOGID, 3, (new StringBuilder()).append("SF loadPluginList failed for plugin '").append(plugin_id).append("'. Details array is ").append(bits.size()).append(" (3 min)").toString()));
} else
{
String version = (String)bits.get(0);
String cvs_version = (String)bits.get(1);
String name = (String)bits.get(2);
String category = "";
if (bits.size() > 3)
category = (String)bits.get(3);
plugin_ids.add(plugin_id);
plugin_map.put(plugin_id.toLowerCase(), new SFPluginDetailsImpl(this, plugin_id, version, cvs_version, name, category));
}
}
plugin_ids_loaded = true;
plugin_ids_loaded_at = SystemTime.getCurrentTime();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
throw new SFPluginDetailsException("Plugin list load failed", e);
}
}
protected void loadPluginDetails(SFPluginDetailsImpl details)
throws SFPluginDetailsException
{
try
{
ResourceDownloader p_dl = rd_factory.create(new URL((new StringBuilder()).append(site_prefix).append("plugin_details.php?plugin=").append(details.getId()).append("&").append(base_url_params).toString()));
p_dl = rd_factory.getRetryDownloader(p_dl, 5);
p_dl.addListener(this);
HTMLPage plugin_page = HTMLPageFactory.loadPage(p_dl.download(), "UTF-8");
if (!processPluginPage(details, plugin_page))
throw new SFPluginDetailsException((new StringBuilder()).append("Plugin details load fails for '").append(details.getId()).append("': data not found").toString());
}
catch (Throwable e)
{
Debug.printStackTrace(e);
throw new SFPluginDetailsException("Plugin details load fails", e);
}
}
protected boolean processPluginPage(SFPluginDetailsImpl details, HTMLPage page)
throws SFPluginDetailsException
{
HTMLTable tables[] = page.getTables();
return processPluginPage(details, tables);
}
protected boolean processPluginPage(SFPluginDetailsImpl details, HTMLTable tables[])
throws SFPluginDetailsException
{
for (int i = 0; i < tables.length; i++)
{
HTMLTable table = tables[i];
HTMLTableRow rows[] = table.getRows();
if (rows.length == 10)
{
HTMLTableCell cells[] = rows[0].getCells();
if (cells.length == 6 && cells[0].getContent().trim().equals("Name") && cells[5].getContent().trim().equals("Contact"))
{
HTMLTableCell detail_cells[] = rows[2].getCells();
String plugin_auth = detail_cells[4].getContent();
String dl_links[] = detail_cells[2].getLinks();
String plugin_download;
if (dl_links.length == 0)
plugin_download = "<unknown>";
else
plugin_download = (new StringBuilder()).append(site_prefix).append(dl_links[0]).toString();
HTMLTableCell cvs_detail_cells[] = rows[3].getCells();
String cvs_dl_links[] = cvs_detail_cells[2].getLinks();
String plugin_cvs_download;
if (cvs_dl_links.length == 0)
plugin_cvs_download = "<unknown>";
else
plugin_cvs_download = (new StringBuilder()).append(site_prefix).append(cvs_dl_links[0]).toString();
String info_url = null;
if (rows[9].getCells().length > 1)
info_url = rows[9].getCells()[1].getContent();
details.setDetails(plugin_download, plugin_auth, plugin_cvs_download, rows[6].getCells()[0].getContent(), rows[9].getCells()[0].getContent(), info_url);
return true;
}
}
HTMLTable sub_tables[] = table.getTables();
boolean res = processPluginPage(details, sub_tables);
if (res)
return res;
}
return false;
}
protected void dumpTables(String indent, HTMLTable tables[])
{
for (int i = 0; i < tables.length; i++)
{
HTMLTable tab = tables[i];
System.out.println((new StringBuilder()).append(indent).append("tab:").append(tab.getContent()).toString());
HTMLTableRow rows[] = tab.getRows();
for (int j = 0; j < rows.length; j++)
{
HTMLTableRow row = rows[j];
System.out.println((new StringBuilder()).append(indent).append(" row[").append(j).append("]: ").append(rows[j].getContent()).toString());
HTMLTableCell cells[] = row.getCells();
for (int k = 0; k < cells.length; k++)
System.out.println((new StringBuilder()).append(indent).append(" cell[").append(k).append("]: ").append(cells[k].getContent()).toString());
}
dumpTables((new StringBuilder()).append(indent).append(" ").toString(), tab.getTables());
}
}
public String[] getPluginIDs()
throws SFPluginDetailsException
{
String as[];
this_mon.enter();
if (!plugin_ids_loaded)
loadPluginList();
String res[] = new String[plugin_ids.size()];
plugin_ids.toArray(res);
as = res;
this_mon.exit();
return as;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public SFPluginDetails getPluginDetails(String name)
throws SFPluginDetailsException
{
SFPluginDetails sfplugindetails;
this_mon.enter();
getPluginIDs();
SFPluginDetails details = (SFPluginDetails)plugin_map.get(name.toLowerCase());
if (details == null)
throw new SFPluginDetailsException((new StringBuilder()).append("Plugin '").append(name).append("' not found").toString());
sfplugindetails = details;
this_mon.exit();
return sfplugindetails;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public SFPluginDetails[] getPluginDetails()
throws SFPluginDetailsException
{
String plugin_ids[] = getPluginIDs();
SFPluginDetails res[] = new SFPluginDetails[plugin_ids.length];
for (int i = 0; i < plugin_ids.length; i++)
res[i] = getPluginDetails(plugin_ids[i]);
return res;
}
public void reportPercentComplete(ResourceDownloader resourcedownloader, int i)
{
}
public void reportAmountComplete(ResourceDownloader resourcedownloader, long l)
{
}
public void reportActivity(ResourceDownloader downloader, String activity)
{
informListeners(activity);
}
public boolean completed(ResourceDownloader downloader, InputStream data)
{
return true;
}
public void failed(ResourceDownloader downloader, ResourceDownloaderException e)
{
informListeners((new StringBuilder()).append("Error: ").append(e.getMessage()).toString());
}
protected void informListeners(String log)
{
for (int i = 0; i < listeners.size(); i++)
((SFPluginDetailsLoaderListener)listeners.get(i)).log(log);
}
public void reset()
{
this_mon.enter();
long now = SystemTime.getCurrentTime();
if (now < plugin_ids_loaded_at)
plugin_ids_loaded_at = 0L;
if (now - plugin_ids_loaded_at > 0x36ee80L)
{
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, "SFPluginDetailsLoader: resetting values"));
plugin_ids_loaded = false;
plugin_ids = new ArrayList();
plugin_map = new HashMap();
} else
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, 1, "SFPluginDetailsLoader: not resetting, cache still valid"));
this_mon.exit();
break MISSING_BLOCK_LABEL_131;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void addListener(SFPluginDetailsLoaderListener l)
{
listeners.add(l);
}
public void removeListener(SFPluginDetailsLoaderListener l)
{
listeners.remove(l);
}
static
{
LOGID = LogIDs.CORE;
try
{
Map data = VersionCheckClient.getSingleton().getVersionCheckInfo("pu");
byte b_sp[] = (byte[])(byte[])data.get("plugin_update_url");
if (b_sp == null)
site_prefix = "http://azureus.sourceforge.net/";
else
site_prefix = new String(b_sp);
}
catch (Throwable e)
{
site_prefix = "http://azureus.sourceforge.net/";
}
base_url_params = (new StringBuilder()).append("version=4.2.0.0&app=").append(SystemProperties.getApplicationName()).toString();
try
{
base_url_params = (new StringBuilder()).append(base_url_params).append("&os=").append(URLEncoder.encode(System.getProperty("os.name"), "UTF-8")).toString();
base_url_params = (new StringBuilder()).append(base_url_params).append("&arch=").append(URLEncoder.encode(System.getProperty("os.arch"), "UTF-8")).toString();
base_url_params = (new StringBuilder()).append(base_url_params).append("&ui=").append(URLEncoder.encode(COConfigurationManager.getStringParameter("ui"), "UTF-8")).toString();
base_url_params = (new StringBuilder()).append(base_url_params).append("&java=").append(URLEncoder.encode(System.getProperty("java.version"), "UTF-8")).toString();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
page_url = (new StringBuilder()).append(site_prefix).append("update/pluginlist3.php?type=&").append(base_url_params).toString();
try
{
PlatformManager pm = PlatformManagerFactory.getPlatformManager();
if (pm.hasCapability(PlatformManagerCapabilities.GetVersion))
page_url = (new StringBuilder()).append(page_url).append("&pmv=").append(pm.getVersion()).toString();
}
catch (Throwable e) { }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -