confxml

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 10 Imported by: 0

README

pipeline status coverage report Latest Release

3D Configurator XML Parser

Prolicht 3D Configurator XML parser. This library handles parsing of configurator save-games.

Usage

Import git.prolicht.digital/golib/confxml. After that you can use the API functions, for example:

savegame, err := UnmarshallCgSaveGame(strings.NewReader(sampleXmlString))

Documentation

Index

Constants

View Source
const CurrentSoplVersion = Version20

CurrentSoplVersion is the current SOPL format version Bump this when the format changes

Variables

This section is empty.

Functions

func MarshallCgSaveGame

func MarshallCgSaveGame(sg *CgSavegame) (string, error)

func UnitForAbas

func UnitForAbas(unit string) string

UnitForAbas converts the configurator unit to an abas unit

Types

type CgArticle

type CgArticle struct {
	Number         string              `xml:"number,attr"`
	Unit           string              `xml:"unit,attr"`
	Quantity       CgQuantity          `xml:"Quantity"`
	Length         *CgLength           `xml:"Length,omitempty"`
	Mitercut       *CgMitercut         `xml:"MiterCut,omitempty"`
	Width          *CgWidth            `xml:"Width,omitempty"`
	TechnicOptions CgTechnicOptionList `xml:"TechOptions,omitempty"`
	ColorOptions   CgColorOptionList   `xml:"ColorOptions,omitempty"`
}

func (*CgArticle) GetAmount

func (c *CgArticle) GetAmount() float64

func (*CgArticle) GetLength

func (c *CgArticle) GetLength() float64

func (*CgArticle) GetWidth

func (c *CgArticle) GetWidth() float64

type CgArticleList

type CgArticleList struct {
	Articles []CgArticle `xml:"Article"`
}

type CgColorOptionList

type CgColorOptionList struct {
	Options []CgOption `xml:"Option,omitempty"`
}

func (CgColorOptionList) Concat

func (c CgColorOptionList) Concat(sep rune) string

func (CgColorOptionList) String

func (c CgColorOptionList) String() string

type CgConfiguration

type CgConfiguration struct {
	XMLName xml.Name `xml:"Configuration"`

	Version string `xml:"Version"`

	Raw []byte `xml:",innerxml"` // ignore, we are only interested in the article list
}

CgConfiguration contains data used by the Clockstone configurator. The only useful field in the configuration data is the Version field that specifies the configurator version that was used.

func (CgConfiguration) GetVersion added in v1.0.2

func (c CgConfiguration) GetVersion() (CgVersion, error)

func (CgConfiguration) MarshalXML added in v1.0.2

