示例#1
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);
        }
示例#2
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;
        }