Middleware
WebCenter
The following example uses JQuery with the new WebCenter REST APIs released in PS3. The source for this example, implemented in JavaScript and html, is here. The source must be customized before use:
In this example, we get a list of existing group spaces and show some data about them. We provide a delete link for each group space. We also provide a form for making new group spaces from various templates. We use a JQuery plugin from www.datatables.net to display the data and one from trentrichardson.com (impromptu) to display messages. The displays are shown in the following screenshot:

The resourceIndex is a list of links that have resourceTypes and URL templates. Your code should hard code the resourceType, not the template. The URL template for the spaces API will give us a list of spaces (GET calls) and allow us to create new spaces (POST calls). In JQuery:
$.ajax({url: resourceIndex, dataType: "xml", username: username, password: password, success: function(xml) {
var link = $(xml).find("link[resourceType=urn:oracle:webcenter:spaces]");
spacesEndpoint = link.attr("template");
}
URL templates include all possible parameters. In some cases, we modify or remove parameters:
//we want a list of all spaces, so we remove the search parameter
spacesEndpoint = spacesEndpoint.replace('&search={search}', '');
//we'll ask for 20 spaces at a time
spacesEndpoint = spacesEndpoint.replace('{itemsPerPage}', '20');
//for making POSTs, we need to remove two other parameters from the template
spacesPOSTEndpoint = spacesEndpoint;
spacesPOSTEndpoint = spacesPOSTEndpoint.replace('&projection={projection}', '');
spacesPOSTEndpoint = spacesPOSTEndpoint.replace('&visibility={visibility}', '');
We now make a call to the Spaces API and display data from the response. In particular, we use the URL template with rel='self' as the basis for a delete link. In JQuery:
function drawSpacesList() {
$.ajax({url: spacesEndpoint, dataType: "xml", username: username, password: password, success: function(xml) {
var aaData = new Array();
var spaceListData = new Array();
$(xml).find("space").each(
function() {
var selfURLtemplate = $("//link[resourceType='urn:oracle:webcenter:space'][rel='self']", this).attr("template");
var deleteHref = "javascript:askDeleteSpace('" + selfURLtemplate + "')";
var deleteAnchor = '<a href="' + deleteHref + '">Delete</a>';
aaData.push(new Array($(this).children("displayName").text(),$(this).children("isPublic").text(),
$(this).children("isOffline").text(), deleteAnchor));
spaceListData.push(new Array($(this).children("displayName").text(), selfURLtemplate));
});
var oTable = $('#groupspaces').dataTable({
"bDestroy": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
oTable.fnClearTable();
oTable.fnAddData(aaData);
var spacelist = document.getElementById("space_list");
for (x in spaceListData) {
spacelist.innerHTML += ("" + spaceListData[x][0] + "");
}
}
});
}
The above iterates through each found space, extracts info, forms the call to the 'deleteHref' and redraws the table to display the data. The delete logic (note type: "delete") is:
function askDeleteSpace(deleteURL) {
currentDeleteURL = deleteURL;
$.prompt('Are you sure you want to delete this Space?',{ buttons: { Ok: true, Cancel: false }, callback: deleteSpace } );
}
function deleteSpace(v, m, f) { //the signature of the callback defined by impromptu
if (v = true) {
$.ajax({url: currentDeleteURL, type: "delete", username: username, password: password, success: drawSpacesList});
currentDeleteURL = "";
}
}
$.ajax({url: spacesTemplateEndpoint, dataType: "xml", username: username, password: password, success: function(xml) {
$(xml).find("template").each(
function() {
templateNames.push($(this).children("name").text());
});
var templateList = document.getElementById("template_list");
for (x in templateNames) {
//edit our "new space" form and add each template
templateList.innerHTML += ("" + templateNames[x] + "");
}
}
});
When a user submits data from the "Create Space" form, we format that data as xml and POST it in the body of the call to the spacesPOSTendpoint:
function createSpace(){
var nsform = document.getElementById("new_space_form");
var name = nsform.new_space_name.value;
var desc = nsform.new_space_desc.value;
var templateName = nsform.new_space_template.value;
var postBody = "<space><name>" + name + "</name><description>" + desc + "</description><templatename>" + templateName + "</templatename></space>";
$.ajax({url: spacesPOSTEndpoint, type: "post", contentType: "application/xml",
data: postBody, dataType: "xml", processData: false, username: username, password: password, success: drawSpacesList});
}
Let's assume you are running the sample code on your local apache server (localhost) and you want to create a localhost proxy for your WebCenter REST API. Follow these steps: