67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/xml"
|
|
)
|
|
|
|
type MxGraphModel struct {
|
|
XMLName xml.Name `xml:"mxGraphModel"`
|
|
|
|
Root struct {
|
|
XMLName xml.Name `xml:"root"`
|
|
MxCell []MxCell `xml:"mxCell"`
|
|
MxObject *[]MxObject `xml:"object"`
|
|
MxLink []MxLink
|
|
}
|
|
}
|
|
|
|
type MxCell struct {
|
|
XMLName xml.Name `xml:"mxCell"`
|
|
ID string `xml:"id,attr"`
|
|
RID *string `xml:"rID,attr"`
|
|
Rtype string `xml:"rType,attr"`
|
|
Parent *string `xml:"parent,attr"`
|
|
Edge *string `xml:"edge,attr"`
|
|
Source *string `xml:"source,attr"`
|
|
Target *string `xml:"target,attr"`
|
|
}
|
|
|
|
type MxLink struct {
|
|
ID string `xml:"id,attr"`
|
|
Source string `xml:"source,attr"`
|
|
Target string `xml:"target,attr"`
|
|
}
|
|
|
|
type MxObject struct {
|
|
XMLName xml.Name `xml:"object"`
|
|
ID string `xml:"id,attr"`
|
|
Settings []xml.Attr `xml:",any,attr"`
|
|
MxCell MxCell `xml:"mxCell"`
|
|
}
|
|
|
|
// Didn't manage to differentiate Links and cells containing components using
|
|
// only structures and unmarshal, so we use this method post-umarshalling
|
|
func (g *MxGraphModel) createLinks() error {
|
|
for i, mxcell := range g.Root.MxCell {
|
|
if mxcell.Edge != nil {
|
|
newLink := MxLink{mxcell.ID,*mxcell.Source,*mxcell.Target}
|
|
g.Root.MxLink = append(g.Root.MxLink,newLink)
|
|
g.Root.MxCell = append(g.Root.MxCell[:i],g.Root.MxCell[i+1:]...)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type mxissue struct {
|
|
msg string
|
|
}
|
|
|
|
func (m *mxissue) Error() string {
|
|
return m.msg
|
|
}
|
|
|
|
func newMxIssue(message string) error {
|
|
return &mxissue{message}
|
|
}
|
|
|