mirror of
https://github.com/unidoc/unioffice.git
synced 2025-05-01 13:48:55 +08:00

These are implied values as they are the defaults in the XSD for optional attributes/elements. However I've noticed that I keep running into issues where Mac Excel/Word fail to open a file unless an optional default is provided. I'll just add them all to hopefully increase compatibility and save painful file format debugging sessions later.
152 lines
4.2 KiB
Go
152 lines
4.2 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"
|
|
"strconv"
|
|
|
|
"baliance.com/gooxml"
|
|
)
|
|
|
|
type CT_FileSharing struct {
|
|
// Read Only Recommended
|
|
ReadOnlyRecommendedAttr *bool
|
|
// User Name
|
|
UserNameAttr *string
|
|
// Write Reservation Password
|
|
ReservationPasswordAttr *string
|
|
// Cryptographic Algorithm Name
|
|
AlgorithmNameAttr *string
|
|
// Password Hash Value
|
|
HashValueAttr *string
|
|
// Salt Value for Password Verifier
|
|
SaltValueAttr *string
|
|
// Iterations to Run Hashing Algorithm
|
|
SpinCountAttr *uint32
|
|
}
|
|
|
|
func NewCT_FileSharing() *CT_FileSharing {
|
|
ret := &CT_FileSharing{}
|
|
ret.ReadOnlyRecommendedAttr = gooxml.Bool(false)
|
|
return ret
|
|
}
|
|
|
|
func (m *CT_FileSharing) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
if m.ReadOnlyRecommendedAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "readOnlyRecommended"},
|
|
Value: fmt.Sprintf("%d", b2i(*m.ReadOnlyRecommendedAttr))})
|
|
}
|
|
if m.UserNameAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "userName"},
|
|
Value: fmt.Sprintf("%v", *m.UserNameAttr)})
|
|
}
|
|
if m.ReservationPasswordAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "reservationPassword"},
|
|
Value: fmt.Sprintf("%v", *m.ReservationPasswordAttr)})
|
|
}
|
|
if m.AlgorithmNameAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "algorithmName"},
|
|
Value: fmt.Sprintf("%v", *m.AlgorithmNameAttr)})
|
|
}
|
|
if m.HashValueAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "hashValue"},
|
|
Value: fmt.Sprintf("%v", *m.HashValueAttr)})
|
|
}
|
|
if m.SaltValueAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "saltValue"},
|
|
Value: fmt.Sprintf("%v", *m.SaltValueAttr)})
|
|
}
|
|
if m.SpinCountAttr != nil {
|
|
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "spinCount"},
|
|
Value: fmt.Sprintf("%v", *m.SpinCountAttr)})
|
|
}
|
|
e.EncodeToken(start)
|
|
e.EncodeToken(xml.EndElement{Name: start.Name})
|
|
return nil
|
|
}
|
|
|
|
func (m *CT_FileSharing) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|
// initialize to default
|
|
m.ReadOnlyRecommendedAttr = gooxml.Bool(false)
|
|
for _, attr := range start.Attr {
|
|
if attr.Name.Local == "readOnlyRecommended" {
|
|
parsed, err := strconv.ParseBool(attr.Value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.ReadOnlyRecommendedAttr = &parsed
|
|
}
|
|
if attr.Name.Local == "userName" {
|
|
parsed, err := attr.Value, error(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.UserNameAttr = &parsed
|
|
}
|
|
if attr.Name.Local == "reservationPassword" {
|
|
parsed, err := attr.Value, error(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.ReservationPasswordAttr = &parsed
|
|
}
|
|
if attr.Name.Local == "algorithmName" {
|
|
parsed, err := attr.Value, error(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.AlgorithmNameAttr = &parsed
|
|
}
|
|
if attr.Name.Local == "hashValue" {
|
|
parsed, err := attr.Value, error(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.HashValueAttr = &parsed
|
|
}
|
|
if attr.Name.Local == "saltValue" {
|
|
parsed, err := attr.Value, error(nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.SaltValueAttr = &parsed
|
|
}
|
|
if attr.Name.Local == "spinCount" {
|
|
parsed, err := strconv.ParseUint(attr.Value, 10, 32)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pt := uint32(parsed)
|
|
m.SpinCountAttr = &pt
|
|
}
|
|
}
|
|
// skip any extensions we may find, but don't support
|
|
for {
|
|
tok, err := d.Token()
|
|
if err != nil {
|
|
return fmt.Errorf("parsing CT_FileSharing: %s", err)
|
|
}
|
|
if el, ok := tok.(xml.EndElement); ok && el.Name == start.Name {
|
|
break
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Validate validates the CT_FileSharing and its children
|
|
func (m *CT_FileSharing) Validate() error {
|
|
return m.ValidateWithPath("CT_FileSharing")
|
|
}
|
|
|
|
// ValidateWithPath validates the CT_FileSharing and its children, prefixing error messages with path
|
|
func (m *CT_FileSharing) ValidateWithPath(path string) error {
|
|
return nil
|
|
}
|