/// <summary>
        /// Serializes the text of a provider.
        /// </summary>
        /// <param name="provider">The provider that contains the text to serialize.</param>
        private void SerializeTextImpl(IXliffDataProvider provider)
        {
            string text;

            text = provider.GetXliffText();
            if (text != null)
            {
                this.writer.WriteString(text);
            }
        }
 /// <summary>
 /// Serializes an <see cref="XliffElement"/> to the stream using the specified Xml element Name and namespace.
 /// The method creates an element and writes attributes if necessary, then writes out text followed by notes
 /// if the element supports notes. It then uses recursion to do the same for children.
 /// </summary>
 /// <param name="name">The name of the XmlElement to create.</param>
 /// <param name="namespaceName">The namespace of the XmlElement to create.</param>
 /// <param name="prefix">The prefix Name of the XmlElement to create.</param>
 /// <param name="provider">The content to serialize.</param>
 /// <param name="extraNamespace">A set of namespaces to configure on the element. The key is the name
 /// of the namespace and the value is the URI of the namespace.</param>
 private void SerializeImpl(
     string name,
     string namespaceName,
     string prefix,
     IXliffDataProvider provider,
     Dictionary <string, string> extraNamespace)
 {
     this.SerializeImpl(
         name,
         namespaceName,
         prefix,
         provider,
         extraNamespace,
         true);
 }
        /// <summary>
        /// Serializes attributes to the current Xml element.
        /// </summary>
        /// <param name="provider">The data provider that contains attributes to serialize.</param>
        private void SerializeAttributesImpl(IXliffDataProvider provider)
        {
            if (provider != null)
            {
                IEnumerable <IAttributeDataProvider> attributes;

                attributes = provider.GetXliffAttributes();
                if (attributes != null)
                {
                    foreach (IAttributeDataProvider attribute in attributes)
                    {
                        bool shouldWrite;

                        shouldWrite = this.ShouldWriteAttributeString(attribute);
                        if (!shouldWrite)
                        {
                            foreach (IAttributeDataProvider dependency in attribute.ExplicitOutputDependencies)
                            {
                                shouldWrite = this.ShouldWriteAttributeString(dependency);
                                if (shouldWrite)
                                {
                                    break;
                                }
                            }

                            if (!shouldWrite && (attribute.OutputResolver != null))
                            {
                                shouldWrite = attribute.OutputResolver.IsOutputRequired(attribute.LocalName);
                            }
                        }

                        if (shouldWrite)
                        {
                            this.WriteAttributeString(attribute);
                        }
                    }
                }
            }
        }
 public void TestInitialize()
 {
     this.element = new Revision();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this._element  = new Ignorable();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element = new Item();
     this.provider = this.element;
 }
Beispiel #7
0
 public void TestInitialize()
 {
     this.element  = new Glossary();
     this.provider = this.element;
 }
Beispiel #8
0
        /// <summary>
        /// Serializes the text of a provider.
        /// </summary>
        /// <param name="provider">The provider that contains the text to serialize.</param>
        private void SerializeTextImpl(IXliffDataProvider provider)
        {
            string text;

            text = provider.GetXliffText();
            if (text != null)
            {
                this.writer.WriteString(text);
            }
        }
 public void TestInitialize()
 {
     this._element  = new XliffDocument("source");
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element  = new CommentTag();
     this.provider = this.element;
 }
