Skip to content

Commit

Permalink
Allow setting the CoreProperties relationship ID
Browse files Browse the repository at this point in the history
New CoreProperties member: RelationshipID
  • Loading branch information
Manjon committed Oct 17, 2020
1 parent 46d9569 commit b7aa13e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *contentTypes) ensureOverridesMap() {
}
}

// Add needs a valid content type, else the behaviour is undefined
// Add needs a valid content type, else the behavior is undefined
func (c *contentTypes) add(partName, contentType string) error {
// Process descrived in ISO/IEC 29500-2 §10.1.2.3
t, params, _ := mime.ParseMediaType(contentType)
Expand Down Expand Up @@ -253,7 +253,8 @@ func (s w3CDateTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error {

// CoreProperties enable users to get and set well-known and common sets of property metadata within packages.
type CoreProperties struct {
PartName string // Won't be writed to the package, only used to indicate the location of the CoreProperties part. If empty the default location is "/props/core.xml".
PartName string // Won't be written to the package, only used to indicate the location of the CoreProperties part. If empty the default location is "/props/core.xml".
RelationshipID string // Won't be written to the package, only used to indicate the relationship ID for target "/props/core.xml".
Category string // A categorization of the content of this package.
ContentStatus string // The status of the content.
Created string // Date of creation of the resource.
Expand Down
2 changes: 1 addition & 1 deletion package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestCoreProperties_encode(t *testing.T) {
<category>A</category>
<lastPrinted xsi:type="dcterms:W3CDTF">b</lastPrinted>
`), false},
{"all", &CoreProperties{"partName", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"},
{"all", &CoreProperties{"partName", "rId1", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"},
buildCoreString(`
<category>a</category>
<contentStatus>b</contentStatus>
Expand Down
3 changes: 2 additions & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func (w *Writer) createCoreProperties() error {
if err != nil {
return err
}
w.Relationships = append(w.Relationships, &Relationship{"", corePropsRel, part.Name, ModeInternal})
w.Relationships = append(w.Relationships,
&Relationship{w.Properties.PartName, corePropsRel, part.Name, ModeInternal})
return w.Properties.encode(cw)
}

Expand Down
1 change: 1 addition & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestWriter_Close(t *testing.T) {
{"withDuplicatedRels", &Writer{p: pRel, w: zip.NewWriter(&bytes.Buffer{}), Properties: CoreProperties{Title: "Song"}, rnd: fakeRand()}, true},
{"withCoreProps", &Writer{p: newPackage(), w: zip.NewWriter(&bytes.Buffer{}), Properties: CoreProperties{Title: "Song"}, rnd: fakeRand()}, false},
{"withCorePropsWithName", &Writer{p: newPackage(), w: zip.NewWriter(&bytes.Buffer{}), Properties: CoreProperties{Title: "Song", PartName: "/props.xml"}, rnd: fakeRand()}, false},
{"withCorePropsWithNameAndId", &Writer{p: newPackage(), w: zip.NewWriter(&bytes.Buffer{}), Properties: CoreProperties{Title: "Song", PartName: "/docProps/props.xml", RelationshipID: "rId1"}, rnd: fakeRand()}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit b7aa13e

Please sign in to comment.