/// <summary>
        /// Creates a new <see cref="XliffElement"/> depending on the XLIFF element Name.
        /// </summary>
        /// <param name="name">The XLIFF element Name.</param>
        /// <returns>An instance of a class associated with the specified XLIFF Name.</returns>
        public override XliffElement CreateElement(XmlNameInfo name)
        {
            XliffElement result;

            result = null;
            if ((name.Namespace == this.Namespace) && (name.LocalName == "element1"))
            {
                result = new CustomElement1(this.Prefix, this.Namespace);
                ((CustomElement1)result).Initialize();
            }
            else if ((name.Namespace == this.Namespace) && (name.LocalName == "element2"))
            {
                result = new CustomElement2(this.Prefix, this.Namespace);
                ((CustomElement2)result).Initialize();
            }
            else
            {
                return(new GenericElement());
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Creates an extension member that stores the element data that can later be stored in an extension.
        /// </summary>
        /// <param name="nameInfo">The name of the element.</param>
        /// <returns>An extension member that stores the element data.</returns>
        public XliffElement CreateElement(IExtensionNameInfo nameInfo)
        {
            XliffElement result;

            result = null;
            if ((nameInfo.Namespace == this.ns) && (nameInfo.LocalName == "element1"))
            {
                result = new CustomElement1(this.prefix, this.ns);
                ((CustomElement1)result).Initialize();
            }
            else if ((nameInfo.Namespace == this.ns) && (nameInfo.LocalName == "element2"))
            {
                result = new CustomElement2(this.prefix, this.ns);
                ((CustomElement2)result).Initialize();
            }
            else
            {
                result = new GenericElement();
            }

            return(result);
        }
        /// <summary>
        /// Creates a new <see cref="XliffElement"/> depending on the XLIFF element Name.
        /// </summary>
        /// <param name="name">The XLIFF element Name.</param>
        /// <returns>An instance of a class associated with the specified XLIFF Name.</returns>
        public override XliffElement CreateElement(XmlNameInfo name)
        {
            XliffElement result;

            result = null;
            if ((name.Namespace == this.Namespace) && (name.LocalName == "element1"))
            {
                result = new CustomElement1(this.Prefix, this.Namespace);
                ((CustomElement1)result).Initialize();
            }
            else if ((name.Namespace == this.Namespace) && (name.LocalName == "element2"))
            {
                result = new CustomElement2(this.Prefix, this.Namespace);
                ((CustomElement2)result).Initialize();
            }
            else
            {
                return new GenericElement();
            }

            return result;
        }
        public void XliffElement_CollapseChildrenWithScope()
        {
            IExtensible extensible;
            CustomExtension extension1;
            CustomExtension extension2;
            CustomElement1 element1;
            CustomElement2 element2;
            List<XliffElement> elementList;
            List<Source> sourceList;
            PlainText text;
            Segment segment;
            Source source;
            StandaloneCode code;
            Unit unit;
            XliffDocument document;

            code = new StandaloneCode();
            text = new PlainText();
            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            extensible = document.Files[0];

            extension1 = new CustomExtension("namespace");
            element1 = new CustomElement1("pre1", "namespace");
            extension1.AddChild(new ElementInfo(new XmlNameInfo("localname"), element1));
            extensible.Extensions.Add(extension1);

            extension2 = new CustomExtension("namespace");
            element2 = new CustomElement2("pre1", "namespace");
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), element2));
            source = new Source();
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), source));
            extensible.Extensions.Add(extension2);

            Console.WriteLine("Test with none.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.None);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            Console.WriteLine("Test with current element.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.CurrentElement);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");

            Console.WriteLine("Test with default.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Default);
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            Console.WriteLine("Test with default with current element.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Default | CollapseScope.CurrentElement);
            Assert.AreEqual(7, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(9, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren<Source>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.All);
            Assert.AreEqual(10, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren<Source>(CollapseScope.All);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            Console.WriteLine("Test with extensions with core elements for Source.");
            sourceList = document.CollapseChildren<Source>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            Console.WriteLine("Test with extensions without core elements.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(3, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.TopLevelDescendants);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.TopLevelDescendants | CollapseScope.CoreElements);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
        }