2017-09-19 15:46:20 +01:00
|
|
|
import { BaseXmlComponent } from "./base";
|
|
|
|
import { IXmlableObject } from "./xmlable-object";
|
|
|
|
export { BaseXmlComponent };
|
|
|
|
|
|
|
|
export abstract class XmlComponent extends BaseXmlComponent {
|
2018-08-29 18:36:48 +03:00
|
|
|
public root: Array<BaseXmlComponent | string>;
|
2017-09-19 15:46:20 +01:00
|
|
|
|
2018-08-29 18:36:48 +03:00
|
|
|
constructor(rootKey: string, initContent? : XmlComponent) {
|
2017-09-19 15:46:20 +01:00
|
|
|
super(rootKey);
|
2018-08-29 18:36:48 +03:00
|
|
|
this.root = initContent ? initContent.root : new Array<BaseXmlComponent>();
|
2017-09-19 15:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public prepForXml(): IXmlableObject {
|
2018-01-23 01:33:12 +00:00
|
|
|
const children = this.root
|
2018-05-06 03:19:36 +01:00
|
|
|
.filter((c) => {
|
2018-04-26 14:16:02 +02:00
|
|
|
if (c instanceof BaseXmlComponent) {
|
2018-08-07 01:25:28 +01:00
|
|
|
return !c.IsDeleted;
|
2018-04-26 14:16:02 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
})
|
2018-01-23 01:33:12 +00:00
|
|
|
.map((comp) => {
|
|
|
|
if (comp instanceof BaseXmlComponent) {
|
|
|
|
return comp.prepForXml();
|
|
|
|
}
|
|
|
|
return comp;
|
|
|
|
})
|
2018-09-04 17:16:31 +03:00
|
|
|
.filter((comp) => comp !== null); // Exclude null, undefined, and empty strings
|
2017-09-19 15:46:20 +01:00
|
|
|
return {
|
|
|
|
[this.rootKey]: children,
|
|
|
|
};
|
|
|
|
}
|
2018-04-23 11:49:57 +02:00
|
|
|
|
2018-05-06 03:19:36 +01:00
|
|
|
// TODO: Unused method
|
|
|
|
public addChildElement(child: XmlComponent | string): XmlComponent {
|
2018-04-23 11:49:57 +02:00
|
|
|
this.root.push(child);
|
2018-05-06 03:19:36 +01:00
|
|
|
|
|
|
|
return this;
|
2018-04-23 11:49:57 +02:00
|
|
|
}
|
2018-04-26 14:16:02 +02:00
|
|
|
|
2018-05-06 03:19:36 +01:00
|
|
|
public delete(): void {
|
2018-04-26 14:16:02 +02:00
|
|
|
this.deleted = true;
|
|
|
|
}
|
2017-09-19 15:46:20 +01:00
|
|
|
}
|