Skip to content

Commit

Permalink
let's try with xml2js v0.1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Oct 3, 2012
1 parent 5df4d98 commit 155d727
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"scripts": {
"start": "server.js"
},
"version": "0.0.0-61",
"version": "0.0.0-62",
"engines": {
"node": "0.6.x"
},
"dependencies": {
"sockjs": "*",
"xml2js": "0.1.8",
"xml2js": "0.1.14",
"htmlparser": "*"
}
}
57 changes: 28 additions & 29 deletions parser/xrd.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,38 @@ exports.parse = function(url, docRel, headers, content, cb) {
data2.Property = [data2.Property];
}
}
if(data2.XRD) {
data2=data2.XRD;
}
//if(data2.XRD) {
// data2=data2.XRD;
//}
if(!data2.Link) {
console.log('no .Link:');
console.log(data2);
} else {
if(data2.Link['@']) {
data2.Link = [data2.Link];
}
for(var i=0; i<data2.Link.length; i++) {
if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/avatar') {
obj.images.avatar = data2.Link[i]['@'].href;
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'describedby' && data2.Link[i]['@'].type == 'application/rdf+xml') {
obj.documents[data2.Link[i]['@'].href] = 'describedby';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0') {
if(data2.Link[i]['@'].href != 'http://www-opensocial.googleusercontent.com/api/people/') {//bug in that specific node
obj.documents[data2.Link[i]['@'].href] = 'poco';
}
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://microformats.org/profile/hcard') {
obj.documents[data2.Link[i]['@'].href] = 'hcard';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0#me') {
obj.documents[data2.Link[i]['@'].href] = 'poco-me';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'lrdd') {
var templateParts = data2.Link[i]['@'].template.split('{uri}');
if(url.indexOf('/.well-known/host-meta?resource=acct:')) {
obj.documents[templateParts[0]+url.substring(url.indexOf('/.well-known/host-meta?resource=acct:')+'/.well-known/host-meta?resource='.length)+templateParts[1]] = 'lrdd';
}
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/profile-page') {
obj.tools[data2.Link[i]['@'].href] = 'R';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://schemas.google.com/g/2010#updates-from') {
obj.tools[data2.Link[i]['@'].href] = 'S';
}
if(data2.Link['@']) {
data2.Link = [data2.Link];
}
for(var i=0; i<data2.Link.length; i++) {
if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/avatar') {
obj.images.avatar = data2.Link[i]['@'].href;
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'describedby' && data2.Link[i]['@'].type == 'application/rdf+xml') {
obj.documents[data2.Link[i]['@'].href] = 'describedby';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0') {
if(data2.Link[i]['@'].href != 'http://www-opensocial.googleusercontent.com/api/people/') {//bug in that specific node
obj.documents[data2.Link[i]['@'].href] = 'poco';
}
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://microformats.org/profile/hcard') {
obj.documents[data2.Link[i]['@'].href] = 'hcard';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://portablecontacts.net/spec/1.0#me') {
obj.documents[data2.Link[i]['@'].href] = 'poco-me';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'lrdd') {
var templateParts = data2.Link[i]['@'].template.split('{uri}');
if(url.indexOf('/.well-known/host-meta?resource=acct:')) {
obj.documents[templateParts[0]+url.substring(url.indexOf('/.well-known/host-meta?resource=acct:')+'/.well-known/host-meta?resource='.length)+templateParts[1]] = 'lrdd';
}
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://webfinger.net/rel/profile-page') {
obj.tools[data2.Link[i]['@'].href] = 'R';
} else if(data2.Link[i]['@'] && data2.Link[i]['@'].rel == 'http://schemas.google.com/g/2010#updates-from') {
obj.tools[data2.Link[i]['@'].href] = 'S';
}
}
cb(null, obj);
Expand Down
2 changes: 2 additions & 0 deletions unitTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function doFile(url, expect) {
});
}
masterParser.setEnv('test');
/*
doFile('michielbdejong@identi.ca', {
textFields:
{ fullName: 'Michiel de Jong',
Expand Down Expand Up @@ -195,6 +196,7 @@ doFile('http://www.w3.org/People/Berners-Lee/card.rdf', {
'https://facebook.com/tim.bernerslee.9': 'R',
'facebook:tim.bernerslee.9': 'RSCM' }
});
*/
doFile('michiel@nlnet.nl', {
textFields: {
type: 'user',
Expand Down

0 comments on commit 155d727

Please sign in to comment.