Beispiel #11
0
        /// <summary>
        /// Gets the children from a provider grouped by the type specified by the provider.
        /// </summary>
        /// <param name="provider">The provider that contains the children.</param>
        /// <returns>A dictionary whose key is the type of the objects contained in the value. The value is a list of
        /// objects that should be output for the type. Objects that have no corresponding type will be grouped with a
        /// created key of type object.</returns>
        private static Dictionary<Type, List<ElementInfo>> GetProviderChildrenGroupedByType(IXliffDataProvider provider)
        {
            IEnumerable<ElementInfo> children;
            IEnumerable<OutputItem> order;
            Dictionary<Type, List<ElementInfo>> result;
            List<ElementInfo> unorderedItems;

            result = new Dictionary<Type, List<ElementInfo>>();
            order = provider.XliffOutputOrder;
            unorderedItems = new List<ElementInfo>();

            children = provider.GetXliffChildren();
            if (children != null)
            {
                // Create a list for each type so all items of the same type are grouped together.
                foreach (OutputItem item in order)
                {
                    if (item.ItemType == OutputItemType.Child)
                    {
                        result[item.ChildType] = new List<ElementInfo>();
                    }
                }

                // Add each child to the appropriate list.
                foreach (ElementInfo child in children)
                {
                    List<ElementInfo> list;

                    if (result.TryGetValue(child.Element.GetType(), out list))
                    {
                        list.Add(child);
                    }
                    else
                    {
                        bool added;

                        added = false;

                        // The class may derive from another so try checking the runtime type.
                        foreach (Type key in result.Keys)
                        {
                            if (key.IsInstanceOfType(child.Element))
                            {
                                result[key].Add(child);
                                added = true;
                                break;
                            }
                        }

                        if (!added)
                        {
                            // Order doesn't matter so append it.
                            unorderedItems.Add(child);
                        }
                    }
                }
            }

            // Merge all the unordered items to a generic group. If object is already specified as a key by the
            // provider then there won't be any unordered items because all items will at least be instances of objects.
            if (unorderedItems.Count > 0)
            {
                result[typeof(object)] = unorderedItems;
            }

            return result;
        }
Beispiel #12
0
 public void TestInitialize()
 {
     this.element  = new ProcessingInstructionTag();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element = new ProfileData();
     this.provider = this.element;
 }
Beispiel #14
0
 public void TestInitialize()
 {
     this._element  = new StandaloneCode();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new MetaGroup();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element = new Glossary();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element  = new ProfileData();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element = new Normalization();
     this.provider = this.element;
 }
Beispiel #19
0
 public void TestInitialize()
 {
     this._element  = new MarkedSpanEnd();
     this._provider = this._element;
 }
        /// <summary>
        /// Verifies that the data stored in an extension match what is expected. Asserts will be raised for any
        /// differences.
        /// </summary>
        /// <param name="indent">Indent level to use when writing log information.</param>
        /// <param name="expected">The data that are expected to be present.</param>
        /// <param name="actual">The element that contains the actual data.</param>
        private void VerifyData(string indent, XliffData expected, IXliffDataProvider actual)
        {
            Assert.AreEqual(expected.Type, actual.GetType(), "Type is incorrect.");
            Assert.AreEqual(expected.HasChildren, actual.HasXliffChildren, "HasXliffChildren is incorrect.");
            Assert.AreEqual(expected.HasText, actual.HasXliffText, "HasXliffText is incorrect.");

            indent += "  ";
            this.VerifyAttributeData(indent, expected.Attributes, actual.GetXliffAttributes());
            this.VerifyChildren(indent, expected.Children, actual.GetXliffChildren());
            Assert.AreEqual(expected.Text, actual.GetXliffText());
        }
Beispiel #21
0
 /// <summary>
 /// Serializes an <see cref="XliffElement"/> to the stream using the specified Xml element Name and namespace.
 /// The method creates an element and writes attributes if necessary, then writes out text followed by notes
 /// if the element supports notes. It then uses recursion to do the same for children.
 /// </summary>
 /// <param name="name">The name of the XmlElement to create.</param>
 /// <param name="namespaceName">The namespace of the XmlElement to create.</param>
 /// <param name="prefix">The prefix Name of the XmlElement to create.</param>
 /// <param name="provider">The content to serialize.</param>
 /// <param name="extraNamespace">A set of namespaces to configure on the element. The key is the name
 /// of the namespace and the value is the URI of the namespace.</param>
 private void SerializeImpl(
     string name,
     string namespaceName,
     string prefix,
     IXliffDataProvider provider,
     Dictionary<string, string> extraNamespace)
 {
     this.SerializeImpl(
                        name,
                        namespaceName,
                        prefix,
                        provider,
                        extraNamespace,
                        true);
 }
 public void TestInitialize()
 {
     this.element  = new ChangeTrack();
     this.provider = this.element;
 }
Beispiel #23
0
 public void TestInitialize()
 {
     this._element  = new MetaGroup();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new PlainText();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element  = new SpanningCodeStart();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new StandaloneCode();
     this._provider = this._element;
 }
