/*
-** $Id: pz2.js,v 1.61 2007-10-02 11:47:50 jakub Exp $
+** $Id: pz2.js,v 1.66 2007-11-13 12:51:29 jakub Exp $
** pz2.js - pazpar2's javascript client library.
*/
// at least one callback required
if ( !paramArray )
- throw new Error("Pz2.js: An array with parameters has to be suplied when instantiating a class");
+ throw new Error("Pz2.js: Array with parameters has to be suplied.");
//supported pazpar2's protocol version
this.suppProtoVer = '1';
this.errorHandler = paramArray.errorhandler || null;
// function callbacks
+ this.initCallback = paramArray.oninit || null;
this.statCallback = paramArray.onstat || null;
this.showCallback = paramArray.onshow || null;
this.termlistCallback = paramArray.onterm || null;
if ( data.getElementsByTagName("protocol")[0]
.childNodes[0].nodeValue
!= context.suppProtoVer )
- throw new Error("Server's protocol not supported by the client");
+ throw new Error(
+ "Server's protocol not supported by the client"
+ );
context.initStatusOK = true;
context.sessionID =
data.getElementsByTagName("session")[0]
},
context.keepAlive
);
+ if ( context.initCallback )
+ context.initCallback();
}
else
context.throwError('Init failed. Malformed WS resonse.',
{
// pinging only makes sense when using pazpar2 directly
if( !this.initStatusOK || !this.useSessions )
- throw new Error('Pz2.js: Ping not allowed (proxy mode) or session not initialized.');
- // session is not initialized code here
-
+ throw new Error(
+ 'Pz2.js: Ping not allowed (proxy mode) or session not initialized.'
+ );
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
request.get(
show: function(start, num, sort)
{
if( !this.searchStatusOK && this.useSessions )
- throw new Error('Pz2.js: show command has to be preceded with a search command.');
+ throw new Error(
+ 'Pz2.js: show command has to be preceded with a search command.'
+ );
// if called explicitly takes precedence
clearTimeout(this.showTimer);
for (i = 0; i < hits.length; i++) {
show.hits[i] = new Array();
show.hits[i]['location'] = new Array();
+ var locCount = 0;
for ( j = 0; j < hits[i].childNodes.length; j++) {
- var locCount = 0;
if ( hits[i].childNodes[j].nodeType
== Node.ELEMENT_NODE ) {
if (hits[i].childNodes[j].nodeName
== 'location') {
var locNode = hits[i].childNodes[j];
var id = locNode.getAttribute('id');
- show.hits[i]['location'][id] = {
+ show.hits[i]['location'][locCount] = {
"id": locNode.getAttribute("id"),
"name": locNode.getAttribute("name")
};
+ locCount++;
}
else {
var nodeName =
!= 'location' ) {
var nodeName =
recordNode.childNodes[i].nodeName;
- var nodeText =
- recordNode.childNodes[i]
+ var nodeText = '';
+ if (recordNode.childNodes[i].firstChild)
+ nodeText = recordNode.childNodes[i]
.firstChild.nodeValue;
record[nodeName] = nodeText;
}
"name": locationNodes[i].getAttribute("name")
};
- for ( j = 0; j < locationNodes[i].childNodes.length; j++) {
+ for (j = 0;
+ j < locationNodes[i].childNodes.length;
+ j++) {
if ( locationNodes[i].childNodes[j].nodeType
== Node.ELEMENT_NODE ) {
var nodeName =
nodeText =
locationNodes[i].childNodes[j]
.firstChild.nodeValue;
- record["location"][i][nodeName] = nodeText;
+ // this is stupid
+ if (nodeName == 'md-subject') {
+ if (record["location"][i]['nodeName']) {
+ record["location"][i][nodeName]
+ .push(nodeText)
+ } else {
+ record["location"][i][nodeName]
+ = new Array();
+ record["location"][i][nodeName]
+ .push(nodeText)
+ }
+ } else {
+ record["location"][i][nodeName]
+ = nodeText;
+ }
}
}
}
termlist: function()
{
if( !this.searchStatusOK && this.useSessions )
- throw new Error('Pz2.js: termlist command has to be preceded with a search command.');
+ throw new Error(
+ 'Pz2.js: termlist command has to be preceded with a search command.'
+ );
// if called explicitly takes precedence
clearTimeout(this.termTimer);
bytarget: function()
{
if( !this.initStatusOK && this.useSessions )
- throw new Error('Pz2.js: bytarget command has to be preceded with a search command.');
+ throw new Error(
+ 'Pz2.js: bytarget command has to be preceded with a search command.'
+ );
// no need to continue
if( !this.searchStatusOK )
// pick up pazpr2 errors first
if ( this.request.responseXML
&& this.request.responseXML.documentElement.nodeName == 'error'
- && this.request.responseXML.getElementsByTagName("error").length ) {
+ && this.request.responseXML.getElementsByTagName("error")
+ .length ) {
var errAddInfo = '';
- if ( this.request.responseXML.getElementsByTagName("error")[0].childNodes.length )
- errAddInfo = ': ' + this.request.responseXML.getElementsByTagName("error")[0].childNodes[0].nodeValue;
- var errMsg = this.request.responseXML.getElementsByTagName("error")[0].getAttribute("msg");
- var errCode = this.request.responseXML.getElementsByTagName("error")[0].getAttribute("code");
+ if ( this.request.responseXML.getElementsByTagName("error")[0]
+ .childNodes.length )
+ errAddInfo = ': ' +
+ this.request.responseXML
+ .getElementsByTagName("error")[0]
+ .childNodes[0].nodeValue;
+ var errMsg =
+ this.request.responseXML.getElementsByTagName("error")[0]
+ .getAttribute("msg");
+ var errCode =
+ this.request.responseXML.getElementsByTagName("error")[0]
+ .getAttribute("code");
var err = new Error(errMsg + errAddInfo);
err.code = errCode;
};
/*
-*********************************************************************************
-** XML HELPER CLASS ************************************************************
-*********************************************************************************
+********************************************************************************
+** XML HELPER FUNCTIONS ********************************************************
+********************************************************************************
*/
// DOMDocument
}
}
+/* do not remove trailing bracket */
}