schema: remove support for multiple drawing anchors

The OOXML XSD allows it, but I don't see a need for it and
it makes the code more complex keeping it.
This commit is contained in:
Todd 2017-09-03 18:53:56 -05:00
parent f959cb0c9f
commit 704a4c6963
3 changed files with 58 additions and 48 deletions

View File

@ -9,12 +9,12 @@ package chartDrawing
import (
"encoding/xml"
"fmt"
"log"
)
type CT_Drawing struct {
EG_Anchor []*EG_Anchor
RelSizeAnchor *CT_RelSizeAnchor
AbsSizeAnchor *CT_AbsSizeAnchor
}
func NewCT_Drawing() *CT_Drawing {
@ -25,10 +25,13 @@ func NewCT_Drawing() *CT_Drawing {
func (m *CT_Drawing) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Name.Local = "CT_Drawing"
e.EncodeToken(start)
if m.EG_Anchor != nil {
for _, c := range m.EG_Anchor {
c.MarshalXML(e, start)
}
if m.RelSizeAnchor != nil {
serelSizeAnchor := xml.StartElement{Name: xml.Name{Local: "relSizeAnchor"}}
e.EncodeElement(m.RelSizeAnchor, serelSizeAnchor)
}
if m.AbsSizeAnchor != nil {
seabsSizeAnchor := xml.StartElement{Name: xml.Name{Local: "absSizeAnchor"}}
e.EncodeElement(m.AbsSizeAnchor, seabsSizeAnchor)
}
e.EncodeToken(xml.EndElement{Name: start.Name})
return nil
@ -46,19 +49,15 @@ lCT_Drawing:
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 {
m.RelSizeAnchor = NewCT_RelSizeAnchor()
if err := d.DecodeElement(m.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 {
m.AbsSizeAnchor = NewCT_AbsSizeAnchor()
if err := d.DecodeElement(m.AbsSizeAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
default:
log.Printf("skipping unsupported element on CT_Drawing %v", el.Name)
if err := d.Skip(); err != nil {
@ -80,8 +79,13 @@ func (m *CT_Drawing) Validate() error {
// ValidateWithPath validates the CT_Drawing and its children, prefixing error messages with path
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 {
if m.RelSizeAnchor != nil {
if err := m.RelSizeAnchor.ValidateWithPath(path + "/RelSizeAnchor"); err != nil {
return err
}
}
if m.AbsSizeAnchor != nil {
if err := m.AbsSizeAnchor.ValidateWithPath(path + "/AbsSizeAnchor"); err != nil {
return err
}
}

View File

@ -9,12 +9,13 @@ package spreadsheetDrawing
import (
"encoding/xml"
"fmt"
"log"
)
type CT_Drawing struct {
EG_Anchor []*EG_Anchor
TwoCellAnchor *CT_TwoCellAnchor
OneCellAnchor *CT_OneCellAnchor
AbsoluteAnchor *CT_AbsoluteAnchor
}
func NewCT_Drawing() *CT_Drawing {
@ -24,10 +25,17 @@ func NewCT_Drawing() *CT_Drawing {
func (m *CT_Drawing) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
e.EncodeToken(start)
if m.EG_Anchor != nil {
for _, c := range m.EG_Anchor {
c.MarshalXML(e, start)
}
if m.TwoCellAnchor != nil {
setwoCellAnchor := xml.StartElement{Name: xml.Name{Local: "xdr:twoCellAnchor"}}
e.EncodeElement(m.TwoCellAnchor, setwoCellAnchor)
}
if m.OneCellAnchor != nil {
seoneCellAnchor := xml.StartElement{Name: xml.Name{Local: "xdr:oneCellAnchor"}}
e.EncodeElement(m.OneCellAnchor, seoneCellAnchor)
}
if m.AbsoluteAnchor != nil {
seabsoluteAnchor := xml.StartElement{Name: xml.Name{Local: "xdr:absoluteAnchor"}}
e.EncodeElement(m.AbsoluteAnchor, seabsoluteAnchor)
}
e.EncodeToken(xml.EndElement{Name: start.Name})
return nil
@ -45,26 +53,20 @@ lCT_Drawing:
case xml.StartElement:
switch el.Name.Local {
case "twoCellAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.TwoCellAnchor = NewCT_TwoCellAnchor()
if err := d.DecodeElement(tmpanchor.TwoCellAnchor, &el); err != nil {
m.TwoCellAnchor = NewCT_TwoCellAnchor()
if err := d.DecodeElement(m.TwoCellAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
case "oneCellAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.OneCellAnchor = NewCT_OneCellAnchor()
if err := d.DecodeElement(tmpanchor.OneCellAnchor, &el); err != nil {
m.OneCellAnchor = NewCT_OneCellAnchor()
if err := d.DecodeElement(m.OneCellAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
case "absoluteAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.AbsoluteAnchor = NewCT_AbsoluteAnchor()
if err := d.DecodeElement(tmpanchor.AbsoluteAnchor, &el); err != nil {
m.AbsoluteAnchor = NewCT_AbsoluteAnchor()
if err := d.DecodeElement(m.AbsoluteAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
default:
log.Printf("skipping unsupported element on CT_Drawing %v", el.Name)
if err := d.Skip(); err != nil {
@ -86,8 +88,18 @@ func (m *CT_Drawing) Validate() error {
// ValidateWithPath validates the CT_Drawing and its children, prefixing error messages with path
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 {
if m.TwoCellAnchor != nil {
if err := m.TwoCellAnchor.ValidateWithPath(path + "/TwoCellAnchor"); err != nil {
return err
}
}
if m.OneCellAnchor != nil {
if err := m.OneCellAnchor.ValidateWithPath(path + "/OneCellAnchor"); err != nil {
return err
}
}
if m.AbsoluteAnchor != nil {
if err := m.AbsoluteAnchor.ValidateWithPath(path + "/AbsoluteAnchor"); err != nil {
return err
}
}

View File

@ -45,26 +45,20 @@ lWsDr:
case xml.StartElement:
switch el.Name.Local {
case "twoCellAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.TwoCellAnchor = NewCT_TwoCellAnchor()
if err := d.DecodeElement(tmpanchor.TwoCellAnchor, &el); err != nil {
m.TwoCellAnchor = NewCT_TwoCellAnchor()
if err := d.DecodeElement(m.TwoCellAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
case "oneCellAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.OneCellAnchor = NewCT_OneCellAnchor()
if err := d.DecodeElement(tmpanchor.OneCellAnchor, &el); err != nil {
m.OneCellAnchor = NewCT_OneCellAnchor()
if err := d.DecodeElement(m.OneCellAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
case "absoluteAnchor":
tmpanchor := NewEG_Anchor()
tmpanchor.AbsoluteAnchor = NewCT_AbsoluteAnchor()
if err := d.DecodeElement(tmpanchor.AbsoluteAnchor, &el); err != nil {
m.AbsoluteAnchor = NewCT_AbsoluteAnchor()
if err := d.DecodeElement(m.AbsoluteAnchor, &el); err != nil {
return err
}
m.EG_Anchor = append(m.EG_Anchor, tmpanchor)
default:
log.Printf("skipping unsupported element on WsDr %v", el.Name)
if err := d.Skip(); err != nil {