11package com .mxgraph .xml2js ;
22
3- import org .w3c .dom .Document ;
4- import org .w3c .dom .Element ;
5- import org .w3c .dom .Node ;
6- import org .w3c .dom .NodeList ;
3+ import org .w3c .dom .*;
74import org .xml .sax .InputSource ;
85
96import javax .xml .parsers .DocumentBuilder ;
@@ -84,7 +81,13 @@ private static Document parseXml(String xml) {
8481 }
8582
8683 public void parseShape (Node shape ) {
87- logInfo (format ("Parsing shape '%s'" , shape .getAttributes ().getNamedItem ("name" ).getTextContent ()));
84+ AttributesTextContent shapeAttributes = new AttributesTextContent (shape .getAttributes ());
85+ String name = shapeAttributes .text ("name" );
86+ logInfo (format ("Parsing shape '%s'" , name ));
87+ generateComment (format ("shape: %s" , name ));
88+ generateComment (format ("width: %s" , shapeAttributes .text ("w" )));
89+ generateComment (format ("height: %s" , shapeAttributes .text ("h" )));
90+
8891 NodeList shapeChildren = shape .getChildNodes ();
8992 for (int i = 0 ; i < shapeChildren .getLength (); i ++) {
9093 Node item = shapeChildren .item (i );
@@ -96,9 +99,21 @@ public void parseShape(Node shape) {
9699 }
97100 }
98101
102+ private static class AttributesTextContent {
103+ private final NamedNodeMap attributes ;
104+
105+ public AttributesTextContent (NamedNodeMap attributes ) {
106+ this .attributes = attributes ;
107+ }
108+
109+ public String text (String attributeName ) {
110+ return attributes .getNamedItem (attributeName ).getTextContent ();
111+ }
112+ }
113+
99114 private void parseForeground (Node foreground ) {
100115 logDebug ("Parsing foreground" );
101- generateCode ( "// foreground" );
116+ generateComment ( " foreground" );
102117 NodeList children = foreground .getChildNodes ();
103118
104119 for (int i = 0 ; i < children .getLength (); i ++) {
@@ -126,6 +141,10 @@ private void generateCode(String code) {
126141 codeLines .add (code );
127142 }
128143
144+ private void generateComment (String comment ) {
145+ generateCode ("// " + comment );
146+ }
147+
129148 private void parsePath (Node path ) {
130149 logDebug ("Parsing path" );
131150 generateCanvasMethodCall ("begin()" );
0 commit comments