-
-
Save paulp/804694 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
names: ["java"], | |
arguments: [{role: "object", | |
nountype: noun_arb_text, | |
label: "search criteria"}], | |
icon: "http://www.sun.com/favicon.ico", | |
preview: "Searches The Java 6 API.", | |
help: "Enter the name of the Java class or package for which you would like to see the documentation.", | |
author: {name: "KS", email: "[email protected]"}, | |
license: "GPL", | |
execute: function(arguments) { | |
var arg = Utils.trim(arguments.object.text); | |
var destUrl = this._findUrl(arg); | |
Utils.openUrlInBrowser(destUrl); | |
}, | |
preview: function preview(pblock, args) { | |
var arg = Utils.trim(args.object.text); | |
var url = this._findUrl(arg); | |
if(url == this._prefix()) | |
url += "overview-summary.html" | |
if(arg.length > 0){ | |
CmdUtils.previewGet(pblock, url, function(data) { | |
var newData = data; | |
if(data.indexOf("did not match any documents") > -1){ | |
pblock.innerHTML = "Unable to find any match for <i><b>" + args.object.text + "</b></i> in the Java API documentation"; | |
return; | |
} | |
var begin = newData.indexOf("<!-- ======== START OF CLASS DATA ======== -->"); | |
var end = newData.indexOf("<!-- ======== CONSTRUCTOR SUMMARY ======== -->"); | |
if(begin == -1){ | |
begin = newData.indexOf("<!-- ========= END OF TOP NAVBAR ========= -->"); | |
end = newData.indexOf("<!-- ======= START OF BOTTOM NAVBAR ====== -->"); | |
} | |
newData = newData.substring(begin, end); | |
newData = newData.replace(/BGCOLOR="[#a-zA-Z0-9]*"/gi, ""); | |
pblock.innerHTML = newData; | |
}, "html"); | |
} | |
pblock.innerHTML = "Enter a class or package name to search the Java API."; | |
if(arg.length > 0) | |
pblock.innerHTML = "Search the Java API for: <i><b>" + args.object.text + "</b></i>"; | |
}, | |
_findUrl: function(inArg){ | |
var destUrl = ""; | |
var arg = inArg; | |
if(arg.substring(arg.length-1) == ".") | |
arg = arg.substring(0, arg.length-1); | |
if(arg == "java") | |
return this._prefix(); | |
// Enable the lines below to go directly to a fully qualified class name... | |
//if(arg.indexOf(".") > -1) | |
// destUrl = this._prefix() + this._parseClass(arg) + ".html"; | |
//else | |
destUrl = this._searchUrl(arg); | |
return destUrl; | |
}, | |
_searchUrl: function(arg){ | |
// return "http://www.google.com/search?hl=en&q=site:" + this._prefix() + "%20"+arg; | |
return "http://www.google.com/search?hl=en&q=site:" + this._prefix() + "%20"+arg+"&btnG=Search&btnI=3564"; | |
}, | |
_parseClass: function(className){ | |
var packageParts = className.split("."); | |
var path = ""; | |
for(i = 0; i < packageParts.length; i++){ | |
if(i > 0) | |
path += "/"; | |
path += packageParts[i]; | |
} | |
return path; | |
}, | |
_prefix: function(){ | |
return "http://download.oracle.com/javase/6/docs/api/"; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment