Beispiel #1
0
        /// <summary>
        /// Reads the given attribute into the specified object.
        /// </summary>
        protected void DecodeAttribute(mxCodec dec, XmlNode attr, Object obj)
        {
            string name = attr.Name;

            if (!name.ToLower().Equals("as") &&
                !name.ToLower().Equals("id"))
            {
                Object value     = attr.Value;
                string fieldname = GetFieldName(name);

                if (IsReference(obj, fieldname, value, false))
                {
                    Object tmp = dec.GetObject(value.ToString());

                    if (tmp == null)
                    {
                        Trace.WriteLine("mxObjectCodec.decode: No object for " +
                                        GetName() + "." + fieldname + "=" + value);
                        return; // exit
                    }

                    value = tmp;
                }

                if (!IsExcluded(obj, fieldname, value, false))
                {
                    SetFieldValue(obj, fieldname, value);
                }
            }
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
        /// <summary>
        /// Encodes an mxCell and wraps the XML up inside the
        /// XML of the user object (inversion).
        /// </summary>
        public override XmlNode AfterEncode(mxCodec enc, Object obj, XmlNode node)
        {
            if (obj is mxCell && node is XmlElement)
            {
                mxCell cell = (mxCell)obj;

                if (cell.Value != null)
                {
                    if (cell.Value is XmlNode)
                    {
                        // Wraps the graphical annotation up in the
                        // user object (inversion) by putting the
                        // result of the default encoding into
                        // a clone of the user object (node type 1)
                        // and returning this cloned user object.
                        XmlElement tmp = (XmlElement)node;
                        node = enc.Document.ImportNode((XmlNode)cell.Value, true);
                        node.AppendChild(tmp);

                        // Moves the id attribute to the outermost
                        // XML node, namely the node which denotes
                        // the object boundaries in the file.
                        String id = tmp.GetAttribute("id");
                        ((XmlElement)node).SetAttribute("id", id);
                        tmp.RemoveAttribute("id");
                    }
                }
            }

            return node;
        }
Beispiel #4
0
        /// <summary>
        /// Reads the specified child into the given object.
        /// </summary>
        protected void DecodeChild(mxCodec dec, XmlNode child, Object obj)
        {
            string fieldname = GetFieldName(((XmlElement)child).GetAttribute("as"));

            if (fieldname == null || !IsExcluded(obj, fieldname, child, false))
            {
                Object template = GetFieldTemplate(obj, fieldname, child);
                Object value    = null;

                if (child.Name.Equals("add"))
                {
                    value = ((XmlElement)child).GetAttribute("value");

                    if (value == null)
                    {
                        value = child.InnerText;
                    }
                }
                else
                {
                    value = dec.Decode(child, template);
                }

                AddObjectValue(obj, fieldname, value, template);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Converts the given value according to the mappings and id-refs in
        /// this codec and uses writeAttribute to write the attribute into the
        /// given node.
        /// </summary>
        /// <param name="enc">Codec that controls the encoding process.</param>
        /// <param name="obj">Object whose member is going to be encoded.</param>
        /// <param name="fieldname"></param>
        /// <param name="value">Value of the property to be encoded.</param>
        /// <param name="node">XML node that contains the encoded object.</param>
        protected void EncodeValue(mxCodec enc, Object obj, string fieldname,
                                   Object value, XmlNode node)
        {
            if (value != null && !IsExcluded(obj, fieldname, value, true))
            {
                if (IsReference(obj, fieldname, value, true))
                {
                    Object tmp = enc.GetId(value);

                    if (tmp == null)
                    {
                        Trace.WriteLine("mxObjectCodec.encode: No ID for " +
                                        GetName() + "." + fieldname + "=" + value);
                        return; // exit
                    }

                    value = tmp;
                }

                Object defaultValue = GetFieldValue(template, fieldname);

                if (fieldname == null || enc.IsEncodeDefaults ||
                    defaultValue == null || !defaultValue.Equals(value))
                {
                    WriteAttribute(enc, obj, GetAttributeName(fieldname), value,
                                   node);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Encodes an mxCell and wraps the XML up inside the
        /// XML of the user object (inversion).
        /// </summary>
        public override XmlNode AfterEncode(mxCodec enc, Object obj, XmlNode node)
        {
            if (obj is mxCell && node is XmlElement)
            {
                mxCell cell = (mxCell)obj;

                if (cell.Value != null)
                {
                    if (cell.Value is XmlNode)
                    {
                        // Wraps the graphical annotation up in the
                        // user object (inversion) by putting the
                        // result of the default encoding into
                        // a clone of the user object (node type 1)
                        // and returning this cloned user object.
                        XmlElement tmp = (XmlElement)node;
                        node = enc.Document.ImportNode((XmlNode)cell.Value, true);
                        node.AppendChild(tmp);

                        // Moves the id attribute to the outermost
                        // XML node, namely the node which denotes
                        // the object boundaries in the file.
                        String id = tmp.GetAttribute("id");
                        ((XmlElement)node).SetAttribute("id", id);
                        tmp.RemoveAttribute("id");
                    }
                }
            }

            return(node);
        }
Beispiel #7
0
        public static void Main()
        {
            // Creates graph with model
            mxGraph graph = new mxGraph();

            // Adds cells into the model
            Object parent = graph.GetDefaultParent();
            graph.Model.BeginUpdate();
            Object v1, v2, e1;
            try
            {
                v1 = graph.InsertVertex(parent, null, "Hello", 20, 20, 80, 30);
                v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30);
                e1 = graph.InsertEdge(parent, null, "e1", v1, v2);
            }
            finally
            {
                graph.Model.EndUpdate();
            }

            mxCodec codec = new mxCodec();
            XmlNode node = codec.Encode(graph.Model);
            string xml1 = mxUtils.GetPrettyXml(node);

            codec = new mxCodec();
            Object model = codec.Decode(node);

            codec = new mxCodec();
            node = codec.Encode(model);
            string xml2 = mxUtils.GetPrettyXml(node);

            Console.WriteLine("mxCodecTest Passed: "+(xml1.Equals(xml2)));
            Thread.Sleep(100000);
        }
Beispiel #8
0
        /// <summary>
        /// Encode the given mxStylesheet.
        /// </summary>
        public override XmlNode Encode(mxCodec enc, Object obj)
        {
            XmlElement node = enc.Document.CreateElement(GetName());

            if (obj is mxStylesheet)
            {
                mxStylesheet stylesheet = (mxStylesheet)obj;

                foreach (KeyValuePair <string, Dictionary <string, Object> > entry in stylesheet.Styles)
                {
                    XmlElement styleNode = enc.Document.CreateElement("add");
                    styleNode.SetAttribute("as", entry.Key);

                    foreach (KeyValuePair <string, Object> entry2 in entry.Value)
                    {
                        XmlElement entryNode = enc.Document.CreateElement("add");
                        entryNode.SetAttribute("as", entry2.Key);
                        entryNode.SetAttribute("value", getStringValue(entry2));
                        styleNode.AppendChild(entryNode);
                    }

                    if (styleNode.ChildNodes.Count > 0)
                    {
                        node.AppendChild(styleNode);
                    }
                }
            }

            return(node);
        }
Beispiel #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Creates an instance of a graph to add vertices and edges. The instance can
            // then be used to create the corresponding XML using a codec. Note that this
            // is only required if a graph is programmatically created. If the XML for the
            // graph is already at hand, it can be sent directly here.
            mxGraph graph = new mxGraph();
            Object parent = graph.GetDefaultParent();

            // Adds vertices and edges to the graph.
            graph.Model.BeginUpdate();
            try
            {
                Object v1 = graph.InsertVertex(parent, null, "Hello,", 20, 20, 80, 30);
                Object v2 = graph.InsertVertex(parent, null, "World!", 200, 150, 80, 30);
                Object e1 = graph.InsertEdge(parent, null, "Edge", v1, v2);
            }
            finally
            {
                graph.Model.EndUpdate();
            }

            // Encodes the model into XML and passes the resulting XML string into a page
            // variable, so it can be read when the page is rendered on the server. Note
            // that the page instance is destroyed after the page was sent to the client.
            mxCodec codec = new mxCodec();
            Xml = mxUtils.GetXml(codec.Encode(graph.Model));
        }
Beispiel #10
0
 /// <summary>
 /// Calls decodeAttributes and decodeChildren for the given node.
 /// </summary>
 protected void DecodeNode(mxCodec dec, XmlNode node, Object obj)
 {
     if (node != null)
     {
         DecodeAttributes(dec, node, obj);
         DecodeChildren(dec, node, obj);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Encodes the specified object and returns a node
        /// representing then given object. Calls beforeEncode
        /// after creating the node and afterEncode with the
        /// resulting node after processing.
        /// Enc is a reference to the calling encoder. It is used
        /// to encode complex objects and create references.
        /// </summary>
        /// <param name="enc">Codec that controls the encoding process.</param>
        /// <param name="obj">Object to be encoded.</param>
        /// <returns>Returns the resulting XML node that represents the given object.</returns>
        public virtual XmlNode Encode(mxCodec enc, Object obj)
        {
            XmlNode node = enc.Document.CreateElement(GetName());

            obj = BeforeEncode(enc, obj, node);
            EncodeObject(enc, obj, node);

            return(AfterEncode(enc, obj, node));
        }
Beispiel #12
0
 /// <summary>
 /// Encodes the given mxGraphModel by writing a (flat) XML sequence
 /// of cell nodes as produced by the mxCellCodec. The sequence is
 /// wrapped-up in a node with the name root.
 /// </summary>
 protected override void EncodeObject(mxCodec enc, Object obj, XmlNode node)
 {
     if (obj is mxGraphModel)
     {
         XmlNode      rootNode = enc.Document.CreateElement("root");
         mxGraphModel model    = (mxGraphModel)obj;
         enc.EncodeCell((mxICell)model.Root, rootNode, true);
         node.AppendChild(rootNode);
     }
 }
Beispiel #13
0
        /// <summary>
        /// Decodes all attributes of the given node using decodeAttribute.
        /// </summary>
        protected void DecodeAttributes(mxCodec dec, XmlNode node, Object obj)
        {
            XmlAttributeCollection attrs = node.Attributes;

            if (attrs != null)
            {
                foreach (XmlAttribute attr in attrs)
                {
                    DecodeAttribute(dec, attr, obj);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Writes the given value into node using writePrimitiveAttribute
        /// or writeComplexAttribute depending on the type of the value.
        /// </summary>
        ///
        protected void WriteAttribute(mxCodec enc, Object obj, string attr,
                                      Object value, XmlNode node)
        {
            value = ConvertValueToXml(value);

            if (IsPrimitiveValue(value))
            {
                WritePrimitiveAttribute(enc, obj, attr, value, node);
            }
            else
            {
                WriteComplexAttribute(enc, obj, attr, value, node);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Reads the cells into the graph model. All cells are children of the root
        /// element in the node.
        /// </summary>
        public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object into)
        {
            if (node is XmlElement)
            {
                XmlElement   elt   = (XmlElement)node;
                mxGraphModel model = null;

                if (into is mxGraphModel)
                {
                    model = (mxGraphModel)into;
                }
                else
                {
                    model = new mxGraphModel();
                }

                // Reads the cells into the graph model. All cells
                // are children of the root element in the node.
                XmlNode root     = elt.GetElementsByTagName("root")[0];
                mxICell rootCell = null;

                if (root != null)
                {
                    XmlNode tmp = root.FirstChild;

                    while (tmp != null)
                    {
                        mxICell cell = dec.DecodeCell(tmp, true);

                        if (cell != null && cell.Parent == null)
                        {
                            rootCell = cell;
                        }

                        tmp = tmp.NextSibling;
                    }

                    root.ParentNode.RemoveChild(root);
                }

                // Sets the root on the model if one has been decoded
                if (rootCell != null)
                {
                    model.Root = rootCell;
                }
            }

            return(node);
        }
Beispiel #16
0
        /// <summary>
        /// Reads the cells into the graph model. All cells are children of the root
        /// element in the node.
        /// </summary>
        public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object into)
        {
            if (node is XmlElement)
            {
                XmlElement elt = (XmlElement)node;
                mxGraphModel model = null;

                if (into is mxGraphModel)
                {
                    model = (mxGraphModel)into;
                }
                else
                {
                    model = new mxGraphModel();
                }

                // Reads the cells into the graph model. All cells
                // are children of the root element in the node.
                XmlNode root = elt.GetElementsByTagName("root")[0];
                mxICell rootCell = null;

                if (root != null)
                {
                    XmlNode tmp = root.FirstChild;

                    while (tmp != null)
                    {
                        mxICell cell = dec.DecodeCell(tmp, true);

                        if (cell != null && cell.Parent == null)
                        {
                            rootCell = cell;
                        }

                        tmp = tmp.NextSibling;
                    }

                    root.ParentNode.RemoveChild(root);
                }

                // Sets the root on the model if one has been decoded
                if (rootCell != null)
                {
                    model.Root = rootCell;
                }
            }

            return node;
        }
Beispiel #17
0
        /// <summary>
        /// Reads the given attribute into the specified object.
        /// </summary>
        protected void DecodeChildren(mxCodec dec, XmlNode node, Object obj)
        {
            XmlNode child = node.FirstChild;

            while (child != null)
            {
                if (child.NodeType == XmlNodeType.Element &&
                    !ProcessInclude(dec, child, obj))
                {
                    DecodeChild(dec, child, obj);
                }

                child = child.NextSibling;
            }
        }
Beispiel #18
0
        /// <summary>
        /// Writes the given value as an attribute of the given node.
        /// </summary>
        protected void WritePrimitiveAttribute(mxCodec enc, Object obj,
                                               string attr, Object value, XmlNode node)
        {
            if (attr == null || obj is IDictionary)
            {
                XmlNode child = enc.Document.CreateElement("add");

                if (attr != null)
                {
                    mxCodec.SetAttribute(child, "as", attr);
                }

                mxCodec.SetAttribute(child, "value", value);
                node.AppendChild(child);
            }
            else
            {
                mxCodec.SetAttribute(node, attr, value);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Writes the given value as a child node of the given node.
        /// </summary>
        protected void WriteComplexAttribute(mxCodec enc, Object obj, string attr,
                                             Object value, XmlNode node)
        {
            XmlNode child = enc.Encode(value);

            if (child != null)
            {
                if (attr != null)
                {
                    mxCodec.SetAttribute(child, "as", attr);
                }

                node.AppendChild(child);
            }
            else
            {
                Trace.WriteLine("mxObjectCodec.encode: No node for " +
                                GetName() + "." + attr + ": " + value);
            }
        }
Beispiel #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dec">Codec that controls the encoding/decoding process.</param>
        /// <param name="node">XML node to be checked.</param>
        /// <param name="into">Optional object to pass-thru to the codec.</param>
        /// <returns>Returns true if the given node was processed as an include.</returns>
        public bool ProcessInclude(mxCodec dec, XmlNode node, Object into)
        {
            if (node.NodeType == XmlNodeType.Element &&
                node.Name.ToLower().Equals("include"))
            {
                string name = ((XmlElement)node).GetAttribute("name");

                if (name != null)
                {
                    XmlNode xml = mxUtils.LoadDocument(name).DocumentElement;

                    if (xml != null)
                    {
                        dec.Decode(xml, into);
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #21
0
        /// <summary>
        /// Encodes the members of the given object into the given node.
        /// </summary>
        /// <param name="enc">Codec that controls the encoding process.</param>
        /// <param name="obj">Object whose fields should be encoded.</param>
        /// <param name="node">XML node that contains the encoded object.</param>
        protected void EncodeFields(mxCodec enc, Object obj, XmlNode node)
        {
            Type type = obj.GetType();

            PropertyInfo[] properties = type.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                if (property.CanRead && property.CanWrite)
                {
                    string name  = property.Name;
                    Object value = GetFieldValue(obj, name);

                    // Removes Is-Prefix from bool properties
                    if (value is bool && name.StartsWith("Is"))
                    {
                        name = name.Substring(2);
                    }

                    name = name.Substring(0, 1).ToLower() + name.Substring(1);
                    EncodeValue(enc, obj, name, value, node);
                }
            }
        }
Beispiel #22
0
 /// <summary>
 /// Encodes the child objects of arrays, dictionaries and enumerables.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object whose child objects should be encoded.</param>
 /// <param name="node">XML node that contains the encoded object.</param>
 protected void EncodeElements(mxCodec enc, Object obj, XmlNode node)
 {
     if (obj.GetType().IsArray)
     {
         foreach (Object o in ((Object[])obj))
         {
             EncodeValue(enc, obj, null, o, node);
         }
     }
     else if (obj is IDictionary)
     {
         foreach (KeyValuePair <string, string> entry in ((IDictionary)mapping))
         {
             EncodeValue(enc, obj, entry.Key, entry.Value, node);
         }
     }
     else if (obj is IEnumerable)
     {
         foreach (Object value in ((IEnumerable)obj))
         {
             EncodeValue(enc, obj, null, value, node);
         }
     }
 }
Beispiel #23
0
 /// <summary>
 /// Hook for subclassers to pre-process the object before
 /// encoding. This returns the input object. The return
 /// value of this function is used in encode to perform
 /// the default encoding into the given node.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object to be encoded.</param>
 /// <param name="node">XML node to encode the object into.</param>
 /// <returns>Returns the object to be encoded by the default encoding.</returns>
 public virtual Object BeforeEncode(mxCodec enc, Object obj, XmlNode node)
 {
     return obj;
 }
Beispiel #24
0
 /// <summary>
 /// Hook for subclassers to pre-process the node for
 /// the specified object and return the node to be
 /// used for further processing by decode.
 /// The object is created based on the template in the
 /// calling method and is never null. This implementation
 /// returns the input node. The return value of this
 /// function is used in decode to perform
 /// the default decoding into the given object.
 /// </summary>
 /// <param name="dec">Codec that controls the decoding process.</param>
 /// <param name="node">XML node to be decoded.</param>
 /// <param name="obj">Object to encode the node into.</param>
 /// <returns>Returns the node used for the default decoding.</returns>
 public virtual XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object obj)
 {
     return node;
 }
Beispiel #25
0
 /// <summary>
 /// Hook for subclassers to Receive-process the node
 /// for the given object after encoding and return the
 /// Receive-processed node. This implementation returns
 /// the input node. The return value of this method
 /// is returned to the encoder from encode.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object to be encoded.</param>
 /// <param name="node">XML node that represents the default encoding.</param>
 /// <returns>Returns the resulting node of the encoding.</returns>
 public virtual XmlNode AfterEncode(mxCodec enc, Object obj, XmlNode node)
 {
     return(node);
 }
Beispiel #26
0
        /// <summary>
        /// Writes the given value as a child node of the given node.
        /// </summary>
        protected void WriteComplexAttribute(mxCodec enc, Object obj, string attr,
            Object value, XmlNode node)
        {
            XmlNode child = enc.Encode(value);

            if (child != null)
            {
                if (attr != null)
                {
                    mxCodec.SetAttribute(child, "as", attr);
                }

                node.AppendChild(child);
            }
            else
            {
                Trace.WriteLine("mxObjectCodec.encode: No node for " +
                    GetName() + "." + attr + ": " + value);
            }
        }
Beispiel #27
0
        /// <summary>
        /// Decodes an mxCell and uses the enclosing XML node as
        /// the user object for the cell (inversion).
        /// </summary>
        public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object obj)
        {
            XmlElement inner = (XmlElement)node;

            if (obj is mxCell)
            {
                mxCell cell = (mxCell)obj;
                String classname = GetName();

                if (!node.Name.Equals(classname))
                {
                    // Passes the inner graphical annotation node to the
                    // object codec for further processing of the cell.
                    XmlNode tmp = inner.GetElementsByTagName(classname)[0];

                    if (tmp != null && tmp.ParentNode == node)
                    {
                        inner = (XmlElement)tmp;

                        // Removes annotation and whitespace from node
                        XmlNode tmp2 = tmp.PreviousSibling;

                        while (tmp2 != null && tmp2.NodeType == XmlNodeType.Text)
                        {
                            XmlNode tmp3 = tmp2.PreviousSibling;

                            if (tmp2.Value.Trim().Length == 0)
                            {
                                tmp2.ParentNode.RemoveChild(tmp2);
                            }

                            tmp2 = tmp3;
                        }

                        // Removes more whitespace
                        tmp2 = tmp.NextSibling;

                        while (tmp2 != null && tmp2.NodeType == XmlNodeType.Text)
                        {
                            XmlNode tmp3 = tmp2.PreviousSibling;

                            if (tmp2.Value.Trim().Length == 0)
                            {
                                tmp2.ParentNode.RemoveChild(tmp2);
                            }

                            tmp2 = tmp3;
                        }

                        tmp.ParentNode.RemoveChild(tmp);
                    }
                    else
                    {
                        inner = null;
                    }

                    // Creates the user object out of the XML node
                    XmlElement value = (XmlElement)node.CloneNode(true);
                    cell.Value = value;
                    String id = value.GetAttribute("id");

                    if (id != null)
                    {
                        cell.Id = id;
                        value.RemoveAttribute("id");
                    }
                }
                else
                {
                    cell.Id = ((XmlElement)node).GetAttribute("id");
                }

                // Preprocesses and removes all Id-references
                // in order to use the correct encoder (this)
                // for the known references to cells (all).
                if (inner != null && idrefs != null)
                {
                    foreach (string attr in idrefs)
                    {
                        string rf = inner.GetAttribute(attr);

                        if (rf != null && rf.Length > 0)
                        {
                            inner.RemoveAttribute(attr);
                            Object tmp = (dec.Objects.ContainsKey(rf)) ? dec.Objects[rf] : null;

                            if (tmp == null)
                            {
                                tmp = dec.Lookup(rf);
                            }

                            if (tmp == null)
                            {
                                // Needs to decode forward reference
                                XmlNode element = dec.GetElementById(rf);

                                if (element != null)
                                {
                                    mxObjectCodec decoder = mxCodecRegistry
                                            .GetCodec(element.Name);

                                    if (decoder == null)
                                    {
                                        decoder = this;
                                    }

                                    tmp = decoder.Decode(dec, element);
                                }
                            }

                            SetFieldValue(obj, attr, tmp);
                        }
                    }
                }
            }

            return inner;
        }
Beispiel #28
0
        /// <summary>
        /// Reads the given attribute into the specified object.
        /// </summary>
        protected void DecodeAttribute(mxCodec dec, XmlNode attr, Object obj)
        {
            string name = attr.Name;

            if (!name.ToLower().Equals("as") &&
                !name.ToLower().Equals("id"))
            {
                Object value = attr.Value;
                string fieldname = GetFieldName(name);

                if (IsReference(obj, fieldname, value, false))
                {
                    Object tmp = dec.GetObject(value.ToString());

                    if (tmp == null)
                    {
                        Trace.WriteLine("mxObjectCodec.decode: No object for " +
                            GetName() + "." + fieldname + "=" + value);
                        return; // exit
                    }

                    value = tmp;
                }

                if (!IsExcluded(obj, fieldname, value, false))
                {
                    SetFieldValue(obj, fieldname, value);
                }
            }
        }
Beispiel #29
0
        /// <summary>
        /// Encodes the specified object and returns a node
        /// representing then given object. Calls beforeEncode
        /// after creating the node and afterEncode with the 
        /// resulting node after processing.
        /// Enc is a reference to the calling encoder. It is used
        /// to encode complex objects and create references.
        /// </summary>
        /// <param name="enc">Codec that controls the encoding process.</param>
        /// <param name="obj">Object to be encoded.</param>
        /// <returns>Returns the resulting XML node that represents the given object.</returns>
        public virtual XmlNode Encode(mxCodec enc, Object obj)
        {
            XmlNode node = enc.Document.CreateElement(GetName());

            obj = BeforeEncode(enc, obj, node);
            EncodeObject(enc, obj, node);

            return AfterEncode(enc, obj, node);
        }
Beispiel #30
0
        /// <summary>
        /// Reads the specified child into the given object.
        /// </summary>
        protected void DecodeChild(mxCodec dec, XmlNode child, Object obj)
        {
            string fieldname = GetFieldName(((XmlElement)child).GetAttribute("as"));

            if (fieldname == null || !IsExcluded(obj, fieldname, child, false))
            {
                Object template = GetFieldTemplate(obj, fieldname, child);
                Object value = null;

                if (child.Name.Equals("add"))
                {
                    value = ((XmlElement)child).GetAttribute("value");

                    if (value == null)
                    {
                        value = child.InnerText;
                    }
                }
                else
                {
                    value = dec.Decode(child, template);
                }

                AddObjectValue(obj, fieldname, value, template);
            }
        }
Beispiel #31
0
        /// <summary>
        /// Encode the given mxStylesheet.
        /// </summary>
        public override XmlNode Encode(mxCodec enc, Object obj)
        {
            XmlElement node = enc.Document.CreateElement(GetName());

            if (obj is mxStylesheet)
            {
                mxStylesheet stylesheet = (mxStylesheet) obj;

                foreach (KeyValuePair<string, Dictionary<string, Object>> entry in stylesheet.Styles)
                {
                    XmlElement styleNode = enc.Document.CreateElement("add");
                    styleNode.SetAttribute("as", entry.Key);

                    foreach (KeyValuePair<string, Object> entry2 in entry.Value)
                    {
                        XmlElement entryNode = enc.Document.CreateElement("add");
                        entryNode.SetAttribute("as", entry2.Key);
                        entryNode.SetAttribute("value", getStringValue(entry2));
                        styleNode.AppendChild(entryNode);
                    }

                    if (styleNode.ChildNodes.Count > 0)
                    {
                        node.AppendChild(styleNode);
                    }
                }
            }

            return node;
        }
Beispiel #32
0
 /// <summary>
 /// Hook for subclassers to pre-process the node for
 /// the specified object and return the node to be
 /// used for further processing by decode.
 /// The object is created based on the template in the
 /// calling method and is never null. This implementation
 /// returns the input node. The return value of this
 /// function is used in decode to perform
 /// the default decoding into the given object.
 /// </summary>
 /// <param name="dec">Codec that controls the decoding process.</param>
 /// <param name="node">XML node to be decoded.</param>
 /// <param name="obj">Object to encode the node into.</param>
 /// <returns>Returns the node used for the default decoding.</returns>
 public virtual XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object obj)
 {
     return(node);
 }
Beispiel #33
0
        /// <summary>
        /// Decodes an mxCell and uses the enclosing XML node as
        /// the user object for the cell (inversion).
        /// </summary>
        public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object obj)
        {
            XmlElement inner = (XmlElement)node;

            if (obj is mxCell)
            {
                mxCell cell      = (mxCell)obj;
                String classname = GetName();

                if (!node.Name.Equals(classname))
                {
                    // Passes the inner graphical annotation node to the
                    // object codec for further processing of the cell.
                    XmlNode tmp = inner.GetElementsByTagName(classname)[0];

                    if (tmp != null && tmp.ParentNode == node)
                    {
                        inner = (XmlElement)tmp;

                        // Removes annotation and whitespace from node
                        XmlNode tmp2 = tmp.PreviousSibling;

                        while (tmp2 != null && tmp2.NodeType == XmlNodeType.Text)
                        {
                            XmlNode tmp3 = tmp2.PreviousSibling;

                            if (tmp2.Value.Trim().Length == 0)
                            {
                                tmp2.ParentNode.RemoveChild(tmp2);
                            }

                            tmp2 = tmp3;
                        }

                        // Removes more whitespace
                        tmp2 = tmp.NextSibling;

                        while (tmp2 != null && tmp2.NodeType == XmlNodeType.Text)
                        {
                            XmlNode tmp3 = tmp2.PreviousSibling;

                            if (tmp2.Value.Trim().Length == 0)
                            {
                                tmp2.ParentNode.RemoveChild(tmp2);
                            }

                            tmp2 = tmp3;
                        }

                        tmp.ParentNode.RemoveChild(tmp);
                    }
                    else
                    {
                        inner = null;
                    }

                    // Creates the user object out of the XML node
                    XmlElement value = (XmlElement)node.CloneNode(true);
                    cell.Value = value;
                    String id = value.GetAttribute("id");

                    if (id != null)
                    {
                        cell.Id = id;
                        value.RemoveAttribute("id");
                    }
                }
                else
                {
                    cell.Id = ((XmlElement)node).GetAttribute("id");
                }

                // Preprocesses and removes all Id-references
                // in order to use the correct encoder (this)
                // for the known references to cells (all).
                if (inner != null && idrefs != null)
                {
                    foreach (string attr in idrefs)
                    {
                        string rf = inner.GetAttribute(attr);

                        if (rf != null && rf.Length > 0)
                        {
                            inner.RemoveAttribute(attr);
                            Object tmp = (dec.Objects.ContainsKey(rf)) ? dec.Objects[rf] : null;

                            if (tmp == null)
                            {
                                tmp = dec.Lookup(rf);
                            }

                            if (tmp == null)
                            {
                                // Needs to decode forward reference
                                XmlNode element = dec.GetElementById(rf);

                                if (element != null)
                                {
                                    mxObjectCodec decoder = mxCodecRegistry
                                                            .GetCodec(element.Name);

                                    if (decoder == null)
                                    {
                                        decoder = this;
                                    }

                                    tmp = decoder.Decode(dec, element);
                                }
                            }

                            SetFieldValue(obj, attr, tmp);
                        }
                    }
                }
            }

            return(inner);
        }
Beispiel #34
0
 /// <summary>
 /// Hook for subclassers to Receive-process the object after
 /// decoding. This implementation returns the given object
 /// without any changes. The return value of this method
 /// is returned to the decoder from decode.
 /// </summary>
 /// <param name="dec">Codec that controls the decoding process.</param>
 /// <param name="node">XML node to be decoded.</param>
 /// <param name="obj">Object that represents the default decoding.</param>
 /// <returns>Returns the result of the decoding process.</returns>
 public virtual Object AfterDecode(mxCodec dec, XmlNode node, Object obj)
 {
     return(obj);
 }
Beispiel #35
0
 /// <summary>
 /// Parses the given node into the object or returns a new object
 /// representing the given node.
 /// </summary>
 /// <param name="dec">Codec that controls the encoding process.</param>
 /// <param name="node">XML node to be decoded.</param>
 /// <returns>Returns the resulting object that represents the given XML node.</returns>
 public virtual Object Decode(mxCodec dec, XmlNode node)
 {
     return Decode(dec, node, null);
 }
Beispiel #36
0
 /// <summary>
 /// Calls decodeAttributes and decodeChildren for the given node.
 /// </summary>
 protected void DecodeNode(mxCodec dec, XmlNode node, Object obj)
 {
     if (node != null)
     {
         DecodeAttributes(dec, node, obj);
         DecodeChildren(dec, node, obj);
     }
 }
Beispiel #37
0
        /// <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;
        }
Beispiel #38
0
        /// <summary>
        /// Encodes the members of the given object into the given node.
        /// </summary>
        /// <param name="enc">Codec that controls the encoding process.</param>
        /// <param name="obj">Object whose fields should be encoded.</param>
        /// <param name="node">XML node that contains the encoded object.</param>
        protected void EncodeFields(mxCodec enc, Object obj, XmlNode node)
        {
            Type type = obj.GetType();
            PropertyInfo[] properties = type.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                if (property.CanRead && property.CanWrite)
                {
                    string name = property.Name;
                    Object value = GetFieldValue(obj, name);

                    // Removes Is-Prefix from bool properties
                    if (value is bool && name.StartsWith("Is"))
                    {
                        name = name.Substring(2);
                    }

                    name = name.Substring(0, 1).ToLower() + name.Substring(1);
                    EncodeValue(enc, obj, name, value, node);
                }
            }
        }
Beispiel #39
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dec">Codec that controls the encoding/decoding process.</param>
        /// <param name="node">XML node to be checked.</param>
        /// <param name="into">Optional object to pass-thru to the codec.</param>
        /// <returns>Returns true if the given node was processed as an include.</returns>
        public bool ProcessInclude(mxCodec dec, XmlNode node, Object into)
        {
            if (node.NodeType == XmlNodeType.Element
                    && node.Name.ToLower().Equals("include"))
            {
                string name = ((XmlElement)node).GetAttribute("name");

                if (name != null)
                {
                    XmlNode xml = mxUtils.LoadDocument(name).DocumentElement;

                    if (xml != null)
                    {
                        dec.Decode(xml, into);
                    }
                }

                return true;
            }

            return false;
        }
Beispiel #40
0
        /// <summary>
        /// Converts the given value according to the mappings and id-refs in
        /// this codec and uses writeAttribute to write the attribute into the
        /// given node.
        /// </summary>
        /// <param name="enc">Codec that controls the encoding process.</param>
        /// <param name="obj">Object whose member is going to be encoded.</param>
        /// <param name="fieldname"></param>
        /// <param name="value">Value of the property to be encoded.</param>
        /// <param name="node">XML node that contains the encoded object.</param>
        protected void EncodeValue(mxCodec enc, Object obj, string fieldname,
            Object value, XmlNode node)
        {
            if (value != null && !IsExcluded(obj, fieldname, value, true))
            {
                if (IsReference(obj, fieldname, value, true))
                {
                    Object tmp = enc.GetId(value);

                    if (tmp == null)
                    {
                        Trace.WriteLine("mxObjectCodec.encode: No ID for " +
                            GetName() + "." + fieldname + "=" + value);
                        return; // exit
                    }

                    value = tmp;
                }

                Object defaultValue = GetFieldValue(template, fieldname);

                if (fieldname == null || enc.IsEncodeDefaults
                        || defaultValue == null || !defaultValue.Equals(value))
                {
                    WriteAttribute(enc, obj, GetAttributeName(fieldname), value,
                            node);
                }
            }
        }
Beispiel #41
0
 /// <summary>
 /// Decodes all attributes of the given node using decodeAttribute.
 /// </summary>
 protected void DecodeAttributes(mxCodec dec, XmlNode node, Object obj)
 {
     XmlAttributeCollection attrs = node.Attributes;
     if (attrs != null)
     {
         foreach (XmlAttribute attr in attrs)
         {
             DecodeAttribute(dec, attr, obj);
         }
     }
 }
Beispiel #42
0
 /// <summary>
 /// Hook for subclassers to pre-process the object before
 /// encoding. This returns the input object. The return
 /// value of this function is used in encode to perform
 /// the default encoding into the given node.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object to be encoded.</param>
 /// <param name="node">XML node to encode the object into.</param>
 /// <returns>Returns the object to be encoded by the default encoding.</returns>
 public virtual Object BeforeEncode(mxCodec enc, Object obj, XmlNode node)
 {
     return(obj);
 }
Beispiel #43
0
        /// <summary>
        /// Reads the given attribute into the specified object.
        /// </summary>
        protected void DecodeChildren(mxCodec dec, XmlNode node, Object obj)
        {
            XmlNode child = node.FirstChild;

            while (child != null)
            {
                if (child.NodeType == XmlNodeType.Element
                        && !ProcessInclude(dec, child, obj))
                {
                    DecodeChild(dec, child, obj);
                }

                child = child.NextSibling;
            }
        }
Beispiel #44
0
 /// <summary>
 ///  Encodes the value of each member in then given obj
 ///  into the given node using encodeFields and encodeElements.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object to be encoded.</param>
 /// <param name="node">XML node that contains the encoded object.</param>
 protected virtual void EncodeObject(mxCodec enc, Object obj, XmlNode node)
 {
     mxCodec.SetAttribute(node, "id", enc.GetId(obj));
     EncodeFields(enc, obj, node);
     EncodeElements(enc, obj, node);
 }
Beispiel #45
0
 /// <summary>
 /// Encodes the child objects of arrays, dictionaries and enumerables.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object whose child objects should be encoded.</param>
 /// <param name="node">XML node that contains the encoded object.</param>
 protected void EncodeElements(mxCodec enc, Object obj, XmlNode node)
 {
     if (obj.GetType().IsArray)
     {
         foreach (Object o in ((Object[])obj))
         {
             EncodeValue(enc, obj, null, o, node);
         }
     }
     else if (obj is IDictionary)
     {
         foreach (KeyValuePair<string, string> entry in ((IDictionary)mapping))
         {
             EncodeValue(enc, obj, entry.Key, entry.Value, node);
         }
     }
     else if (obj is IEnumerable)
     {
         foreach (Object value in ((IEnumerable)obj))
         {
             EncodeValue(enc, obj, null, value, node);
         }
     }
 }
Beispiel #46
0
        /// <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);
        }
Beispiel #47
0
 /// <summary>
 ///  Encodes the value of each member in then given obj
 ///  into the given node using encodeFields and encodeElements.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object to be encoded.</param>
 /// <param name="node">XML node that contains the encoded object.</param>
 protected virtual void EncodeObject(mxCodec enc, Object obj, XmlNode node)
 {
     mxCodec.SetAttribute(node, "id", enc.GetId(obj));
     EncodeFields(enc, obj, node);
     EncodeElements(enc, obj, node);
 }
Beispiel #48
0
 /// <summary>
 /// Hook for subclassers to Receive-process the object after
 /// decoding. This implementation returns the given object
 /// without any changes. The return value of this method
 /// is returned to the decoder from decode.
 /// </summary>
 /// <param name="dec">Codec that controls the decoding process.</param>
 /// <param name="node">XML node to be decoded.</param>
 /// <param name="obj">Object that represents the default decoding.</param>
 /// <returns>Returns the result of the decoding process.</returns>
 public virtual Object AfterDecode(mxCodec dec, XmlNode node, Object obj)
 {
     return obj;
 }
Beispiel #49
0
        /// <summary>
        /// Writes the given value into node using writePrimitiveAttribute
        /// or writeComplexAttribute depending on the type of the value.
        /// </summary>
        /// 
        protected void WriteAttribute(mxCodec enc, Object obj, string attr,
            Object value, XmlNode node)
        {
            value = ConvertValueToXml(value);

            if (IsPrimitiveValue(value))
            {
                WritePrimitiveAttribute(enc, obj, attr, value, node);
            }
            else
            {
                WriteComplexAttribute(enc, obj, attr, value, node);
            }
        }
Beispiel #50
0
 /// <summary>
 /// Hook for subclassers to Receive-process the node
 /// for the given object after encoding and return the
 /// Receive-processed node. This implementation returns
 /// the input node. The return value of this method
 /// is returned to the encoder from encode.
 /// </summary>
 /// <param name="enc">Codec that controls the encoding process.</param>
 /// <param name="obj">Object to be encoded.</param>
 /// <param name="node">XML node that represents the default encoding.</param>
 /// <returns>Returns the resulting node of the encoding.</returns>
 public virtual XmlNode AfterEncode(mxCodec enc, Object obj, XmlNode node)
 {
     return node;
 }
Beispiel #51
0
        /// <summary>
        /// Writes the given value as an attribute of the given node.
        /// </summary>
        protected void WritePrimitiveAttribute(mxCodec enc, Object obj,
            string attr, Object value, XmlNode node)
        {
            if (attr == null || obj is IDictionary)
            {
                XmlNode child = enc.Document.CreateElement("add");

                if (attr != null)
                {
                    mxCodec.SetAttribute(child, "as", attr);
                }

                mxCodec.SetAttribute(child, "value", value);
                node.AppendChild(child);
            }
            else
            {
                mxCodec.SetAttribute(node, attr, value);
            }
        }
Beispiel #52
0
 /// <summary>
 /// Parses the given node into the object or returns a new object
 /// representing the given node.
 /// </summary>
 /// <param name="dec">Codec that controls the encoding process.</param>
 /// <param name="node">XML node to be decoded.</param>
 /// <returns>Returns the resulting object that represents the given XML node.</returns>
 public virtual Object Decode(mxCodec dec, XmlNode node)
 {
     return(Decode(dec, node, null));
 }
Beispiel #53
0
        /// <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;
        }
Beispiel #54
0
 /// <summary>
 /// Encodes the given mxGraphModel by writing a (flat) XML sequence
 /// of cell nodes as produced by the mxCellCodec. The sequence is
 /// wrapped-up in a node with the name root.
 /// </summary>
 protected override void EncodeObject(mxCodec enc, Object obj, XmlNode node)
 {
     if (obj is mxGraphModel)
     {
         XmlNode rootNode = enc.Document.CreateElement("root");
         mxGraphModel model = (mxGraphModel)obj;
         enc.EncodeCell((mxICell)model.Root, rootNode, true);
         node.AppendChild(rootNode);
     }
 }