/// <summary> /// Parses the given node into the object or returns a new object /// representing the given node. /// Dec is a reference to the calling decoder. It is used to decode /// complex objects and resolve references. /// If a node has an id attribute then the object cache is checked for the /// object. If the object is not yet in the cache then it is constructed /// using the constructor of template and cached in mxCodec.objects. /// This implementation decodes all attributes and childs of a node /// according to the following rules: /// - If the variable name is in exclude or if the attribute name is "id" /// or "as" then it is ignored. /// - If the variable name is in idrefs then mxCodec.getObject is used /// to replace the reference with an object. /// - The variable name is mapped using a reverse mapping. /// - If the value has a child node, then the codec is used to create a /// child object with the variable name taken from the "as" attribute. /// - If the object is an array and the variable name is empty then the /// value or child object is appended to the array. /// - If an add child has no value or the object is not an array then /// the child text content is evaluated using mxUtils.eval. /// If no object exists for an ID in idrefs a warning is issued /// using mxLog.warn. /// Returns the resulting object that represents the given XML /// node or the configured given object. /// </summary> /// <param name="dec">Codec that controls the encoding process.</param> /// <param name="node">XML node to be decoded.</param> /// <param name="into">Optional objec to encode the node into.</param> /// <returns>Returns the resulting object that represents the given XML node /// or the object given to the method as the into parameter.</returns> public virtual Object Decode(mxCodec dec, XmlNode node, Object into) { Object obj = null; if (node is XmlElement) { string id = ((XmlElement)node).GetAttribute("id"); obj = (dec.Objects.ContainsKey(id)) ? dec.Objects[id] : null; if (obj == null) { obj = into; if (obj == null) { obj = CloneTemplate(node); } if (id != null && id.Length > 0) { dec.PutObject(id, obj); } } node = BeforeDecode(dec, node, obj); DecodeNode(dec, node, obj); obj = AfterDecode(dec, node, obj); } return(obj); }
/// <summary> /// Decodes the given mxStylesheet. /// </summary> public override Object Decode(mxCodec dec, XmlNode node, Object into) { Object obj = null; if (node is XmlElement) { string id = ((XmlElement)node).GetAttribute("id"); obj = (dec.Objects.ContainsKey(id)) ? dec.Objects[id] : null; if (obj == null) { obj = into; if (obj == null) { obj = CloneTemplate(node); } if (id != null && id.Length > 0) { dec.PutObject(id, obj); } } node = node.FirstChild; while (node != null) { if (!ProcessInclude(dec, node, obj) && node.Name.Equals("add") && node is XmlElement) { string name = ((XmlElement) node).GetAttribute("as"); if (name != null && name.Length > 0) { string extend = ((XmlElement) node).GetAttribute("extend"); Dictionary<string, Object> style = (extend != null && ((mxStylesheet)obj).Styles.ContainsKey(extend)) ? ((mxStylesheet)obj).Styles[extend] : null; if (style == null) { style = new Dictionary<string, Object>(); } else { style = new Dictionary<string, Object>(style); } XmlNode entry = node.FirstChild; while (entry != null) { if (entry is XmlElement) { XmlElement entryElement = (XmlElement)entry; string key = entryElement.GetAttribute("as"); if (entry.Name.Equals("add")) { string text = entryElement.Value; Object value = null; if (text != null && text.Length > 0) { value = mxUtils.Eval(text); } else { value = entryElement.GetAttribute("value"); } if (value != null) { style[key] = value; } } else if (entry.Name.Equals("remove")) { style.Remove(key); } } entry = entry.NextSibling; } ((mxStylesheet) obj).PutCellStyle(name, style); } } node = node.NextSibling; } } return obj; }
/// <summary> /// Parses the given node into the object or returns a new object /// representing the given node. /// Dec is a reference to the calling decoder. It is used to decode /// complex objects and resolve references. /// If a node has an id attribute then the object cache is checked for the /// object. If the object is not yet in the cache then it is constructed /// using the constructor of template and cached in mxCodec.objects. /// This implementation decodes all attributes and childs of a node /// according to the following rules: /// - If the variable name is in exclude or if the attribute name is "id" /// or "as" then it is ignored. /// - If the variable name is in idrefs then mxCodec.getObject is used /// to replace the reference with an object. /// - The variable name is mapped using a reverse mapping. /// - If the value has a child node, then the codec is used to create a /// child object with the variable name taken from the "as" attribute. /// - If the object is an array and the variable name is empty then the /// value or child object is appended to the array. /// - If an add child has no value or the object is not an array then /// the child text content is evaluated using mxUtils.eval. /// If no object exists for an ID in idrefs a warning is issued /// using mxLog.warn. /// Returns the resulting object that represents the given XML /// node or the configured given object. /// </summary> /// <param name="dec">Codec that controls the encoding process.</param> /// <param name="node">XML node to be decoded.</param> /// <param name="into">Optional objec to encode the node into.</param> /// <returns>Returns the resulting object that represents the given XML node /// or the object given to the method as the into parameter.</returns> public virtual Object Decode(mxCodec dec, XmlNode node, Object into) { Object obj = null; if (node is XmlElement) { string id = ((XmlElement)node).GetAttribute("id"); obj = (dec.Objects.ContainsKey(id)) ? dec.Objects[id] : null; if (obj == null) { obj = into; if (obj == null) { obj = CloneTemplate(node); } if (id != null && id.Length > 0) { dec.PutObject(id, obj); } } node = BeforeDecode(dec, node, obj); DecodeNode(dec, node, obj); obj = AfterDecode(dec, node, obj); } return obj; }
/// <summary> /// Decodes the given mxStylesheet. /// </summary> public override Object Decode(mxCodec dec, XmlNode node, Object into) { Object obj = null; if (node is XmlElement) { string id = ((XmlElement)node).GetAttribute("id"); obj = (dec.Objects.ContainsKey(id)) ? dec.Objects[id] : null; if (obj == null) { obj = into; if (obj == null) { obj = CloneTemplate(node); } if (id != null && id.Length > 0) { dec.PutObject(id, obj); } } node = node.FirstChild; while (node != null) { if (!ProcessInclude(dec, node, obj) && node.Name.Equals("add") && node is XmlElement) { string name = ((XmlElement)node).GetAttribute("as"); if (name != null && name.Length > 0) { string extend = ((XmlElement)node).GetAttribute("extend"); Dictionary <string, Object> style = (extend != null && ((mxStylesheet)obj).Styles.ContainsKey(extend)) ? ((mxStylesheet)obj).Styles[extend] : null; if (style == null) { style = new Dictionary <string, Object>(); } else { style = new Dictionary <string, Object>(style); } XmlNode entry = node.FirstChild; while (entry != null) { if (entry is XmlElement) { XmlElement entryElement = (XmlElement)entry; string key = entryElement.GetAttribute("as"); if (entry.Name.Equals("add")) { string text = entryElement.Value; Object value = null; if (text != null && text.Length > 0) { value = mxUtils.Eval(text); } else { value = entryElement.GetAttribute("value"); } if (value != null) { style[key] = value; } } else if (entry.Name.Equals("remove")) { style.Remove(key); } } entry = entry.NextSibling; } ((mxStylesheet)obj).PutCellStyle(name, style); } } node = node.NextSibling; } } return(obj); }