2016-04-25 03:28:02 +01:00
|
|
|
import * as _ from "lodash";
|
|
|
|
|
2016-04-21 23:27:46 +01:00
|
|
|
export abstract class BaseXmlComponent {
|
2016-04-09 20:16:35 +01:00
|
|
|
protected rootKey: string;
|
|
|
|
|
|
|
|
constructor(rootKey: string) {
|
|
|
|
this.rootKey = rootKey;
|
|
|
|
}
|
2016-04-10 05:09:02 +01:00
|
|
|
|
2016-04-21 23:27:46 +01:00
|
|
|
abstract replaceKey(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export abstract class XmlComponent extends BaseXmlComponent {
|
|
|
|
protected root: Array<BaseXmlComponent>;
|
|
|
|
|
|
|
|
constructor(rootKey: string) {
|
|
|
|
super(rootKey);
|
|
|
|
this.root = new Array<BaseXmlComponent>();
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceKey(): void {
|
|
|
|
//console.log(this.rootKey);
|
|
|
|
//console.log(this.root);
|
2016-04-10 05:09:02 +01:00
|
|
|
if (this.root !== undefined) {
|
|
|
|
this.root.forEach(root => {
|
|
|
|
root.replaceKey();
|
|
|
|
});
|
2016-04-21 23:27:46 +01:00
|
|
|
this[this.rootKey] = this.root;
|
|
|
|
delete this.root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export abstract class XmlUnitComponent extends BaseXmlComponent {
|
|
|
|
protected root: string;
|
|
|
|
|
|
|
|
constructor(rootKey: string) {
|
|
|
|
super(rootKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceKey(): void {
|
|
|
|
if (this.root !== undefined) {
|
|
|
|
this[this.rootKey] = this.root;
|
|
|
|
delete this.root;
|
2016-04-10 05:09:02 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-28 03:55:33 +01:00
|
|
|
}
|
|
|
|
|
2016-04-25 03:28:02 +01:00
|
|
|
export abstract class XmlAttributeComponent extends BaseXmlComponent {
|
|
|
|
protected root: Object;
|
|
|
|
private xmlKeys: Object;
|
|
|
|
|
|
|
|
constructor(xmlKeys: Object) {
|
|
|
|
super("_attr");
|
|
|
|
this.xmlKeys = xmlKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceKey(): void {
|
|
|
|
if (this.root !== undefined) {
|
|
|
|
_.forOwn(this.root, (value, key) => {
|
|
|
|
var newKey = this.xmlKeys[key];
|
|
|
|
this.root[newKey] = value;
|
|
|
|
delete this.root[key];
|
|
|
|
});
|
|
|
|
this[this.rootKey] = this.root;
|
|
|
|
delete this.root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 04:50:23 +01:00
|
|
|
interface AttributesProperties {
|
2016-03-30 02:55:11 +01:00
|
|
|
val?: any;
|
2016-03-29 04:50:23 +01:00
|
|
|
color?: string;
|
|
|
|
space?: string;
|
|
|
|
sz?: string;
|
2016-03-30 00:28:05 +01:00
|
|
|
type?: string;
|
2016-03-31 23:01:20 +01:00
|
|
|
rsidR?: string;
|
|
|
|
rsidRPr?: string;
|
|
|
|
rsidSect?: string;
|
|
|
|
w?: string;
|
|
|
|
h?: string;
|
2016-04-03 05:23:13 +01:00
|
|
|
top?: string;
|
|
|
|
right?: string;
|
|
|
|
bottom?: string;
|
|
|
|
left?: string;
|
|
|
|
header?: string;
|
|
|
|
footer?: string;
|
|
|
|
gutter?: string;
|
|
|
|
linePitch?: string;
|
2016-03-29 04:50:23 +01:00
|
|
|
}
|
|
|
|
|
2016-04-25 03:28:02 +01:00
|
|
|
export class Attributes extends XmlAttributeComponent {
|
2016-04-03 01:44:18 +01:00
|
|
|
|
2016-03-29 04:50:23 +01:00
|
|
|
constructor(properties?: AttributesProperties) {
|
2016-04-25 03:28:02 +01:00
|
|
|
super({
|
|
|
|
val: "w:val",
|
|
|
|
color: "w:color",
|
|
|
|
space: "w:space",
|
|
|
|
sz: "w:sz",
|
|
|
|
type: "w:type",
|
|
|
|
rsidR: "w:rsidR",
|
|
|
|
rsidRPr: "w:rsidRPr",
|
|
|
|
rsidSect: "w:rsidSect",
|
|
|
|
w: "w:w",
|
|
|
|
h: "w:h",
|
|
|
|
top: "w:top",
|
|
|
|
right: "w:right",
|
|
|
|
bottom: "w:bottom",
|
|
|
|
left: "w:left",
|
|
|
|
header: "w:header",
|
|
|
|
footer: "w:footer",
|
|
|
|
gutter: "w:gutter",
|
|
|
|
linePitch: "w:linePitch"
|
|
|
|
});
|
|
|
|
this.root = properties
|
2016-03-29 22:55:37 +01:00
|
|
|
|
2016-03-29 04:50:23 +01:00
|
|
|
if (!properties) {
|
2016-04-25 03:28:02 +01:00
|
|
|
this.root = {};
|
2016-03-29 04:50:23 +01:00
|
|
|
}
|
2016-03-28 03:55:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:27:46 +01:00
|
|
|
export class Text extends XmlUnitComponent {
|
2016-04-03 01:44:18 +01:00
|
|
|
|
2016-03-28 03:55:33 +01:00
|
|
|
constructor(text: string) {
|
2016-04-21 23:27:46 +01:00
|
|
|
super("w:t"); //need special xml component
|
|
|
|
this.root = text;
|
2016-03-28 03:55:33 +01:00
|
|
|
}
|
|
|
|
}
|