ojp-sdk
Version:
OJP (Open Journey Planner) Javascript SDK
40 lines (39 loc) • 1.16 kB
JavaScript
import { Location } from "../../location/location";
import { BaseParser } from "../base-parser";
export class LocationInformationParser extends BaseParser {
constructor() {
super();
this.callback = null;
this.locations = [];
}
parseXML(responseXMLText) {
this.locations = [];
super.parseXML(responseXMLText);
}
onCloseTag(nodeName) {
if (nodeName === 'Location' && this.currentNode.parentName === 'OJPLocationInformationDelivery') {
const location = Location.initWithLocationResultTreeNode(this.currentNode);
if (location) {
this.locations.push(location);
}
}
}
onError(saxError) {
console.error('ERROR: SAX parser');
console.log(saxError);
if (this.callback) {
this.callback({
locations: this.locations,
message: 'ERROR',
});
}
}
onEnd() {
if (this.callback) {
this.callback({
locations: this.locations,
message: 'LocationInformation.DONE',
});
}
}
}