Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
235 lines (212 sloc) 10 KB
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF8">
<title>Registry Services - Javascript sample using JQuery</title>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery.rdfquery.core.min-1.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/rdf.tables.css" />
</head>
<body>
<table id="providers">
<caption>Service Providers</caption>
<thead>
<tr>
<th>Title
<span class="rdfquerybug"><a href='http://code.google.com/p/rdfquery/issues/detail?id=17'
title="Known RDFQuery problem in some browsers: RDF/XML Parser Fails to Parse XMLLiteral Outter Text Nodes">
1</a></span>
</th>
<th>Description
<span class="rdfquerybug"><a href='http://code.google.com/p/rdfquery/issues/detail?id=17'
title="Known RDFQuery problem in some browsers: RDF/XML Parser Fails to Parse XMLLiteral Outter Text Nodes">
1</a></span>
</th>
<th>URL</th>
<th>Source Provider URL</th>
<th>Display Records</th>
</tr>
</thead>
<tbody id="providersData">
</tbody>
</table>
<p/>
<p/>
<p/>
<table id="providers">
<caption>Registration Records</caption>
<thead>
<tr>
<th>URL</th>
<th>Source Record URL</th>
</tr>
</thead>
<tbody id="registrationData">
<tr>
<td>Click on a "Display Records" icon in the "Service Providers" table to display its Registration Records.</td>
<td/>
</tr>
</tbody>
</table>
<p/>
<p/>
<p/>
<table id="providers">
<caption>Resource Records</caption>
<thead>
<tr>
<th>URL</th>
<th>Modified time</th>
<th>Associated Registration Records</th>
</tr>
</thead>
<tbody id="resourceData">
<tr>
<td>Click on a "Display Records" icon in the "Service Providers" table to display Resource Records associated with its Registration Records.</td>
<td/>
<td/>
</tr>
</tbody>
</table>
<script type="text/javascript">
var registrationDataDOMId = "registrationData";
var registrationDataJSId = "#registrationData";
function displayRegistrationRecords(spUrl) {
$(registrationDataJSId)
.replaceWith("<tbody id='registrationData'><tr>" +
"<td>Fetching registration records...</td><td/>" +
"</tr></tbody>");
var
serviceProviderFilter = encodeURIComponent("oslc:serviceProvider=<" + spUrl +">"),
whereClause = "oslc.where=" + serviceProviderFilter;
$.ajax({
url : "/oslc/rr/registration/collection?oslc.select=*&" + whereClause,
success : function(data, textStatus, jqXHR) {
regrRdf = $.rdf().load(data, {});
var regrRdfMatches = regrRdf
.prefix("rr", "http://jazz.net/ns/ism/registry#")
.prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
.where("?collection rdfs:member ?regRecord")
.where("?regRecord rr:sourceRecord ?sourceRecord");
if (regrRdfMatches.size() == 0) {
$(registrationDataJSId)
.replaceWith("<tbody id='registrationData'><tr>" +
"<td>No registration records for provider</td>" +
"<td/></tr>" +
"</tbody>");
} else {
var registrationHtmlStr =
"<tbody id='registrationData'>";
regrRdfMatches.each(function () {
var
rrUrl = this.regRecord.value,
sourceRecordUrl = this.sourceRecord.value;
registrationHtmlStr = registrationHtmlStr +
"<tr>" +
"<td><a href='" + rrUrl + "'>" + rrUrl + "</a></td>" +
"<td><a href='" + sourceRecordUrl + "'>" + sourceRecordUrl + "</a></td>" +
"</tr>";
});
registrationHtmlStr = registrationHtmlStr +
"</tbody>";
$(registrationDataJSId)
.replaceWith(registrationHtmlStr);
}
},
error: function(data, textStatus, jqXHR) {
alert(data.responseText);
},
dataType : "xml"
});
}
function displayResourceRecords(spUrl) {
var resourceDataDOMId = "resourceData";
var resourceDataJSId = "#resourceData";
$(resourceDataJSId)
.replaceWith("<tbody id='resourceData'><tr>" +
"<td>Fetching resource records...</td><td/><td/>" +
"</tr></tbody>");
var
serviceProviderFilter = encodeURI("rr:providerRecord{oslc:serviceProvider=<" +
spUrl + ">}"),
whereClause = "oslc.where=" + serviceProviderFilter;
$.ajax({
url : "/oslc/rr/collection?oslc.select=*&" + whereClause,
success : function(data, textStatus, jqXHR) {
rrRdf = $.rdf().load(data, {});
var rrRdfMatches = rrRdf
.prefix("dcterms", "http://purl.org/dc/terms/")
.prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
.where("?collection rdfs:member ?rr")
.where("?rr dcterms:modified ?time");
if (rrRdfMatches.size() == 0) {
$(resourceDataJSId)
.replaceWith("<tbody id='resourceData'><tr>" +
"<td>No resource records for provider</td>" +
"<td/><td/></tr>" +
"</tbody>");
} else {
var resourceRecordHtmlStr = "<tbody id='resourceData'>";
rrRdfMatches.each(function (i, bindings, rrTriples) {
var
rrUrl = this.rr.value,
modified = this.time.value;
var rrLinksCount = rrRdf
.prefix("rr", "http://jazz.net/ns/ism/registry#")
.where("<" + rrUrl + "> rr:providerRecord ?pr")
.size();
resourceRecordHtmlStr = resourceRecordHtmlStr + "<tr>" +
"<td><a href='" + rrUrl + "'>" + rrUrl + "</a></td>" +
"<td>" + modified + "</td>" +
"<td>" + rrLinksCount + "</td>" +
"</tr>";
});
resourceRecordHtmlStr = resourceRecordHtmlStr +
"</tbody>";
$(resourceDataJSId)
.replaceWith(resourceRecordHtmlStr);
}
},
error: function(data, textStatus, jqXHR) {
alert(data.responseText);
},
dataType : "xml"
});
}
function displayRecordsFromServiceProvider(spUrl) {
displayRegistrationRecords(spUrl);
displayResourceRecords(spUrl);
}
$.ajax({
url : "/oslc/pr/collection?oslc.select=*",
success : function(data, textStatus, jqXHR) {
spRdf = $.rdf().load(data, {});
spRdf
.prefix("dcterms", "http://purl.org/dc/terms/")
.prefix("rr", "http://jazz.net/ns/ism/registry#")
.where("?s a <http://open-services.net/ns/core#ServiceProvider>")
.optional("?s dcterms:title ?title")
.optional("?s dcterms:description ?description")
.optional("?s rr:sourceRecord ?sourceRecord")
.each(function () {
var
title = this.title === undefined ? "No title" : this.title.value,
description = this.description === undefined ? "No description" : this.description.value,
spUrl = this.s.value;
sourceRecordUrl = this.sourceRecord === undefined ? "" : this.sourceRecord.value;
$("#providersData")
.append("<tr>" +
"<td>" + title + "</td>" +
"<td>" + description + "</td>" +
"<td><a href='" + spUrl + "'>" + spUrl + "</a></td>" +
"<td><a href='" + sourceRecordUrl + "'>" + sourceRecordUrl + "</a></td>" +
"<td><a onclick='displayRecordsFromServiceProvider(\"" + spUrl +
"\")'><img src='images/action_go.gif'/></a></td>" +
"</tr>");
});
},
dataType : "xml"
});
</script>
</body>
</html>