69 lines
2.5 KiB
Go

// 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 chart
import (
"encoding/xml"
"fmt"
"baliance.com/gooxml/schema/schemas.openxmlformats.org/drawingml/2006/chartDrawing"
)
type UserShapes struct {
chartDrawing.CT_Drawing
}
func NewUserShapes() *UserShapes {
ret := &UserShapes{}
ret.CT_Drawing = *chartDrawing.NewCT_Drawing()
return ret
}
func (m *UserShapes) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if m == nil {
return nil
}
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns"}, Value: "http://schemas.openxmlformats.org/drawingml/2006/chart"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:a"}, Value: "http://schemas.openxmlformats.org/drawingml/2006/main"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:c"}, Value: "http://schemas.openxmlformats.org/drawingml/2006/chart"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:r"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/relationships"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:sh"}, Value: "http://schemas.openxmlformats.org/officeDocument/2006/sharedTypes"})
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "xmlns:xml"}, Value: "http://www.w3.org/XML/1998/namespace"})
start.Name.Local = "userShapes"
return m.CT_Drawing.MarshalXML(e, start)
}
func (m *UserShapes) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// initialize to default
m.CT_Drawing = *chartDrawing.NewCT_Drawing()
// skip any extensions we may find, but don't support
for {
tok, err := d.Token()
if err != nil {
return fmt.Errorf("parsing UserShapes: %s", err)
}
if el, ok := tok.(xml.EndElement); ok && el.Name == start.Name {
break
}
}
return nil
}
// Validate validates the UserShapes and its children
func (m *UserShapes) Validate() error {
return m.ValidateWithPath("UserShapes")
}
// ValidateWithPath validates the UserShapes and its children, prefixing error messages with path
func (m *UserShapes) ValidateWithPath(path string) error {
if err := m.CT_Drawing.ValidateWithPath(path); err != nil {
return err
}
return nil
}