Beispiel #27
0
 public void TestInitialize()
 {
     this._element  = new PlainText();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element = new ProcessingInstructionTag();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element = new ChangeTrack();
     this.provider = this.element;
 }
        /// <summary>
        /// Gets the children from a provider grouped by the type specified by the provider.
        /// </summary>
        /// <param name="provider">The provider that contains the children.</param>
        /// <returns>A dictionary whose key is the type of the objects contained in the value. The value is a list of
        /// objects that should be output for the type. Objects that have no corresponding type will be grouped with a
        /// created key of type object.</returns>
        private static Dictionary <Type, List <ElementInfo> > GetProviderChildrenGroupedByType(IXliffDataProvider provider)
        {
            IEnumerable <ElementInfo> children;
            IEnumerable <OutputItem>  order;
            Dictionary <Type, List <ElementInfo> > result;
            List <ElementInfo> unorderedItems;

            result         = new Dictionary <Type, List <ElementInfo> >();
            order          = provider.XliffOutputOrder;
            unorderedItems = new List <ElementInfo>();

            children = provider.GetXliffChildren();
            if (children != null)
            {
                // Create a list for each type so all items of the same type are grouped together.
                foreach (OutputItem item in order)
                {
                    if (item.ItemType == OutputItemType.Child)
                    {
                        result[item.ChildType] = new List <ElementInfo>();
                    }
                }

                // Add each child to the appropriate list.
                foreach (ElementInfo child in children)
                {
                    List <ElementInfo> list;

                    if (result.TryGetValue(child.Element.GetType(), out list))
                    {
                        list.Add(child);
                    }
                    else
                    {
                        bool added;

                        added = false;

                        // The class may derive from another so try checking the runtime type.
                        foreach (Type key in result.Keys)
                        {
                            if (key.IsInstanceOfType(child.Element))
                            {
                                result[key].Add(child);
                                added = true;
                                break;
                            }
                        }

                        if (!added)
                        {
                            // Order doesn't matter so append it.
                            unorderedItems.Add(child);
                        }
                    }
                }
            }

            // Merge all the unordered items to a generic group. If object is already specified as a key by the
            // provider then there won't be any unordered items because all items will at least be instances of objects.
            if (unorderedItems.Count > 0)
            {
                result[typeof(object)] = unorderedItems;
            }

            return(result);
        }
 public void TestInitialize()
 {
     this.element  = new Revision();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this._element = new CodePoint();
     this._provider = this._element;
 }
        /// <summary>
        /// Serializes an <see cref="XliffElement"/> to the stream using the specified Xml element Name and namespace.
        /// The method creates an element and writes attributes if necessary, then writes out text followed by notes
        /// if the element supports notes. It then uses recursion to do the same for children.
        /// </summary>
        /// <param name="name">The name of the XmlElement to create.</param>
        /// <param name="namespaceName">The namespace of the XmlElement to create.</param>
        /// <param name="prefix">The prefix Name of the XmlElement to create.</param>
        /// <param name="provider">The content to serialize.</param>
        /// <param name="extraNamespace">A set of namespaces to configure on the element. The key is the name
        /// of the namespace and the value is the URI of the namespace.</param>
        /// <param name="serializeInnerContent">True to serialize inner content. If false only the opening and closing
        /// tags will be serialized along with attributes.</param>
        private void SerializeImpl(
            string name,
            string namespaceName,
            string prefix,
            IXliffDataProvider provider,
            Dictionary <string, string> extraNamespace,
            bool serializeInnerContent)
        {
            // The name may be null for elements that are just inline elements for others. For example, the
            // PlainText class represents text within a Source node, but doesn't actually require an Xml element
            // so it won't have a Name.
            if (name != null)
            {
                this.writer.WriteStartElement(prefix, name, namespaceName);

                if (extraNamespace != null)
                {
                    foreach (string key in extraNamespace.Keys)
                    {
                        this.writer.WriteAttributeString(
                            NamespacePrefixes.XmlNamespace,
                            key,
                            string.Empty,
                            extraNamespace[key]);
                    }
                }

                this.SerializeAttributesImpl(provider);
                this.SerializeExtensions(provider as IExtensible, true, false);
            }

            if (serializeInnerContent)
            {
                Comparison <OutputItem> comparer;
                List <OutputItem>       order;
                Dictionary <Type, List <ElementInfo> > children;
                List <ElementInfo> unorderedChildren;
                bool serializedChildAsObject;
                bool serializedText;
                bool serializedExtensions;

                serializedChildAsObject = false;
                serializedText          = false;
                serializedExtensions    = false;

                children = XliffWriter.GetProviderChildrenGroupedByType(provider);

                comparer = delegate(OutputItem item1, OutputItem item2)
                {
                    int result;

                    if (item1.GroupOrdinal == item2.GroupOrdinal)
                    {
                        result = 0;
                    }
                    else if (item1.GroupOrdinal < item2.GroupOrdinal)
                    {
                        result = -1;
                    }
                    else
                    {
                        result = 1;
                    }

                    return(result);
                };

                order = new List <OutputItem>(provider.XliffOutputOrder);
                order.Sort(comparer);

                foreach (OutputItem item in order)
                {
                    switch (item.ItemType)
                    {
                    case OutputItemType.Child:
                        this.SerializeChildImpl(children[item.ChildType]);

                        // Object was specified by the provider so don't treat it as the unordered list.
                        serializedChildAsObject |= item.ChildType == typeof(object);
                        break;

                    case OutputItemType.Extension:
                        this.SerializeExtensions(provider as IExtensible, false, true);
                        serializedExtensions = true;
                        break;

                    case OutputItemType.Text:
                        this.SerializeTextImpl(provider);
                        serializedText = true;
                        break;

                    default:
                        Debug.Assert(false, item.ItemType.ToString() + " is not handled.");
                        break;
                    }
                }

                // Serialize everything that hasn't been serialized yet. Order doesn't matter at this point.
                if (!serializedText)
                {
                    this.SerializeTextImpl(provider);
                }

                if (!serializedChildAsObject && children.TryGetValue(typeof(object), out unorderedChildren))
                {
                    this.SerializeChildImpl(unorderedChildren);
                }

                if (!serializedExtensions)
                {
                    this.SerializeExtensions(provider as IExtensible, false, true);
                }
            }

            if (name != null)
            {
                if (provider.HasXliffChildren || provider.HasXliffText)
                {
                    this.writer.WriteFullEndElement();
                }
                else
                {
                    this.writer.WriteEndElement();
                }
            }
        }
Beispiel #34
0
 public void TestInitialize()
 {
     this._element  = new Skeleton();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new MarkedSpanStart();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new OriginalData();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new SpanningCodeStart();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element  = new ResourceItemSource();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this._element  = new MetadataContainer();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element = new Translation();
     this.provider = this.element;
 }
Beispiel #41
0
        /// <summary>
        /// Serializes attributes to the current Xml element.
        /// </summary>
        /// <param name="provider">The data provider that contains attributes to serialize.</param>
        private void SerializeAttributesImpl(IXliffDataProvider provider)
        {
            if (provider != null)
            {
                IEnumerable<IAttributeDataProvider> attributes;

                attributes = provider.GetXliffAttributes();
                if (attributes != null)
                {
                    foreach (IAttributeDataProvider attribute in attributes)
                    {
                        bool shouldWrite;

                        shouldWrite = this.ShouldWriteAttributeString(attribute);
                        if (!shouldWrite)
                        {
                            foreach (IAttributeDataProvider dependency in attribute.ExplicitOutputDependencies)
                            {
                                shouldWrite = this.ShouldWriteAttributeString(dependency);
                                if (shouldWrite)
                                {
                                    break;
                                }
                            }

                            if (!shouldWrite && (attribute.OutputResolver != null))
                            {
                                shouldWrite = attribute.OutputResolver.IsOutputRequired(attribute.LocalName);
                            }
                        }

                        if (shouldWrite)
                        {
                            this.WriteAttributeString(attribute);
                        }
                    }
                }
            }
        }
 public void TestInitialize()
 {
     this.element = new CommentTag();
     this.provider = this.element;
 }
