mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-29 13:49:10 +08:00
156 lines
3.5 KiB
Go
156 lines
3.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 spreadsheetml
|
||
|
|
||
|
import (
|
||
|
"encoding/xml"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type CT_Mdx struct {
|
||
|
// Connection Name Index
|
||
|
NAttr uint32
|
||
|
// Cube Function Tag
|
||
|
FAttr ST_MdxFunctionType
|
||
|
// Tuple MDX Metadata
|
||
|
T *CT_MdxTuple
|
||
|
// Set MDX Metadata
|
||
|
Ms *CT_MdxSet
|
||
|
// Member Property MDX Metadata
|
||
|
P *CT_MdxMemeberProp
|
||
|
// KPI MDX Metadata
|
||
|
K *CT_MdxKPI
|
||
|
}
|
||
|
|
||
|
func NewCT_Mdx() *CT_Mdx {
|
||
|
ret := &CT_Mdx{}
|
||
|
return ret
|
||
|
}
|
||
|
func (m *CT_Mdx) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||
|
if m == nil {
|
||
|
return nil
|
||
|
}
|
||
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "n"},
|
||
|
Value: fmt.Sprintf("%v", m.NAttr)})
|
||
|
attr, err := m.FAttr.MarshalXMLAttr(xml.Name{Local: "f"})
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
start.Attr = append(start.Attr, attr)
|
||
|
e.EncodeToken(start)
|
||
|
start.Attr = nil
|
||
|
if m.T != nil {
|
||
|
set := xml.StartElement{Name: xml.Name{Local: "x:t"}}
|
||
|
e.EncodeElement(m.T, set)
|
||
|
}
|
||
|
if m.Ms != nil {
|
||
|
sems := xml.StartElement{Name: xml.Name{Local: "x:ms"}}
|
||
|
e.EncodeElement(m.Ms, sems)
|
||
|
}
|
||
|
if m.P != nil {
|
||
|
sep := xml.StartElement{Name: xml.Name{Local: "x:p"}}
|
||
|
e.EncodeElement(m.P, sep)
|
||
|
}
|
||
|
if m.K != nil {
|
||
|
sek := xml.StartElement{Name: xml.Name{Local: "x:k"}}
|
||
|
e.EncodeElement(m.K, sek)
|
||
|
}
|
||
|
e.EncodeToken(xml.EndElement{Name: start.Name})
|
||
|
return nil
|
||
|
}
|
||
|
func (m *CT_Mdx) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||
|
// initialize to default
|
||
|
for _, attr := range start.Attr {
|
||
|
if attr.Name.Local == "n" {
|
||
|
parsed, err := strconv.ParseUint(attr.Value, 10, 32)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
m.NAttr = uint32(parsed)
|
||
|
}
|
||
|
if attr.Name.Local == "f" {
|
||
|
m.FAttr.UnmarshalXMLAttr(attr)
|
||
|
}
|
||
|
}
|
||
|
lCT_Mdx:
|
||
|
for {
|
||
|
tok, err := d.Token()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
switch el := tok.(type) {
|
||
|
case xml.StartElement:
|
||
|
switch el.Name.Local {
|
||
|
case "t":
|
||
|
m.T = NewCT_MdxTuple()
|
||
|
if err := d.DecodeElement(m.T, &el); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
case "ms":
|
||
|
m.Ms = NewCT_MdxSet()
|
||
|
if err := d.DecodeElement(m.Ms, &el); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
case "p":
|
||
|
m.P = NewCT_MdxMemeberProp()
|
||
|
if err := d.DecodeElement(m.P, &el); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
case "k":
|
||
|
m.K = NewCT_MdxKPI()
|
||
|
if err := d.DecodeElement(m.K, &el); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
default:
|
||
|
log.Printf("skipping unsupported element %v", el.Name)
|
||
|
if err := d.Skip(); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
case xml.EndElement:
|
||
|
break lCT_Mdx
|
||
|
case xml.CharData:
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
func (m *CT_Mdx) Validate() error {
|
||
|
return m.ValidateWithPath("CT_Mdx")
|
||
|
}
|
||
|
func (m *CT_Mdx) ValidateWithPath(path string) error {
|
||
|
if m.FAttr == ST_MdxFunctionTypeUnset {
|
||
|
return fmt.Errorf("%s/FAttr is a mandatory field", path)
|
||
|
}
|
||
|
if err := m.FAttr.ValidateWithPath(path + "/FAttr"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if m.T != nil {
|
||
|
if err := m.T.ValidateWithPath(path + "/T"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
if m.Ms != nil {
|
||
|
if err := m.Ms.ValidateWithPath(path + "/Ms"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
if m.P != nil {
|
||
|
if err := m.P.ValidateWithPath(path + "/P"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
if m.K != nil {
|
||
|
if err := m.K.ValidateWithPath(path + "/K"); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|