simplify core-properties; add xsd comment

This commit is contained in:
Tom Hunkapiller
2021-05-26 09:27:05 +03:00
parent 60b7ce4785
commit e4709a7f8d
5 changed files with 62 additions and 105 deletions

View File

@ -1,4 +1,4 @@
import { XmlComponent } from "file/xml-components";
import { StringContainer, XmlComponent } from "file/xml-components";
import { ICustomPropertyOptions } from "../custom-properties";
import { IDocumentBackgroundOptions } from "../document";
@ -7,7 +7,6 @@ import { ISectionOptions } from "../file";
import { INumberingOptions } from "../numbering";
import { Paragraph } from "../paragraph";
import { IStylesOptions } from "../styles";
import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components";
export interface IPropertiesOptions {
readonly sections: ISectionOptions[];
@ -36,6 +35,28 @@ export interface IPropertiesOptions {
readonly evenAndOddHeaderAndFooters?: boolean;
}
// <xs:element name="coreProperties" type="CT_CoreProperties"/>
// <xs:complexType name="CT_CoreProperties">
// <xs:all>
// <xs:element name="category" minOccurs="0" maxOccurs="1" type="xs:string"/>
// <xs:element name="contentStatus" minOccurs="0" maxOccurs="1" type="xs:string"/>
// <xs:element ref="dcterms:created" minOccurs="0" maxOccurs="1"/>
// <xs:element ref="dc:creator" minOccurs="0" maxOccurs="1"/>
// <xs:element ref="dc:description" minOccurs="0" maxOccurs="1"/>
// <xs:element ref="dc:identifier" minOccurs="0" maxOccurs="1"/>
// <xs:element name="keywords" minOccurs="0" maxOccurs="1" type="CT_Keywords"/>
// <xs:element ref="dc:language" minOccurs="0" maxOccurs="1"/>
// <xs:element name="lastModifiedBy" minOccurs="0" maxOccurs="1" type="xs:string"/>
// <xs:element name="lastPrinted" minOccurs="0" maxOccurs="1" type="xs:dateTime"/>
// <xs:element ref="dcterms:modified" minOccurs="0" maxOccurs="1"/>
// <xs:element name="revision" minOccurs="0" maxOccurs="1" type="xs:string"/>
// <xs:element ref="dc:subject" minOccurs="0" maxOccurs="1"/>
// <xs:element ref="dc:title" minOccurs="0" maxOccurs="1"/>
// <xs:element name="version" minOccurs="0" maxOccurs="1" type="xs:string"/>
// </xs:all>
// </xs:complexType>
export class CoreProperties extends XmlComponent {
constructor(options: Omit<IPropertiesOptions, "sections">) {
super("cp:coreProperties");
@ -49,27 +70,39 @@ export class CoreProperties extends XmlComponent {
}),
);
if (options.title) {
this.root.push(new Title(options.title));
this.root.push(new StringContainer("dc:title", options.title));
}
if (options.subject) {
this.root.push(new Subject(options.subject));
this.root.push(new StringContainer("dc:subject", options.subject));
}
if (options.creator) {
this.root.push(new Creator(options.creator));
this.root.push(new StringContainer("dc:creator", options.creator));
}
if (options.keywords) {
this.root.push(new Keywords(options.keywords));
this.root.push(new StringContainer("cp:keywords", options.keywords));
}
if (options.description) {
this.root.push(new Description(options.description));
this.root.push(new StringContainer("dc:description", options.description));
}
if (options.lastModifiedBy) {
this.root.push(new LastModifiedBy(options.lastModifiedBy));
this.root.push(new StringContainer("cp:lastModifiedBy", options.lastModifiedBy));
}
if (options.revision) {
this.root.push(new Revision(options.revision));
this.root.push(new StringContainer("cp:revision", options.revision));
}
this.root.push(new Created());
this.root.push(new Modified());
this.root.push(new TimestampElement("dcterms:created"));
this.root.push(new TimestampElement("dcterms:modified"));
}
}
class TimestampElement extends XmlComponent {
constructor(name: string) {
super(name);
this.root.push(
new DocumentAttributes({
type: "dcterms:W3CDTF",
}),
);
this.root.push(new Date().toISOString());
}
}