2016-05-23 22:23:05 +01:00
|
|
|
import * as _ from "lodash";
|
2017-03-08 21:49:41 +00:00
|
|
|
import { BaseXmlComponent } from "./base";
|
2016-05-20 00:40:31 +01:00
|
|
|
|
|
|
|
export abstract class XmlAttributeComponent extends BaseXmlComponent {
|
|
|
|
protected root: Object;
|
|
|
|
private xmlKeys: Object;
|
|
|
|
|
|
|
|
constructor(xmlKeys: Object, properties: Object) {
|
|
|
|
super("_attr");
|
|
|
|
this.xmlKeys = xmlKeys;
|
|
|
|
|
2016-05-26 15:08:34 +01:00
|
|
|
this.root = properties;
|
2016-05-20 00:40:31 +01:00
|
|
|
|
|
|
|
if (!properties) {
|
|
|
|
this.root = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 21:49:41 +00:00
|
|
|
public replaceKey(): void {
|
2016-05-20 00:40:31 +01:00
|
|
|
if (this.root !== undefined) {
|
|
|
|
_.forOwn(this.root, (value, key) => {
|
2017-03-08 21:49:41 +00:00
|
|
|
const newKey = this.xmlKeys[key];
|
2016-05-20 00:40:31 +01:00
|
|
|
this.root[newKey] = value;
|
|
|
|
delete this.root[key];
|
|
|
|
});
|
|
|
|
this[this.rootKey] = this.root;
|
|
|
|
delete this.root;
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 21:49:41 +00:00
|
|
|
}
|