-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WdCT_WordprocessingContentPart.go
135 lines (127 loc) · 4.3 KB
/
WdCT_WordprocessingContentPart.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package wml
import (
"encoding/xml"
"fmt"
"go.devnw.com/ooxml"
"go.devnw.com/ooxml/schema/soo/dml"
)
type WdCT_WordprocessingContentPart struct {
BwModeAttr dml.ST_BlackWhiteMode
IdAttr string
NvContentPartPr *WdCT_WordprocessingContentPartNonVisual
Xfrm *dml.CT_Transform2D
ExtLst *dml.CT_OfficeArtExtensionList
}
func NewWdCT_WordprocessingContentPart() *WdCT_WordprocessingContentPart {
ret := &WdCT_WordprocessingContentPart{}
return ret
}
func (m *WdCT_WordprocessingContentPart) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m.BwModeAttr != dml.ST_BlackWhiteModeUnset {
attr, err := m.BwModeAttr.MarshalXMLAttr(xml.Name{Local: "bwMode"})
if err != nil {
return err
}
start.Attr = append(start.Attr, attr)
}
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "r:id"},
Value: fmt.Sprintf("%v", m.IdAttr)})
e.EncodeToken(start)
if m.NvContentPartPr != nil {
senvContentPartPr := xml.StartElement{Name: xml.Name{Local: "wp:nvContentPartPr"}}
e.EncodeElement(m.NvContentPartPr, senvContentPartPr)
}
if m.Xfrm != nil {
sexfrm := xml.StartElement{Name: xml.Name{Local: "wp:xfrm"}}
e.EncodeElement(m.Xfrm, sexfrm)
}
if m.ExtLst != nil {
seextLst := xml.StartElement{Name: xml.Name{Local: "wp:extLst"}}
e.EncodeElement(m.ExtLst, seextLst)
}
e.EncodeToken(xml.EndElement{Name: start.Name})
return nil
}
func (m *WdCT_WordprocessingContentPart) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
for _, attr := range start.Attr {
if attr.Name.Space == "http://schemas.openxmlformats.org/officeDocument/2006/relationships" && attr.Name.Local == "id" ||
attr.Name.Space == "http://purl.oclc.org/ooxml/officeDocument/relationships" && attr.Name.Local == "id" {
parsed, err := attr.Value, error(nil)
if err != nil {
return err
}
m.IdAttr = parsed
continue
}
if attr.Name.Local == "bwMode" {
m.BwModeAttr.UnmarshalXMLAttr(attr)
continue
}
}
lWdCT_WordprocessingContentPart:
for {
tok, err := d.Token()
if err != nil {
return err
}
switch el := tok.(type) {
case xml.StartElement:
switch el.Name {
case xml.Name{Space: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", Local: "nvContentPartPr"},
xml.Name{Space: "http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing", Local: "nvContentPartPr"}:
m.NvContentPartPr = NewWdCT_WordprocessingContentPartNonVisual()
if err := d.DecodeElement(m.NvContentPartPr, &el); err != nil {
return err
}
case xml.Name{Space: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", Local: "xfrm"},
xml.Name{Space: "http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing", Local: "xfrm"}:
m.Xfrm = dml.NewCT_Transform2D()
if err := d.DecodeElement(m.Xfrm, &el); err != nil {
return err
}
case xml.Name{Space: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", Local: "extLst"},
xml.Name{Space: "http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing", Local: "extLst"}:
m.ExtLst = dml.NewCT_OfficeArtExtensionList()
if err := d.DecodeElement(m.ExtLst, &el); err != nil {
return err
}
default:
office.Log("skipping unsupported element on WdCT_WordprocessingContentPart %v", el.Name)
if err := d.Skip(); err != nil {
return err
}
}
case xml.EndElement:
break lWdCT_WordprocessingContentPart
case xml.CharData:
}
}
return nil
}
// Validate validates the WdCT_WordprocessingContentPart and its children
func (m *WdCT_WordprocessingContentPart) Validate() error {
return m.ValidateWithPath("WdCT_WordprocessingContentPart")
}
// ValidateWithPath validates the WdCT_WordprocessingContentPart and its children, prefixing error messages with path
func (m *WdCT_WordprocessingContentPart) ValidateWithPath(path string) error {
if err := m.BwModeAttr.ValidateWithPath(path + "/BwModeAttr"); err != nil {
return err
}
if m.NvContentPartPr != nil {
if err := m.NvContentPartPr.ValidateWithPath(path + "/NvContentPartPr"); err != nil {
return err
}
}
if m.Xfrm != nil {
if err := m.Xfrm.ValidateWithPath(path + "/Xfrm"); err != nil {
return err
}
}
if m.ExtLst != nil {
if err := m.ExtLst.ValidateWithPath(path + "/ExtLst"); err != nil {
return err
}
}
return nil
}