Skip to content

Commit

Permalink
worked
Browse files Browse the repository at this point in the history
  • Loading branch information
khorevaa committed Apr 29, 2021
1 parent e20a489 commit 5612837
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 15 deletions.
63 changes: 57 additions & 6 deletions configuration.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package mdclasses

import (
"encoding/xml"
"github.com/khorevaa/logos"
"github.com/v8platform/mdclasses/encoding/xml"
)

var log = logos.New("github.com/v8platform/mdclasses").Sugar()

type Mdclass struct {
xml.Name
value string
}

type Name struct {
xml.Name
value string
}

type Configuration struct {
XMLName xml.Name `xml:"Configuration"`
Mdclass string `xml:"mdclass,attr"`
Uuid string `xml:"uuid,attr"`
Name string `xml:"name"`
Synonym ValueTypeRef `xml:"synonym"`
XMLName xml.Name `xml:"mdclass Configuration"`
Mdclass xml.Attr `xml:"mdclass,attr"`
Uuid string `xml:"uuid,attr"`
Name string `xml:"name"`
Synonym struct {
Key string `xml:"key"`
Value string `xml:"value"`
} `xml:"synonym"`
ContainedObjects []struct {
ClassId string `xml:"classId,attr,allowempty"`
ObjectId string `xml:"objectId,attr,allowempty"`
Expand Down Expand Up @@ -114,6 +127,44 @@ type Configuration struct {
Tasks []string `xml:"tasks"`
}

const ConfigurationFile = "Configuration.mdo"

func (conf *Name) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
panic("implement me")
}

func (conf *Mdclass) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
//pp.Println(name)
return xml.Attr{
conf.Name,
conf.value,
}, nil
}

func (conf *Mdclass) UnmarshalXMLAttr(attr xml.Attr) error {

conf.Name = attr.Name
conf.value = attr.Value

return nil
}

func (conf *Name) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
//pp.Println(name)
return xml.Attr{
conf.Name,
conf.value,
}, nil
}

func (conf *Name) UnmarshalXMLAttr(attr xml.Attr) error {

conf.Name = attr.Name
conf.value = attr.Value

return nil
}

func (conf *Configuration) Unpack(cfg UnpackConfig) error {

for _, name := range conf.SubsystemsNames {
Expand Down
14 changes: 10 additions & 4 deletions encoding/xml/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ func (p *printer) createAttrPrefix(url string) string {
// (('X'|'x') ('M'|'m') ('L'|'l'))
// See Section 2.3 of https://www.w3.org/TR/REC-xml/
if len(prefix) >= 3 && strings.EqualFold(prefix[:3], "xml") {
prefix = "_" + prefix
// prefix = "_" + prefix
return prefix
}
if p.attrNS[prefix] != "" {
// Name is taken. Find a better one.
Expand Down Expand Up @@ -722,13 +723,12 @@ func (p *printer) writeStart(start *StartElement, selfClosing bool) error {
}

p.WriteByte('<')
p.WriteString(start.Name.Local)

if start.Name.Space != "" {
p.WriteString(` xmlns="`)
p.EscapeString(start.Name.Space)
p.WriteByte('"')
p.WriteByte(':')
}
p.WriteString(start.Name.Local)

// Attributes
for _, attr := range start.Attr {
Expand Down Expand Up @@ -772,7 +772,13 @@ func (p *printer) writeEnd(name Name) error {
p.writeIndent(-1)
p.WriteByte('<')
p.WriteByte('/')
if name.Space != "" {
p.EscapeString(name.Space)
p.WriteByte(':')
}

p.WriteString(name.Local)

p.WriteByte('>')
p.popPrefix()
return nil
Expand Down
7 changes: 4 additions & 3 deletions encoding/xml/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ func (d *Decoder) translate(n *Name, isElementName bool) {
case n.Space == "" && n.Local == xmlnsPrefix:
return
}
if v, ok := d.ns[n.Space]; ok {
n.Space = v
} else if n.Space == "" {
// if v, ok := d.ns[n.Space]; ok {
// n.Space = v
// } else
if n.Space == "" {
n.Space = d.DefaultSpace
}
}
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module github.com/v8platform/mdclasses
go 1.16

require (
github.com/khorevaa/logos v0.9.8
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/k0kubun/pp v3.0.1+incompatible
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/pkg/errors v0.9.1
github.com/khorevaa/logos v0.9.8

)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40=
github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
12 changes: 12 additions & 0 deletions mdclasses.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package mdclasses

import (
"fmt"
"github.com/v8platform/mdclasses/encoding/xml"
)

func UnpackConfiguration(dir string) (Configuration, error) {

cfg := NewUnpackConfig("Configuration", dir)
Expand All @@ -10,6 +15,13 @@ func UnpackConfiguration(dir string) (Configuration, error) {
return Configuration{}, err
}

bytes, err := xml.Marshal(conf)
if err != nil {
return Configuration{}, err
}
str := string(bytes)
fmt.Println(str)

return conf, nil

}
2 changes: 1 addition & 1 deletion unpack.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mdclasses

import (
"encoding/xml"
"fmt"
"github.com/pkg/errors"
"github.com/v8platform/mdclasses/encoding/xml"
"io/ioutil"
"os"
"path/filepath"
Expand Down

0 comments on commit 5612837

Please sign in to comment.