Commit a1ed09ad authored by Tristan Cavelier's avatar Tristan Cavelier

gidstorage useless class removed

parent b163ec2b
......@@ -125,110 +125,6 @@
content_type_re =
/^([a-z]+\/[a-zA-Z0-9\+\-\.]+)(?:\s*;\s*charset\s*=\s*([a-zA-Z0-9\-]+))?$/;
function Metadata(metadata) {
if (typeof metadata === 'object' && !Array.isArray(metadata)) {
this.metadata = metadata;
} else {
this.metadata = {};
}
Metadata.prototype.update.call(this, metadata);
}
Metadata.prototype.update = function (metadata) {
var k;
for (k in metadata) {
if (metadata.hasOwnProperty(k)) {
if (metadata[k] !== undefined) {
if (k[0] === '_') {
this.metadata[k] = JSON.parse(JSON.stringify(metadata[k]));
} else {
this.metadata[k] = Metadata.normalizeValue(metadata[k]);
}
}
}
}
return this;
};
Metadata.prototype.get = function (key) {
return this.metadata[key];
};
Metadata.prototype.set = function (key, value) {
if (value === undefined) {
delete this.metadata[key];
return this;
}
if (key[0] === '_') {
this.metadata[key] = value;
} else {
this.metadata[key] = Metadata.normalizeValue(value);
}
return this;
};
Metadata.normalizeArray = function (value) {
var i;
if (value.length === 0) {
return;
}
value = value.slice();
i = 0;
while (i < value.length) {
if (typeof value[i] === 'object' && !Array.isArray(value[i])) {
value[i] = Metadata.normalizeObject(value[i]);
if (value[i] === undefined) {
value.splice(i, 1);
} else {
i += 1;
}
} else if ((typeof value[i] === 'string') ||
(isNaN(value[i]) && typeof value[i] === 'number')) {
i += 1;
} else {
value.splice(i, 1);
}
}
if (value.length === 1) {
return value[0];
}
return value;
};
Metadata.normalizeObject = function (value) {
var i, count = 0, new_value = {};
for (i in value) {
if (value.hasOwnProperty(i)) {
if ((typeof value[i] === 'string') ||
(isNaN(value[i]) && typeof value[i] === 'number')) {
new_value[i] = value[i];
count += 1;
}
}
}
if (new_value.content === undefined) {
return;
}
if (count === 1) {
return new_value.content;
}
return new_value;
};
Metadata.normalizeValue = function (value) {
if ((typeof value === 'string') ||
(isNaN(value) && typeof value === 'number')) {
return value;
}
if (Array.isArray(value)) {
return Metadata.normalizeArray(value);
}
if (typeof value === 'object') {
return Metadata.normalizeObject(value);
}
};
/**
* Creates a gid from metadata and constraints.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment