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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* $Id: dereference.js,v 1.23.2.3 2010/04/06 16:46:11 source Exp $
*
* This file is part of the OpenLink Software Ajax Toolkit (OAT) project.
*
* Copyright (C) 2005-2010 OpenLink Software
*
* See LICENSE file for details.
*/
/*
OAT.Dereference.go(url, callback, optObj)
*/
OAT.Dereference = {
options:{
endpoint:"/about?url=", /* endpoint for dereferencing *this* resource */
pragmas:{}, /* key->value pairs */
endpointOpts:{
virtuoso:true, /* is virtuoso? */
proxyVersion:1 /* normal proxy type - default */
},
ajaxOpts:{}
},
addParam:function(url, param, value) {
if (url.match(/.*\?.*/)) {
return url + "&" + param + "=" + value;
}
return url + "?" + param + "=" + value;
},
copy:function(srcObj,dstObj,propObj) {
if (!propObj) { propObj = srcObj; }
for (var p in propObj) { dstObj[p] = srcObj[p]; }
},
go:function(url,callback,optObj) {
var ajaxOpts = {};
var endpointOpts = {};
var pragmas = {};
var direct = false;
var endpoint = "";
/* deep copy defaults */
this.copy(this.options.ajaxOpts,ajaxOpts);
this.copy(this.options.endpointOpts,endpointOpts);
this.copy(this.options.pragmas,pragmas);
endpoint = this.options.endpoint;
/* now the settings */
if (optObj) {
this.copy(optObj.ajaxOpts,ajaxOpts);
this.copy(optObj.endpointOpts,endpointOpts);
this.copy(optObj.pragmas,pragmas);
if (optObj.endpoint) endpoint = optObj.endpoint;
}
if (!optObj.direct) {
if (url.match(/^http/i) && endpointOpts.virtuoso) { /* Virtuoso proxy: */
if (endpointOpts.proxyVersion == 1) {
var r = url.match(/^(http[s]?:\/\/)([^@\/]+@)?(.*)/);
var user = (r[2] ? r[2].substring(0,r[2].length-1) : false);
var encoded = encodeURIComponent(r[1] + r[3]);
encoded = this.addParam(endpoint + encoded, "force", "rdf");
if (user) { encoded = this.addParam(encoded, "login", encodeURIComponent(user)); }
if (url.match(/\.n3$/)) { encoded = this.addParam(encoded, "output-format", "n3"); }
if (url.match(/\.ttl$/)) { encoded = this.addParam(encoded, "output-format", "ttl"); }
for (var p in pragmas) { encoded = this.addParam(encoded, p, pragmas[p]); }
} else {
var r = url.match(/^(http[s]?:\/\/)([^@\/]+@)?(.*)/);
var user = (r[2] ? r[2].substring(0,r[2].length-1) : false);
var encoded = (endpoint + r[1] + r[3]);
ajaxOpts["noSecurityCookie"] = true;
}
} else if ((url.match(/^urn:/i) ||
url.match(/^doi:/i) ||
url.match(/^oai:/i) ||
url.match(/^nodeid:/i)) && endpointOpts.virtuoso) { /* Virtuoso proxy: */
if (endpointOpts.proxyVersion == 1) {
var encoded = encodeURIComponent(url);
encoded = this.addParam(endpoint + encoded, "force", "rdf");
if (url.match(/\.n3$/)) { encoded = this.addParam(encoded, "output-format", "n3"); }
if (url.match(/\.ttl$/)) { encoded = this.addParam(encoded, "output-format", "ttl"); }
for (var p in pragmas) { encoded = this.addParam(encoded, p, pragmas[p]); }
} else {
var encoded = endpoint + url;
ajaxOpts["noSecurityCookie"] = true;
}
} else if (url.match(/^urn:/i) ||
url.match(/^doi:/i) ||
url.match(/^oai:/i) ||
url.match(/^http/i)) { /* other than Virtuoso: */
var encoded = endpoint + decodeURIComponent(url);
ajaxOpts["noSecurityCookie"] = true;
} else { /* relative uri */
var encoded = url;
}
} else { /* Dereference using supplied endpoint and options. Direct SPARQL queries, etc */
encoded = endpoint + url;
}
var xhr = OAT.AJAX.GET(encoded,false,callback,ajaxOpts);
return xhr;
}
}
|