Locale.setDefault(local);
HelpSet helpset;
Page parent;
URL helpurl;
SearchlistClassLoader loader = new
SearchlistClassLoader(this.getClass().getClassLoader());
// (SearchlistClassLoader) this.getClass().getClassLoader();
File dir = new File(ArtOfIllusion.PLUGIN_DIRECTORY, "Help");
/*
* NTJ: hack to get library files working for the EA
String[] jars = new String[] { "helpgui-1.1a.jar",
"jhall.jar", "jhelpaction.jar", "pircbot.jar",
"AOIHelp.zip"
};
URLClassLoader myldr = null;
Method addURL = null;
File urlfile = null;
Object[] urlarg = new Object[1];
try {
myldr = (URLClassLoader) getClass().getClassLoader();
Class [] sig = new Class[] { URL.class };
addURL = URLClassLoader.class.getDeclaredMethod("addURL",
sig);
addURL.setAccessible(true);
} catch (Exception e) {
System.out.println("failed to get addURL: " + e);
}
for (i = 0; i < jars.length; i++) {
try {
urlfile = new File(dir, jars[i]);
urlarg[0] = urlfile.toURI().toURL();
addURL.invoke(myldr, urlarg);
} catch (Exception e) {
System.out.println("failed to update classloader: " +
e);
}
}
*/
try {
if (loader.getResource("helpset/AOIHelp.hs") == null) {
throw new RuntimeException("cannot load global helpset");
}
/*
* NTJ: JavaHelp is optional.
* If we fail to find it in the classpath, fall back to
* HelpGUI
*/
try {
JHelpAction.startHelpWorker("helpset/AOIHelp.hs");
Method getbroker =
JHelpAction.class.getDeclaredMethod("getHelpBroker",
null);
getbroker.setAccessible(true);
global = (HelpSet)
((HelpBroker) getbroker.invoke(null, null)).getHelpSet();
helplib = JAVAHELP_LIB;
} catch (Throwable e) {
System.out.println("HelpPlugin: could not initialise JavaHelp");
}
/*
* NTJ: drive HelpSet manually
helpurl = HelpSet.findHelpSet(loader, "helpset/AOIHelp",
local);
global = new HelpSet(helpurl);
broker = global.createHelpBroker();
final HelpBroker brok = broker;
(new Thread() {
public void run()
{ brok.initPresentation(); }
}).start();
*/
/*
* NTJ: Using (open-source) HelpGui derivative as fallback
*/
java.util.List list;
if (helplib == 0) {
try {
docset = new DocSet(Translate.getLocale());
list =
PluginRegistry.getPlugins(DocSet.Parser.class);
DocSet.Parser parser;
for (i = 0; i < list.size(); i++) {
parser = (DocSet.Parser) list.get(i);
System.out.println("HelpPlugin.INIT: " +
"registering parser: " +
parser.getClass().getName());
DocSet.registerParser(parser);
}
docset.setLoader(loader);
docset.add("helpset/AOIHelp.hs", null);
helplib = HELPGUI_LIB;
} catch (Throwable t) {
System.out.println("HelpPlugin: could not initialise HelpGUI");
}
}
helpset = global;
parent = null;
enabled = (helplib != 0);
/*
* scan Plugins/Help and add any help resources found.
*/
File files[] = dir.listFiles();
File subdir[], helpfile;
int cut, subcount;
ZipFile zf = null;
ZipEntry ze = null;
String basename;
ClassLoader ldr;
URL url[] = new URL[1];
for (i = 0; i < files.length; i++) {
// create a subsection for each subdirectory
if (files[i].isDirectory()) {
subdir = files[i].listFiles();
subcount = subdir.length;
if (subcount > 0) {
if (helplib == JAVAHELP_LIB) {
helpset = new HelpSet(loader);
global.add(helpset);
}
else if (helplib == HELPGUI_LIB) {
parent = docset.addSection(files[i].getName(), null);
}
}
}
else {
subdir = null;
subcount = 1;
helpset = global;
parent = null;
}
for (k = 0; k < subcount; k++) {
helpfile = (subdir != null ? subdir[k] : files[i]);
try {
// look inside all zip files
zf = new ZipFile(helpfile);
// look for a helpset entry (*.hs)
Enumeration iter = zf.entries();
while (iter.hasMoreElements()) {
ze = (ZipEntry) iter.nextElement();
if (ze.isDirectory()) continue;
if (ze.getName().endsWith(".hs")) break;
ze = null;
}
// no helpset entry found, try next...
if (ze == null) continue;
basename = ze.getName();
cut = basename.lastIndexOf('.');
if (cut > 0)
basename = basename.substring(0, cut);
// if it's a helpset, add it to the resources
System.out.println("HelpPlugin.ADD: " +
basename);
url[0] = helpfile.toURI().toURL();
ldr = new URLClassLoader(url);
PluginRegistry.registerResource("help",
basename,
ldr,
ze.getName(),
null);
} catch (Exception e) {}
finally {
if (zf != null) {
zf.close();
zf = null;
}
}
}
}
HelpSet plugset=null;
if (helplib == JAVAHELP_LIB) plugset = new HelpSet(loader);
// load all the registered help resources
list = PluginRegistry.getResources("help");
System.out.println("resources found=" + list.size());
if (list.size() > 0) {
if (docset != null)
parent = docset.addSection("Plugins", null);
PluginRegistry.PluginResource resource;
for (i = 0; i < list.size(); i++) {
resource =
(PluginRegistry.PluginResource) list.get(i);
// don't load global help a second time
if (resource.getId().equals("helpset/AOIHelp"))
continue;
System.out.println("Help: linking: " +
resource.getURL().getPath());
loader.add(resource.getClassLoader());
System.out.println("loading: " + resource.getId() +
" from " +
resource.getURL().getPath());
/*
* NTJ: *ugh* After all that work, something in
* in JavaHelp is only using the loader of the
* plugin. I suspect it is JHelpDev...
*/
if (plugset != null)
//plugset.add(new HelpSet(resource.getClassLoader(), resource.getURL()));
plugset.add(new HelpSet(loader, resource.getURL()));
else {
loader.add(resource.getClassLoader());
docset.add(resource.getURL().getPath(),parent);
}
}
}