-
Notifications
You must be signed in to change notification settings - Fork 0
/
word.go
69 lines (62 loc) · 1.99 KB
/
word.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package resource
import (
"path"
)
/*
Represents a word resource object that is created using the word file and a name.
*/
type WordResource struct {
Resource
inputFileExtension string
resourceName string
resource string
}
/*
Initializes a new instance of the `wordResource` class with word file path and resource name.
- @param {string} word The word file path.
- @param {string} resourceName The name of the resource.
*/
func NewWordResourceWithResourcePath(resource string, resourceName string) WordResource {
var ep WordResource
ep.setFilepath(resource)
ep.typeOfResource = ep.ResourceType()
ep = WordResource{Resource: NewResourceWithPath(resource, resourceName)}
ep.fileExtension()
return ep
}
/*
Initializes a new instance of the `WordResource` class.
- @param {Byte[]} The byte array of the Word file.
- @param {string} resourceName The name of the resource.
*/
func NewWordResourceWithByteValue(resource []byte, resourceName string) WordResource {
var ep WordResource
ep.typeOfResource = ep.ResourceType()
ep = WordResource{Resource: *NewResourceWithByteValue(resource, resourceName)}
return ep
}
func (p WordResource) ResourceType() ResourceType {
return WordResourceType
}
func (p *WordResource) fileExtension() string {
p.inputFileExtension = ""
if p.ResourceName != "" {
p.inputFileExtension = path.Ext(p.ResourceName)
} else if p.filepath1 != "" {
p.inputFileExtension = path.Ext(p.filepath1)
} else {
panic("Invalid path or resource name.")
}
if p.inputFileExtension == ".doc" {
p.setMimeType("application/msword")
return ".doc"
} else if p.inputFileExtension == ".docx" && p.data[0] == 0x50 && p.data[1] == 0x4b {
p.setMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
return ".docx"
} else if p.inputFileExtension == ".odt" && p.data[0] == 0x50 && p.data[1] == 0x4b {
p.setMimeType("application/vnd.oasis.opendocument.text")
return ".odt"
} else {
panic("Unsupported file type or invalid file extension.")
}
}