93 lines
2.3 KiB
Go
Raw Normal View History

2017-08-28 20:56:18 -05:00
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package chartDrawing
import (
"encoding/xml"
"fmt"
"log"
)
type CT_Drawing struct {
EG_Anchor []*EG_Anchor
}
func NewCT_Drawing() *CT_Drawing {
ret := &CT_Drawing{}
return ret
}
2017-08-28 20:56:18 -05:00
func (m *CT_Drawing) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m == nil {
return nil
}
start.Name.Local = "CT_Drawing"
e.EncodeToken(start)
if m.EG_Anchor != nil {
for _, c := range m.EG_Anchor {
c.MarshalXML(e, start)
}
}
e.EncodeToken(xml.EndElement{Name: start.Name})
return nil
}
2017-08-28 20:56:18 -05:00
func (m *CT_Drawing) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
lCT_Drawing:
for {
tok, err := d.Token()
if err != nil {
return err
}
switch el := tok.(type) {
case xml.StartElement:
switch el.Name.Local {
case "relSizeAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.RelSizeAnchor = NewCT_RelSizeAnchor()
if err := d.DecodeElement(tmpanchor.RelSizeAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
case "absSizeAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.AbsSizeAnchor = NewCT_AbsSizeAnchor()
if err := d.DecodeElement(tmpanchor.AbsSizeAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
default:
log.Printf("skipping unsupported element %v", el.Name)
if err := d.Skip(); err != nil {
return err
}
}
case xml.EndElement:
break lCT_Drawing
case xml.CharData:
}
}
return nil
}
// Validate validates the CT_Drawing and its children
2017-08-28 20:56:18 -05:00
func (m *CT_Drawing) Validate() error {
return m.ValidateWithPath("CT_Drawing")
}
// ValidateWithPath validates the CT_Drawing and its children, prefixing error messages with path
2017-08-28 20:56:18 -05:00
func (m *CT_Drawing) ValidateWithPath(path string) error {
for i, v := range m.EG_Anchor {
if err := v.ValidateWithPath(fmt.Sprintf("%s/EG_Anchor[%d]", path, i)); err != nil {
return err
}
}
return nil
}