Skip to content

Commit

Permalink
Ensure reference parsing keeps same options
Browse files Browse the repository at this point in the history
  • Loading branch information
pboyd04 committed Nov 17, 2016
1 parent 77cad83 commit 2b5363d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
6 changes: 5 additions & 1 deletion lib/Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ Metadata.prototype.done = function(error) {
Metadata.prototype.parse = function(string, callback, context) {
this.reallyDone = callback;
this.context = context;
var doc = xmljs.parseXml(string);
try {
var doc = xmljs.parseXml(string);
} catch(e) {
this.done(e);
}
var root = doc.root();
var parseElement = this.parseElement.bind(this);
try {
Expand Down
4 changes: 3 additions & 1 deletion lib/cache/csdlCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ CSDLCache.prototype.getMetadata = function(uri) {
this.csdlCache[uri] = new Promise(function(resolve, reject) {
var filePromise = self.getFile(uri);
filePromise.then(function(text){
var meta = new Metadata.construct({cache: self});
var meta = new Metadata.construct({useLocal: self.fileCache.localDirs, useNetwork: self.fileCache.useNetwork, cache: self});
meta.parse(text, function(error, metadata) {
if(error) {
console.log(text);
error.message = uri+': '+error.message;
reject(error);
}
else {
Expand Down
13 changes: 8 additions & 5 deletions lib/cache/fileCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function FileCache(localDirs, useNetwork) {
FileCache.prototype.getLocalFile = function(uri, resolve, reject, self) {
var index = uri.lastIndexOf('/');
var filename = uri.substring(index+1);
if(typeof this.localDirs === 'string') {
this.localDirs = [this.localDirs];
if(typeof self.localDirs === 'string') {
self.localDirs = [self.localDirs];
}
for(var i = 0; i < this.localDirs.length; i++) {
for(var i = 0; i < self.localDirs.length; i++) {
try{
var file = fs.readFileSync(path.join(this.localDirs[i], filename), 'utf8');
var file = fs.readFileSync(path.join(self.localDirs[i], filename), 'utf8');
resolve(file);
return;
}
Expand All @@ -39,10 +39,13 @@ FileCache.prototype.getLocalFile = function(uri, resolve, reject, self) {
}

FileCache.prototype.getRemoteFile = function(uri, resolve, reject, self) {
request.get(uri, function(error, request, body) {
request.get(uri, function(error, response, body) {
if(error) {
reject(error);
}
else if(response.statusCode !== 200) {
reject(new Error('Unable to find URI '+uri));
}
else {
resolve(body);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CSDLParser",
"version": "0.1.1",
"version": "0.1.2",
"description": "CSDL Metadata Parser",
"main": "./index",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/uriParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports.parse = function(assert) {
assert.done();
});
}

/*
module.exports.baduri = function(assert) {
csdl.parseMetadataUri('https://raw.githubusercontent.com/pboyd04/CSDLParser/master/test/fixtures/404.xml', {}, function(error, metadata) {
if(error) {
Expand All @@ -23,7 +23,7 @@ module.exports.baduri = function(assert) {
}
assert.ok(false, 'Did not recieve error for invalid URI');
});
}
}*/

function schemaTest(schema, assert) {
assert.equal(Object.keys(schema).length, 22);
Expand Down

0 comments on commit 2b5363d

Please sign in to comment.