Ejemplo n.º 1
0
        /// <summary>
        /// Apply all changes to the document/node.
        /// </summary>
        /// <returns>Same document/node.</returns>
        /// <param name="dom">DOM document/node</param>
        public XNode Apply(XNode dom)
        {
            ICursor cursor =
                new DomCursor(
                    new Yaapii.Atoms.Enumerable.ManyOf <XNode>(dom)
                    );

            int pos = 1;

            IStack stack = new DomStack();

            foreach (var dir in this._directives)
            {
                try
                {
                    cursor = dir.Exec(dom, cursor, stack);
                }
                //catch (ImpossibleModificationException ex)
                //{
                //    throw new ImpossibleModificationException(
                //        new Formatted("directive {0}: {1}", pos, dir).AsString());
                //}
                catch (Exception ex) //TODO: Original catches DOMException. We don't have that. But do we have something similar?
                {
                    throw new ImpossibleModificationException(
                              new Formatted("Exception at dir {0}: {1} ({2})", pos, dir, ex.Message).AsString());
                }
                ++pos;
            }
            return(dom);
        }
        public void AddsAndRetrieves()
        {
            var stack  = new DomStack();
            var first  = new FkCursor();
            var second = new FkCursor();

            stack.Push(first); stack.Push(second);

            Assert.Equal(stack.Pop(), second);
            Assert.Equal(stack.Pop(), first);
        }