@@ -6,12 +6,13 @@ import {
66 ICategory ,
77 ICondition ,
88 IDirectedGraph ,
9- Link ,
10- Node ,
9+ IPath ,
1110 IProperty ,
1211 ISetter ,
1312 IStyle ,
14- IXmlNode
13+ IXmlNode ,
14+ Link ,
15+ Node
1516} from '@model' ;
1617
1718export class DgmlParser {
@@ -47,6 +48,8 @@ export class DgmlParser {
4748 directedGraph . properties = this . convertXmlToProperties ( xmlNode . children ) ;
4849 } else if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'styles' ) {
4950 directedGraph . styles = this . convertXmlToStyles ( xmlNode . children ) ;
51+ } else if ( xmlNode . name !== undefined && xmlNode . name . toLowerCase ( ) === 'paths' ) {
52+ directedGraph . paths = this . convertXmlToPaths ( xmlNode . children ) ;
5053 }
5154 } ) ;
5255 this . addStylingToCategories ( directedGraph ) ;
@@ -99,6 +102,7 @@ export class DgmlParser {
99102 newNode . style = this . getAttributeValue ( attributesCopy , 'style' ) ;
100103 newNode . horizontalAlignment = this . getAttributeValue ( attributesCopy , 'horizontalalignment' ) ;
101104 newNode . verticalAlignment = this . getAttributeValue ( attributesCopy , 'verticalalignment' ) ;
105+ newNode . filePath = this . getAttributeValue ( attributesCopy , 'filepath' ) ;
102106 const minWidth = this . getAttributeValue ( attributesCopy , 'minwidth' ) ;
103107 newNode . minWidth = minWidth !== undefined ? + minWidth : undefined ;
104108 const maxWidth = this . getAttributeValue ( attributesCopy , 'maxwidth' ) ;
@@ -116,10 +120,10 @@ export class DgmlParser {
116120 newNode . boundsWidth = + bounds [ 2 ] ;
117121 newNode . boundsHeight = + bounds [ 3 ] ;
118122 }
119- const additionalProperties = Object . keys ( attributesCopy ) ;
120- if ( additionalProperties . length > 0 ) {
121- additionalProperties . forEach ( property => {
122- newNode . properties . push ( { id : property , value : attributesCopy [ property ] } ) ;
123+ const customProperties = Object . keys ( attributesCopy ) ;
124+ if ( customProperties . length > 0 ) {
125+ customProperties . forEach ( property => {
126+ newNode . customProperties . push ( { id : property , value : attributesCopy [ property ] } ) ;
123127 } ) ;
124128 }
125129 if ( nodes . filter ( n => n . id === newNode . id ) . length === 0 ) {
@@ -275,6 +279,23 @@ export class DgmlParser {
275279 return styles ;
276280 }
277281
282+ private convertXmlToPaths ( xmlNodes : IXmlNode [ ] ) : IPath [ ] {
283+ const paths : IPath [ ] = [ ] ;
284+ if ( xmlNodes . length > 0 ) {
285+ xmlNodes . forEach ( xmlNode => {
286+ if ( xmlNode . attributes !== undefined ) {
287+ const attributesCopy : { [ key : string ] : string } = this . toLowercaseDictionary ( xmlNode . attributes ) ;
288+ const newProperty = {
289+ id : attributesCopy [ 'id' ] ,
290+ value : attributesCopy [ 'value' ] ,
291+ } as IPath ;
292+ paths . push ( newProperty ) ;
293+ }
294+ } ) ;
295+ }
296+ return paths ;
297+ }
298+
278299 private createCondition ( xmlNode : IXmlNode ) : ICondition | undefined {
279300 let condition : ICondition | undefined = undefined ;
280301 if ( xmlNode . children !== undefined ) {
@@ -409,15 +430,31 @@ export class DgmlParser {
409430 }
410431
411432 private enrichNodes ( directedGraph : IDirectedGraph ) : void {
412- directedGraph . properties . forEach ( property => {
413- directedGraph . nodes . forEach ( node => {
414- if ( node . properties . length > 0 ) {
415- const existingPropertyIdx = node . properties . findIndex ( nodeProperty => nodeProperty . id . toLowerCase ( ) === property . id . toLowerCase ( ) ) ;
433+ directedGraph . nodes . forEach ( node => {
434+ if ( node . filePath !== undefined ) {
435+ node . filePath = this . replacePaths ( node . filePath , directedGraph ) ;
436+ }
437+ if ( node . customProperties !== undefined && node . customProperties . length > 0 ) {
438+ directedGraph . properties . forEach ( property => {
439+ const existingPropertyIdx = node . customProperties . findIndex ( nodeProperty => nodeProperty . id . toLowerCase ( ) === property . id . toLowerCase ( ) ) ;
416440 if ( existingPropertyIdx !== - 1 ) {
417- Object . assign ( node . properties [ existingPropertyIdx ] , property ) ;
441+ Object . assign ( node . customProperties [ existingPropertyIdx ] , property ) ;
442+ if ( node . customProperties [ existingPropertyIdx ] . isReference ) {
443+ node . customProperties [ existingPropertyIdx ] . value = this . replacePaths ( node . customProperties [ existingPropertyIdx ] . value , directedGraph ) ;
444+ }
418445 }
419- }
420- } ) ;
446+ } ) ;
447+ }
421448 } ) ;
422449 }
450+
451+ private replacePaths ( filePath : string | undefined , directedGraph : IDirectedGraph ) : string | undefined {
452+ let fixedFilepath = filePath ;
453+ if ( fixedFilepath !== undefined && directedGraph . paths !== undefined && directedGraph . paths . length > 0 ) {
454+ directedGraph . paths . forEach ( path => {
455+ fixedFilepath = fixedFilepath ?. replace ( `\$(${ path . id } )` , path . value ) ;
456+ } ) ;
457+ }
458+ return fixedFilepath ;
459+ }
423460}
0 commit comments