Beispiel #43
0
        /// <summary>
        /// Serializes an <see cref="XliffElement"/> to the stream using the specified Xml element Name and namespace.
        /// The method creates an element and writes attributes if necessary, then writes out text followed by notes
        /// if the element supports notes. It then uses recursion to do the same for children.
        /// </summary>
        /// <param name="name">The name of the XmlElement to create.</param>
        /// <param name="namespaceName">The namespace of the XmlElement to create.</param>
        /// <param name="prefix">The prefix Name of the XmlElement to create.</param>
        /// <param name="provider">The content to serialize.</param>
        /// <param name="extraNamespace">A set of namespaces to configure on the element. The key is the name
        /// of the namespace and the value is the URI of the namespace.</param>
        /// <param name="serializeInnerContent">True to serialize inner content. If false only the opening and closing
        /// tags will be serialized along with attributes.</param>
        private void SerializeImpl(
            string name,
            string namespaceName,
            string prefix,
            IXliffDataProvider provider,
            Dictionary<string, string> extraNamespace,
            bool serializeInnerContent)
        {
            // The name may be null for elements that are just inline elements for others. For example, the
            // PlainText class represents text within a Source node, but doesn't actually require an Xml element
            // so it won't have a Name.
            if (name != null)
            {
                this.writer.WriteStartElement(prefix, name, namespaceName);

                if (extraNamespace != null)
                {
                    foreach (string key in extraNamespace.Keys)
                    {
                        this.writer.WriteAttributeString(
                                                          NamespacePrefixes.XmlNamespace,
                                                          key,
                                                          string.Empty,
                                                          extraNamespace[key]);
                    }
                }

                this.SerializeAttributesImpl(provider);
                this.SerializeExtensions(provider as IExtensible, true, false);
            }

            if (serializeInnerContent)
            {
                Comparison<OutputItem> comparer;
                List<OutputItem> order;
                Dictionary<Type, List<ElementInfo>> children;
                List<ElementInfo> unorderedChildren;
                bool serializedChildAsObject;
                bool serializedText;
                bool serializedExtensions;

                serializedChildAsObject = false;
                serializedText = false;
                serializedExtensions = false;

                children = XliffWriter.GetProviderChildrenGroupedByType(provider);

                comparer = delegate(OutputItem item1, OutputItem item2)
                {
                    int result;

                    if (item1.GroupOrdinal == item2.GroupOrdinal)
                    {
                        result = 0;
                    }
                    else if (item1.GroupOrdinal < item2.GroupOrdinal)
                    {
                        result = -1;
                    }
                    else
                    {
                        result = 1;
                    }

                    return result;
                };

                order = new List<OutputItem>(provider.XliffOutputOrder);
                order.Sort(comparer);

                foreach (OutputItem item in order)
                {
                    switch (item.ItemType)
                    {
                        case OutputItemType.Child:
                            this.SerializeChildImpl(children[item.ChildType]);

                            // Object was specified by the provider so don't treat it as the unordered list.
                            serializedChildAsObject |= item.ChildType == typeof(object);
                            break;

                        case OutputItemType.Extension:
                            this.SerializeExtensions(provider as IExtensible, false, true);
                            serializedExtensions = true;
                            break;

                        case OutputItemType.Text:
                            this.SerializeTextImpl(provider);
                            serializedText = true;
                            break;

                        default:
                            Debug.Assert(false, item.ItemType.ToString() + " is not handled.");
                            break;
                    }
                }

                // Serialize everything that hasn't been serialized yet. Order doesn't matter at this point.
                if (!serializedText)
                {
                    this.SerializeTextImpl(provider);
                }

                if (!serializedChildAsObject && children.TryGetValue(typeof(object), out unorderedChildren))
                {
                    this.SerializeChildImpl(unorderedChildren);
                }

                if (!serializedExtensions)
                {
                    this.SerializeExtensions(provider as IExtensible, false, true);
                }
            }

            if (name != null)
            {
                if (provider.HasXliffChildren || provider.HasXliffText)
                {
                    this.writer.WriteFullEndElement();
                }
                else
                {
                    this.writer.WriteEndElement();
                }
            }
        }
 public void TestInitialize()
 {
     this._element = new XliffDocument("source");
     this._provider = this._element;
 }
Beispiel #45
0
 public void TestInitialize()
 {
     this.element  = new Item();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element  = new Reference();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element = new ResourceItemSource();
     this.provider = this.element;
 }
 public void TestInitialize()
 {
     this.element = new Reference();
     this.provider = this.element;
 }
Beispiel #49
0
 public void TestInitialize()
 {
     this._element  = new Data();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new MetadataContainer();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this._element = new File();
     this._provider = this._element;
 }
 public void TestInitialize()
 {
     this.element  = new Normalization();
     this.provider = this.element;
 }
Beispiel #53
0
 public void TestInitialize()
 {
     this.element  = new Translation();
     this.provider = this.element;
 }
Beispiel #54
0
 public void TestInitialize()
 {
     this._element  = new CodePoint();
     this._provider = this._element;
 }