func (c CgConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type CgItemList

type CgItemList struct {
	XMLName xml.Name `xml:"ItemList"`

	SystemList      CgSystemList `xml:"SystemList"`
	SaveDataVersion string       `xml:"saveDataVersion,attr"`
}

type CgLength

type CgLength struct {
	Value float64 `xml:",chardata"`
	Unit  string  `xml:"unit,attr"`
}

type CgMitercut added in v1.0.3

type CgMitercut struct {
	Ybegin float64 `xml:"yBegin,attr"`
	Yend   float64 `xml:"yEnd,attr"`
	Zbegin float64 `xml:"zBegin,attr"`
	Zend   float64 `xml:"zEnd,attr"`
}

type CgOption

type CgOption struct {
	Value string `xml:",chardata"`
	ID    int    `xml:"id,attr"`
}

type CgPackagingUnit

type CgPackagingUnit struct {
	Number      string        `xml:"number,attr"`
	ArticleList CgArticleList `xml:"ArticleList"`
}

type CgPackagingUnitList

type CgPackagingUnitList struct {
	PackagingUnits []CgPackagingUnit `xml:"PackagingUnit"`
}

type CgQuantity

type CgQuantity struct {
	Value float64 `xml:",chardata"`
	Unit  string  `xml:"unit,attr"`
}

type CgSavegame

type CgSavegame struct {
	XMLName xml.Name `xml:"ProlichtConfiguration"`

	Configuration CgConfiguration `xml:"Configuration"`
	ItemList      CgItemList      `xml:"ItemList"`
}

CgSavegame is the root element (ProlichtConfiguration)

func ConvertFromOldSOPLFormat added in v1.0.4

func ConvertFromOldSOPLFormat(soplString string) (*CgSavegame, error)

ConvertFromOldSOPLFormat converts AFL(SOPL) strings to 3D configurator save-games

func UnmarshallCgSaveGame

func UnmarshallCgSaveGame(xmlReader io.Reader) (*CgSavegame, error)

type CgSystem

type CgSystem struct {
	Number            string `xml:"number,attr"`
	Info              string `xml:"Info"`
	DatabaseID        string `xml:"DatabaseID"`
	RowID             string `xml:"RowID"`
	RecordID          string `xml:"RecordID"`
	IsValid           bool   `xml:"IsValid"`
	PackagingUnitList CgPackagingUnitList
}

func (*CgSystem) ConvertToOldSOPLFormat

func (s *CgSystem) ConvertToOldSOPLFormat() string

ConvertToOldSOPLFormat generates the old import format: minimum fields lenght is 11 (legacy format without yaxisy... and yaxisx...) newer records include additional 4 fields example line: 1~~100-2075~0~m~~~~~~

0            1              2        3       4        5        6       7        8        9                 10				11				12			13				14

U|xtstufe'~'U|hauptartikel'~'U|artex'~'U|mge'~'U|he'~'U|laenge'~'U|le'~'U|breite'~'U|be'~'U|technicoption'~'U|coloroption'~'U|yaxisybegin'~'U|yaxisyend'~'U|yaxiszbegin'~'U|yaxiszend

type CgSystemList

type CgSystemList struct {
	Systems []CgSystem `xml:"System"`
}

type CgTechnicOptionList

type CgTechnicOptionList struct {
	Options []CgOption `xml:"Option,omitempty"`
}

func (CgTechnicOptionList) Concat

func (t CgTechnicOptionList) Concat(sep rune) string

func (CgTechnicOptionList) String

func (t CgTechnicOptionList) String() string

type CgVersion added in v1.0.2

type CgVersion struct {
	Major int
	Minor int
	Patch int

	Build int
}

CgVersion represents a version string in semantic versioning schema (https://semver.org/lang/de/)

func VersionFromComparableString added in v1.0.2

func VersionFromComparableString(versionStr string) (CgVersion, error)

VersionFromComparableString parses a given string and returns the corresponding version. Check the ComparableString() method for the accepted version format. For example:

String: 003.001.000.0123
Version: 3.1.0+123
String: 003.000.000.0123
Version: 3.0.0+123
String: 003.000.000.0005
Version: 3.0.0+5
String: 3.0.0.5
Version: 3.0.0+5

func VersionFromConfiguratorStyle added in v1.0.2

func VersionFromConfiguratorStyle(versionStr string) (CgVersion, error)

VersionFromConfiguratorStyle parses the given version string into a CgVersion struct. The given string mus comply with the Clockstone version format.

func (CgVersion) ComparableVersion added in v1.0.2

func (v CgVersion) ComparableVersion() string

ComparableVersion returns a string representation of the version that is easily comparable via string comparison.

func (CgVersion) Compare added in v1.0.2

func (v CgVersion) Compare(other CgVersion) int

Compare compares the given version with another version. It returns: 1 when the other version is older -1 when the other version is newer 0 if the versions are the same

func (CgVersion) SemanticVersion added in v1.0.2

func (v CgVersion) SemanticVersion() string

SemanticVersion formats the version number according to the semantic version schema rules (https://semver.org/lang/de/)

func (CgVersion) String added in v1.0.2

func (v CgVersion) String() string

String formats the version number in the same fashion as the configurator does

type CgWidth

type CgWidth struct {
	Value float64 `xml:",chardata"`
	Unit  string  `xml:"unit,attr"`
}

type Sopl added in v1.1.0

type Sopl struct {
	Version SoplVersion   `yaml:"version" validate:"sopl_version"`
	Systems []*SoplSystem `yaml:"systems" validate:"dive"`
}

Sopl (and its nested structs) is the struct that represents the SOPL file as defined on https://devdocs.prolicht.digital/en/projects/abas/sales/sopl-format#version-20

func FromAfl added in v1.1.0

func FromAfl(afl []byte) (*Sopl, error)

FromAfl creates a new Sopl struct from a afl byte array

func FromXml added in v1.1.0

func FromXml(xmlData []byte) (*Sopl, error)

FromXml creates a new Sopl struct from a xml byte array

func FromYaml added in v1.1.0

func FromYaml(data []byte) (*Sopl, error)

FromYaml creates a new Sopl struct from a yaml byte array

func (*Sopl) ToAfl added in v1.1.0

func (sopl *Sopl) ToAfl() string

ToAfl creates a afl byte array from the Sopl struct

func (*Sopl) ToXml added in v1.1.0

func (sopl *Sopl) ToXml() ([]byte, error)

ToXml creates a xml byte array from the Sopl struct

func (*Sopl) ToYaml added in v1.1.0

func (sopl *Sopl) ToYaml() ([]byte, error)

ToYaml creates a yaml byte array from the Sopl struct

func (*Sopl) Validate added in v1.1.0

func (sopl *Sopl) Validate() error

Validate validates the Sopl struct using the validator package and custom validators

type SoplContainer added in v1.1.0

type SoplContainer struct {
	SKU      string         `yaml:"sku" validate:"required,sku"`
	Products []*SoplProduct `yaml:"products" validate:"dive"`
	Quantity int            `yaml:"quantity,omitempty" validate:"required,gte=1"`
}

type SoplExchangeFormat added in v1.1.0

type SoplExchangeFormat string
const (
	FormatXML     SoplExchangeFormat = "xml" // configurator savegame
	FormatAFL     SoplExchangeFormat = "afl" // old SOPL string
	FormatYAML    SoplExchangeFormat = "yml" // new SOPL representation
	FormatUnknown SoplExchangeFormat = "unk" // unknown format
)

func GuessSoplExchangeFormat added in v1.1.0

func GuessSoplExchangeFormat(data []byte) SoplExchangeFormat

GuessSoplExchangeFormat tries to derive the exchange format (old AFL, Configurator Savegame XML or YAML) from the given input. If no valid format was detected, FormatUnknown will be returned.

type SoplProduct added in v1.1.0

type SoplProduct struct {
	SKU                  string         `yaml:"sku" validate:"required,sku"`
	EncryptedSKU         string         `yaml:"encrypted_sku,omitempty" validate:"enc_sku"`
	ColorOptions         map[int]string `yaml:"color_options,omitempty" validate:"color_options"`
	TechnicOptions       map[int]string `yaml:"technic_options,omitempty" validate:"technic_options"`
	Quantity             float64        `yaml:"quantity" validate:"gte=0"`
	QuantityUnit         string         `yaml:"quantity_unit" validate:"required_with=Quantity"`
	Length               float64        `yaml:"length,omitempty" validate:"gte=0.0"`
	LengthUnit           string         `yaml:"length_unit,omitempty" validate:"required_with=Length"`
	MitercutYStart       float64        `yaml:"mitercut_y_start,omitempty" validate:"gte=-90.0,lte=90.0"`
	MitercutYEnd         float64        `yaml:"mitercut_y_end,omitempty" validate:"gte=-90.0,lte=90.0"`
	MitercutZStart       float64        `yaml:"mitercut_z_start,omitempty" validate:"gte=-90.0,lte=90.0"`
	MitercutZEnd         float64        `yaml:"mitercut_z_end,omitempty" validate:"gte=-90.0,lte=90.0"`
	Price                float64        `yaml:"price" validate:"gte=0.0"`
	MinimumPrice         float64        `yaml:"minimum_price" validate:"gte=0.0"`
	TechOptionSurcharge  float64        `yaml:"tech_option_surcharge,omitempty" validate:"gte=0.0"`
	ColorOptionSurcharge float64        `yaml:"color_option_surcharge,omitempty" validate:"gte=0.0"`
}

func (SoplProduct) ColorOptionString added in v1.1.1

func (s SoplProduct) ColorOptionString(separator string) string

func (SoplProduct) TechnicOptionString added in v1.1.1

func (s SoplProduct) TechnicOptionString(separator string) string

type SoplSystem added in v1.1.0

type SoplSystem struct {
	SKU        string           `yaml:"sku" validate:"required,sku"`
	Containers []*SoplContainer `yaml:"containers" validate:"dive"`
}

type SoplVersion added in v1.1.0

type SoplVersion string
const (
	VersionUnknown SoplVersion = ""
	Version10      SoplVersion = "1.0"
	Version15      SoplVersion = "1.5"
	Version20      SoplVersion = "2.0"
)

A list of supported versions.

func GuessSoplVersion added in v1.1.0

func GuessSoplVersion(data []byte) SoplVersion

GuessSoplVersion guesses the SOPL format version for the given input data. If no version could be detected, an empty string is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL