This commit is contained in:
Andre Rodrigues 2012-04-17 19:10:36 -07:00
Родитель d04ee917f1
Коммит 2757f87233
2 изменённых файлов: 109 добавлений и 11 удалений

Просмотреть файл

@ -67,19 +67,22 @@ AtomHandler.prototype.parse = function (entityXml, innerTag) {
}
var propertiesXmlTag = this._xmlQualifyXmlTagName(innerTag, this.nsMeta);
if (entityXml.content && entityXml.content[propertiesXmlTag]) {
for (var property in entityXml.content[propertiesXmlTag]) {
if (property !== Constants.XML_METADATA_MARKER) {
var propertyName = property;
if (property.indexOf(this.nsData) !== -1) {
propertyName = property.substr(2, property.length - 2);
}
var propertyName = property;
if (azureutil.stringStartsWith(propertyName, this.nsData + ':')) {
propertyName = property.substr(2, property.length - 2);
}
if (property !== Constants.XML_METADATA_MARKER) {
if (azureutil.objectIsEmpty(entityXml.content[propertiesXmlTag][property])) {
// Empty properties are represented as an empty string.
entity[propertyName] = '';
} else if (entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER]) {
} else if (entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER] !== undefined &&
entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] &&
entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] === 'true') {
entity[propertyName] = null;
} else if (entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER] !== undefined) {
// Has an entry for value
if (entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER] &&
entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('type', this.nsMeta)]) {
@ -89,10 +92,6 @@ AtomHandler.prototype.parse = function (entityXml, innerTag) {
propertyName,
entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER],
entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('type', this.nsMeta)]);
} else if (entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER] &&
entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] &&
entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] === 'true') {
entity[propertyName] = null;
} else {
// The situation where a value marker exists and no type / null metadata marker exists shouldn't happen, but, just in case ...
entity[propertyName] = entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER];

Просмотреть файл

@ -144,4 +144,103 @@ suite('atomhandler-tests', function () {
done();
});
test('Parse', function (done) {
var atomHandler = new AtomHandler('m', 'd');
var entityXmlJs = {
title: '',
updated: '',
author: {
name: ''
},
id: '',
content: {
'@': {
type: 'application/xml'
},
'm:properties': {
'd:PartitionKey': 'part1',
'd:RowKey': 'row1',
'd:intValue': '10',
'd:stringValue': 'my string',
'd:nullValue': '',
'd:nullValue2': null
}
}
};
var entityResult = atomHandler.parse(entityXmlJs);
var entity = {
'PartitionKey': 'part1',
'RowKey': 'row1',
'intValue': '10',
'stringValue': 'my string',
'nullValue': '',
'nullValue2': ''
};
assert.deepEqual(entityResult, entity);
done();
});
test('ParseDataTypes', function (done) {
var atomHandler = new AtomHandler('m', 'd');
var entityXmlJs = {
title: '',
updated: '',
author: {
name: ''
},
id: '',
content: {
'@': {
type: 'application/xml'
},
'm:properties': {
'd:PartitionKey': {
'#': 'part1',
'@': { 'm:type': 'Edm.String' }
},
'd:RowKey': {
'#': 'row1',
'@': { 'm:type': 'Edm.String' }
},
'd:intValue': {
'#': '10',
'@': { 'm:type': 'Edm.Int32' }
},
'd:stringValue': {
'#': 'my string',
'@': { 'm:type': 'Edm.String' }
},
'd:nullValue': {
'#': '',
'@': { 'm:null': 'true' }
},
'd:nullValue2': {
'@': { 'm:null': 'true' }
}
}
}
};
var entityResult = atomHandler.parse(entityXmlJs);
var entity = {
'PartitionKey': 'part1',
'RowKey': 'row1',
'intValue': 10,
'stringValue': 'my string',
'nullValue': null,
'nullValue2': null
};
assert.deepEqual(entityResult, entity);
done();
});
});