public
Last active

  • Download Gist
x.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
 
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: "tss@cornbread.com"},
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+"&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://java.sun.com/javase/6/docs/api/";
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.