コード例 #1
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = new List <ElementInfo>();
            this.AddChildElementsToList(this.References, ref result);

            if (this.Source != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.ResourceDataModule, ElementNames.Source);
                result.Add(new ElementInfo(name, this.Source));
            }

            if (this.Target != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.ResourceDataModule, ElementNames.Target);
                result.Add(new ElementInfo(name, this.Target));
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = base.GetChildren();

            if (this.Term != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.GlossaryModule,
                    NamespaceValues.GlossaryModule,
                    Modules.Glossary.XmlNames.ElementNames.Term);
                result.Add(new ElementInfo(name, this.Term));
            }

            this.AddChildElementsToList(this.Translations, ref result);

            if (this.Definition != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.GlossaryModule,
                    NamespaceValues.GlossaryModule,
                    Modules.Glossary.XmlNames.ElementNames.Definition);
                result.Add(new ElementInfo(name, this.Definition));
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementInfo"/> class.
        /// </summary>
        /// <param name="name">The Xml name of the element.</param>
        /// <param name="element">The element this class describes.</param>
        public ElementInfo(XmlNameInfo name, XliffElement element)
            : base(name)
        {
            ArgValidator.Create(element, "element").IsNotNull();

            this.Element = element;
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementInfo"/> class.
        /// </summary>
        /// <param name="name">The Xml name of the element.</param>
        /// <param name="element">The element this class describes.</param>
        public ElementInfo(XmlNameInfo name, XliffElement element)
            : base(name)
        {
            ArgValidator.Create(element, "element").IsNotNull();

            this.Element = element;
        }
コード例 #5
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = base.GetChildren();
            if (this.HasNotes)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Notes);
                result.Add(new ElementInfo(name, this.noteContainer));
            }

            if (this.Changes != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.ChangeTrackingModule,
                    NamespaceValues.ChangeTrackingModule,
                    Modules.ChangeTracking.XmlNames.ElementNames.ChangeTrack);
                result.Add(new ElementInfo(name, this.Changes));
            }

            if (this.Metadata != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.MetadataModule,
                    NamespaceValues.MetadataModule,
                    Modules.Metadata.XmlNames.ElementNames.Metadata);
                result.Add(new ElementInfo(name, this.Metadata));
            }

            if (this.ProfileData != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.SizeRestrictionModule,
                    NamespaceValues.SizeRestrictionModule,
                    Modules.SizeRestriction.XmlNames.ElementNames.ProfileData);
                result.Add(new ElementInfo(name, this.ProfileData));
            }

            if (this.ValidationRules != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.ValidationModule,
                    NamespaceValues.ValidationModule,
                    Modules.Validation.XmlNames.ElementNames.Validation);
                result.Add(new ElementInfo(name, this.ValidationRules));
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = base.GetChildren();

            if (this.Glossary != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.GlossaryModule,
                    NamespaceValues.GlossaryModule,
                    Modules.Glossary.XmlNames.ElementNames.Glossary);
                result.Add(new ElementInfo(name, this.Glossary));
            }

            if (this.HasMatches)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.TranslationCandidatesModule,
                    NamespaceValues.TranslationCandidatesModule,
                    Modules.TranslationCandidates.XmlNames.ElementNames.Matches);
                result.Add(new ElementInfo(name, this.translationCandidates));
            }

            if (this.OriginalData != null)
            {
                ElementInfo child;
                XmlNameInfo name;

                name  = new XmlNameInfo(NamespaceValues.Core, ElementNames.OriginalData);
                child = new ElementInfo(name, this.OriginalData);
                result.Add(child);
            }

            if (this.ResourceData != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.ResourceDataModule,
                    NamespaceValues.ResourceDataModule,
                    Modules.ResourceData.XmlNames.ElementNames.ResourceData);
                result.Add(new ElementInfo(name, this.ResourceData));
            }

            // DEV NOTE: Order of segments must be maintained during serialization and deserialization so make sure
            // the order can be preserved. Using a type of list maintains order, but if you change this.Resources
            // to another type (like dictionary), make sure you have a way to maintain order.
            this.AddChildElementsToList(this.Resources, ref result);

            return(result);
        }
コード例 #7
0
ファイル: XliffData.cs プロジェクト: x600/XLIFF2-Object-Model
        /// <summary>
        /// Adds an attribute.
        /// </summary>
        /// <param name="prefix">The Xml prefix of the attribute.</param>
        /// <param name="ns">The namespace of the attribute.</param>
        /// <param name="localName">The local name of the attribute.</param>
        /// <param name="value">The value of the attribute.</param>
        /// <param name="hasValue">True if the attribute has a value, otherwise false.</param>
        public AttributeData AddAttribute(string prefix, string ns, string localName, object value, bool hasValue)
        {
            AttributeData data;
            XmlNameInfo   name;

            name = new XmlNameInfo(prefix, ns, localName);
            data = new AttributeData(this.Type.Name, name, false, value, hasValue);
            this.Attributes.Add(data);

            return(data);
        }
コード例 #8
0
        /// <summary>
        /// Tries to set the value of an attribute.
        /// </summary>
        /// <param name="name">The XLIFF Name of the attribute.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>This method always returns true.</returns>
        protected override bool TrySetPropertyValue(XmlNameInfo name, string value)
        {
            XmlNameInfo nameWithoutPrefix;

            this.RegisterAttribute(name.Namespace, name.LocalName, name.LocalName, value);

            nameWithoutPrefix = new XmlNameInfo(name.Prefix, name.Namespace, name.LocalName);
            this.SetPropertyValue(value, name.LocalName);

            return(true);
        }
コード例 #9
0
        /// <summary>
        /// Tries to set the value of an attribute.
        /// </summary>
        /// <param name="name">The XLIFF Name of the attribute.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>This method always returns true.</returns>
        protected override bool TrySetPropertyValue(XmlNameInfo name, string value)
        {
            bool result;

            result = false;
            if (name.Namespace == this.Namespace)
            {
                this.SetPropertyValue(value, "Attribute3");
                result = true;
            }

            return(result);
        }
コード例 #10
0
        /// <summary>
        /// Tries to set the value of an attribute.
        /// </summary>
        /// <param name="name">The XLIFF Name of the attribute.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>This method always returns true.</returns>
        protected override bool TrySetPropertyValue(XmlNameInfo name, string value)
        {
            bool result;

            result = false;
            if (name.Namespace == this.Namespace)
            {
                this.SetPropertyValue(value, "Attribute3");
                result = true;
            }

            return result;
        }
コード例 #11
0
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="info">The object to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo info)
        {
            if (info.Namespace == null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(info.Prefix, NamespaceValues.Core, info.LocalName);
                info = new ElementInfo(name, info.Element);
            }

            this.children.Add(info);

            return(true);
        }
コード例 #12
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = new List <ElementInfo>();

            if (this.Normalization != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.SizeRestrictionModule, ElementNames.Normalization);
                result.Add(new ElementInfo(name, this.Normalization));
            }

            return(result);
        }
コード例 #13
0
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="info">The object to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo info)
        {
            ArgValidator.ParentIsNull(info.Element);
            Utilities.SetParent(info.Element, this);

            if (info.Namespace == null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(info.Prefix, NamespaceValues.Core, info.LocalName);
                info = new ElementInfo(name, info.Element);
            }

            this.children.Value.Add(info);

            return(true);
        }
コード例 #14
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = base.GetChildren();

            if (this.Metadata != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                    NamespacePrefixes.MetadataModule,
                    NamespaceValues.MetadataModule,
                    ElementNames.Metadata);
                result.Add(new ElementInfo(name, this.Metadata));
            }

            if (this.OriginalData != null)
            {
                ElementInfo child;
                XmlNameInfo name;

                name  = new XmlNameInfo(NamespaceValues.Core, ElementNames.OriginalData);
                child = new ElementInfo(name, this.OriginalData);
                result.Add(child);
            }

            if (this.Source != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Source);
                result.Add(new ElementInfo(name, this.Source));
            }

            if (this.Target != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Target);
                result.Add(new ElementInfo(name, this.Target));
            }

            return(result);
        }
コード例 #15
0
        /// <summary>
        /// Tries to set the value of an attribute.
        /// </summary>
        /// <param name="name">The XLIFF Name of the attribute.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>This method always returns true.</returns>
        protected override bool TrySetPropertyValue(XmlNameInfo name, string value)
        {
            bool result;

            result = false;
            if (name.Namespace == this.Namespace)
            {
                if (name.LocalName == "attribute1")
                {
                    this.Attribute1 = value;
                    result          = true;
                }
                else
                {
                    this.SetPropertyValue(value, "Attribute2");
                    result = true;
                }
            }

            return(result);
        }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
        /// <summary>
        /// Deserializes the attributes at the reader's current position and stores them in the
        /// <paramref name="currentElement"/>.
        /// </summary>
        /// <param name="currentElement">The element associated with the reader's current position.</param>
        private void DeserializeAttributes(IXliffDataConsumer currentElement)
        {
            if (this.reader.MoveToFirstAttribute())
            {
                IExtensible extensible;

                extensible = currentElement as IExtensible;
                do
                {
                    SetAttributeResult setResult;
                    XmlNameInfo        name;

                    name      = new XmlNameInfo(this.reader.Prefix, this.reader.NamespaceURI, this.reader.LocalName);
                    setResult = currentElement.TrySetAttributeValue(name, this.reader.Value);
                    if ((setResult == SetAttributeResult.InvalidAttribute) ||
                        ((setResult == SetAttributeResult.PossibleExtension) &&
                         (this.StoreAttributeExtension(extensible) == SetAttributeResult.InvalidAttribute)))
                    {
                        string message;

                        if (string.IsNullOrEmpty(name.Prefix))
                        {
                            message = name.LocalName;
                        }
                        else
                        {
                            message = string.Join(":", name.Prefix, name.LocalName);
                        }

                        message = string.Format(
                            Properties.Resources.XliffReader_InvalidAttributeName_Format,
                            message,
                            currentElement.GetType().Name);
                        throw new NotSupportedException(message);
                    }
                }while (this.reader.MoveToNextAttribute());
            }
        }
コード例 #18
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List <ElementInfo> GetChildren()
        {
            List <ElementInfo> result;

            result = new List <ElementInfo>();

            if (this.Source != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Source);
                result.Add(new ElementInfo(name, this.Source));
            }

            if (this.Target != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Target);
                result.Add(new ElementInfo(name, this.Target));
            }

            return(result);
        }
コード例 #19
0
 /// <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)
 {
     return(new TestElement());
 }
コード例 #20
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List<ElementInfo> GetChildren()
        {
            List<ElementInfo> result;

            result = new List<ElementInfo>();

            if (this.Normalization != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.SizeRestrictionModule, ElementNames.Normalization);
                result.Add(new ElementInfo(name, this.Normalization));
            }

            return result;
        }
コード例 #21
0
        /// <summary>
        /// Adds an attribute.
        /// </summary>
        /// <param name="prefix">The Xml prefix of the attribute.</param>
        /// <param name="ns">The namespace of the attribute.</param>
        /// <param name="localName">The local name of the attribute.</param>
        /// <param name="value">The value of the attribute.</param>
        /// <param name="hasValue">True if the attribute has a value, otherwise false.</param>
        public AttributeData AddAttribute(string prefix, string ns, string localName, object value, bool hasValue)
        {
            AttributeData data;
            XmlNameInfo name;

            name = new XmlNameInfo(prefix, ns, localName);
            data = new AttributeData(this.Type.Name, name, false, value, hasValue);
            this.Attributes.Add(data);

            return data;
        }
コード例 #22
0
        /// <summary>
        /// Tries to set the value of an attribute.
        /// </summary>
        /// <param name="name">The XLIFF Name of the attribute.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>This method always returns true.</returns>
        protected override bool TrySetPropertyValue(XmlNameInfo name, string value)
        {
            bool result;

            result = false;
            if (name.Namespace == this.Namespace)
            {
                if (name.LocalName == "attribute1")
                {
                    this.Attribute1 = value;
                    result = true;
                }
                else
                {
                    this.SetPropertyValue(value, "Attribute2");
                    result = true;
                }
            }

            return result;
        }
コード例 #23
0
        /// <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;
        }
コード例 #24
0
        /// <summary>
        /// Deserializes the element at the reader's current position as a new <see cref="XliffElement"/>.
        /// </summary>
        private void DeserializeElement()
        {
            IXliffDataConsumer newElement;
            XmlNameInfo name;
            bool handlerCreated;
            bool isEmpty;

            handlerCreated = false;

            // Create a new element based on the XLIFF Name. Some elements don't necessarily have XliffElements
            // (ex. Notes) so false is returned.
            name = new XmlNameInfo(this.reader.Prefix, this.reader.NamespaceURI, this.reader.LocalName);
            newElement = this.currentElementState.Consumer.CreateXliffElement(name);
            if (newElement == null)
            {
                // Don't store native XLIFF elements as extensions.
                if (this.settings.IncludeExtensions &&
                    !Utilities.IsCoreNamespace(this.reader.NamespaceURI) &&
                    !Utilities.IsModuleNamespace(this.reader.NamespaceURI))
                {
                    IExtensible extensible;

                    extensible = this.currentElementState.Consumer as IExtensible;
                    if ((extensible != null) && extensible.SupportsElementExtensions && this.handlers.IsValueCreated)
                    {
                        IExtensionHandler handler;

                        if (this.handlers.Value.TryGetValue(this.reader.NamespaceURI, out handler) ||
                            this.handlers.Value.TryGetValue(XliffReader.DefaultHandlerKey, out handler))
                        {
                            ExtensionNameInfo extensionName;
                            XliffElement createdElement;

                            extensionName = new ExtensionNameInfo(name.Prefix, name.Namespace, name.LocalName);
                            createdElement = handler.CreateElement(extensionName);
                            handler.StoreElement(extensible, new ElementInfo(name, createdElement));

                            newElement = createdElement;
                            handlerCreated = true;
                        }
                        else
                        {
                            Debug.Assert(false, "Default handler was not found.");
                        }
                    }
                }

                if (newElement == null)
                {
                    string message;

                    message = string.Format(
                                            Properties.Resources.XliffElement_UnknownElement_Format,
                                            this.reader.Name,
                                            this.currentElementState.Consumer.GetType().Name);
                    throw new FormatException(message);
                }
                else
                {
                    int ordinal;

                    ordinal = this.currentElementState.GetOrdinal(OutputItemType.Extension, typeof(IExtension));
                    if (ordinal < this.currentElementState.LastOrdinalRead)
                    {
                        string message;

                        message = string.Format(
                                                Properties.Resources.XliffElement_ElementOutOfOrder_Format,
                                                this.currentElementState.Consumer.GetType().Name,
                                                newElement.GetType().Name,
                                                name.Namespace,
                                                name.LocalName);
                        throw new FormatException(message);
                    }

                    this.currentElementState.LastOrdinalRead = ordinal;
                }
            }
            else
            {
                int ordinal;

                ordinal = this.currentElementState.GetOrdinal(OutputItemType.Child, newElement.GetType());
                if (ordinal < this.currentElementState.LastOrdinalRead)
                {
                    string message;

                    message = string.Format(
                                            Properties.Resources.XliffElement_ElementOutOfOrder_Format,
                                            this.currentElementState.Consumer.GetType().Name,
                                            newElement.GetType().Name,
                                            name.Namespace,
                                            name.LocalName);
                    throw new FormatException(message);
                }

                this.currentElementState.LastOrdinalRead = ordinal;
            }

            // Check if empty element before reading attributes because reading attributes moves the reader.
            isEmpty = this.reader.IsEmptyElement;

            Debug.Assert(newElement != null, "newElement is null.");
            this.DeserializeAttributes(newElement);

            // Extensions are not stored directly as children.
            if (!handlerCreated)
            {
                this.currentElementState.Consumer.AddXliffChild(name, newElement);
            }

            if (!isEmpty)
            {
                this.elementStack.Push(this.currentElementState);
                this.currentElementState = new ElementState(newElement);
            }
            else
            {
                this.ValidateElementState(new ElementState(newElement));
            }
        }
コード例 #25
0
 /// <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)
 {
     return(Reflector.CreateElement(name) ?? new GenericElement());
 }
コード例 #26
0
        /// <summary>
        /// Deserializes the element at the reader's current position as a new <see cref="XliffElement"/>.
        /// </summary>
        private void DeserializeElement()
        {
            IXliffDataConsumer newElement;
            XmlNameInfo        name;
            bool handlerCreated;
            bool isEmpty;

            handlerCreated = false;

            // Create a new element based on the XLIFF Name. Some elements don't necessarily have XliffElements
            // (ex. Notes) so false is returned.
            name       = new XmlNameInfo(this.reader.Prefix, this.reader.NamespaceURI, this.reader.LocalName);
            newElement = this.currentElementState.Consumer.CreateXliffElement(name);
            if (newElement == null)
            {
                // Don't store native XLIFF elements as extensions.
                if (this.settings.IncludeExtensions &&
                    !Utilities.IsCoreNamespace(this.reader.NamespaceURI) &&
                    !Utilities.IsModuleNamespace(this.reader.NamespaceURI))
                {
                    IExtensible extensible;

                    extensible = this.currentElementState.Consumer as IExtensible;
                    if ((extensible != null) && extensible.SupportsElementExtensions && this.handlers.IsValueCreated)
                    {
                        IExtensionHandler handler;

                        if (this.handlers.Value.TryGetValue(this.reader.NamespaceURI, out handler) ||
                            this.handlers.Value.TryGetValue(XliffReader.DefaultHandlerKey, out handler))
                        {
                            ExtensionNameInfo extensionName;
                            XliffElement      createdElement;

                            extensionName  = new ExtensionNameInfo(name.Prefix, name.Namespace, name.LocalName);
                            createdElement = handler.CreateElement(extensionName);
                            handler.StoreElement(extensible, new ElementInfo(name, createdElement));

                            newElement     = createdElement;
                            handlerCreated = true;
                        }
                        else
                        {
                            Debug.Assert(false, "Default handler was not found.");
                        }
                    }
                }

                if (newElement == null)
                {
                    string message;

                    message = string.Format(
                        Properties.Resources.XliffElement_UnknownElement_Format,
                        this.reader.Name,
                        this.currentElementState.Consumer.GetType().Name);
                    throw new FormatException(message);
                }
                else
                {
                    int ordinal;

                    ordinal = this.currentElementState.GetOrdinal(OutputItemType.Extension, typeof(IExtension));
                    if (ordinal < this.currentElementState.LastOrdinalRead)
                    {
                        string message;

                        message = string.Format(
                            Properties.Resources.XliffElement_ElementOutOfOrder_Format,
                            this.currentElementState.Consumer.GetType().Name,
                            newElement.GetType().Name,
                            name.Namespace,
                            name.LocalName);
                        throw new FormatException(message);
                    }

                    this.currentElementState.LastOrdinalRead = ordinal;
                }
            }
            else
            {
                int ordinal;

                ordinal = this.currentElementState.GetOrdinal(OutputItemType.Child, newElement.GetType());
                if (ordinal < this.currentElementState.LastOrdinalRead)
                {
                    string message;

                    message = string.Format(
                        Properties.Resources.XliffElement_ElementOutOfOrder_Format,
                        this.currentElementState.Consumer.GetType().Name,
                        newElement.GetType().Name,
                        name.Namespace,
                        name.LocalName);
                    throw new FormatException(message);
                }

                this.currentElementState.LastOrdinalRead = ordinal;
            }

            // Check if empty element before reading attributes because reading attributes moves the reader.
            isEmpty = this.reader.IsEmptyElement;

            Debug.Assert(newElement != null, "newElement is null.");
            this.DeserializeAttributes(newElement);

            // Extensions are not stored directly as children.
            if (!handlerCreated)
            {
                this.currentElementState.Consumer.AddXliffChild(name, newElement);
            }

            if (!isEmpty)
            {
                this.elementStack.Push(this.currentElementState);
                this.currentElementState = new ElementState(newElement);
            }
            else
            {
                this.ValidateElementState(new ElementState(newElement));
            }
        }
コード例 #27
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List<ElementInfo> GetChildren()
        {
            List<ElementInfo> result;

            result = base.GetChildren();

            if (this.Term != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.GlossaryModule,
                                       NamespaceValues.GlossaryModule,
                                       Modules.Glossary.XmlNames.ElementNames.Term);
                result.Add(new ElementInfo(name, this.Term));
            }

            this.AddChildElementsToList(this.Translations, ref result);

            if (this.Definition != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.GlossaryModule,
                                       NamespaceValues.GlossaryModule,
                                       Modules.Glossary.XmlNames.ElementNames.Definition);
                result.Add(new ElementInfo(name, this.Definition));
            }

            return result;
        }
コード例 #28
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List<ElementInfo> GetChildren()
        {
            List<ElementInfo> result;

            result = new List<ElementInfo>();
            this.AddChildElementsToList(this.References, ref result);

            if (this.Source != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.ResourceDataModule, ElementNames.Source);
                result.Add(new ElementInfo(name, this.Source));
            }

            if (this.Target != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.ResourceDataModule, ElementNames.Target);
                result.Add(new ElementInfo(name, this.Target));
            }

            return result;
        }
コード例 #29
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List<ElementInfo> GetChildren()
        {
            List<ElementInfo> result;

            result = base.GetChildren();

            if (this.Glossary != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.GlossaryModule,
                                       NamespaceValues.GlossaryModule,
                                       Modules.Glossary.XmlNames.ElementNames.Glossary);
                result.Add(new ElementInfo(name, this.Glossary));
            }

            if (this.HasMatches)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.TranslationCandidatesModule,
                                       NamespaceValues.TranslationCandidatesModule,
                                       Modules.TranslationCandidates.XmlNames.ElementNames.Matches);
                result.Add(new ElementInfo(name, this.translationCandidates));
            }

            if (this.OriginalData != null)
            {
                ElementInfo child;
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.OriginalData);
                child = new ElementInfo(name, this.OriginalData);
                result.Add(child);
            }

            if (this.ResourceData != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.ResourceDataModule,
                                       NamespaceValues.ResourceDataModule,
                                       Modules.ResourceData.XmlNames.ElementNames.ResourceData);
                result.Add(new ElementInfo(name, this.ResourceData));
            }

            // DEV NOTE: Order of segments must be maintained during serialization and deserialization so make sure
            // the order can be preserved. Using a type of list maintains order, but if you change this.Resources
            // to another type (like dictionary), make sure you have a way to maintain order.
            this.AddChildElementsToList(this.Resources, ref result);

            return result;
        }
コード例 #30
0
        /// <summary>
        /// Gets the child <see cref="XliffElement"/>s contained within this object.
        /// </summary>
        /// <returns>A list of child elements stored as a pair consisting of the XLIFF Name for the child and
        /// the child itself.</returns>
        protected override List<ElementInfo> GetChildren()
        {
            List<ElementInfo> result;

            result = new List<ElementInfo>();
            if (this.HasNotes)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Notes);
                result.Add(new ElementInfo(name, this.noteContainer));
            }

            if (this.Changes != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.ChangeTrackingModule,
                                       NamespaceValues.ChangeTrackingModule,
                                       Modules.ChangeTracking.XmlNames.ElementNames.ChangeTrack);
                result.Add(new ElementInfo(name, this.Changes));
            }

            if (this.Metadata != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.MetadataModule,
                                       NamespaceValues.MetadataModule,
                                       Modules.Metadata.XmlNames.ElementNames.Metadata);
                result.Add(new ElementInfo(name, this.Metadata));
            }

            if (this.ProfileData != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.SizeRestrictionModule,
                                       NamespaceValues.SizeRestrictionModule,
                                       Modules.SizeRestriction.XmlNames.ElementNames.ProfileData);
                result.Add(new ElementInfo(name, this.ProfileData));
            }

            if (this.RestrictionProfiles != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.SizeRestrictionModule,
                                       NamespaceValues.SizeRestrictionModule,
                                       Modules.SizeRestriction.XmlNames.ElementNames.Profiles);
                result.Add(new ElementInfo(name, this.RestrictionProfiles));
            }

            if (this.ResourceData != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.ResourceDataModule,
                                       NamespaceValues.ResourceDataModule,
                                       Modules.ResourceData.XmlNames.ElementNames.ResourceData);
                result.Add(new ElementInfo(name, this.resourceData));
            }

            if (this.ValidationRules != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(
                                       NamespacePrefixes.ValidationModule,
                                       NamespaceValues.ValidationModule,
                                       Modules.Validation.XmlNames.ElementNames.Validation);
                result.Add(new ElementInfo(name, this.ValidationRules));
            }

            this.AddChildElementsToList(this.Containers, ref result);

            if (this.Skeleton != null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(NamespaceValues.Core, ElementNames.Skeleton);
                result.Add(new ElementInfo(name, this.Skeleton));
            }

            return result;
        }
コード例 #31
0
        /// <summary>
        /// Deserializes the attributes at the reader's current position and stores them in the
        /// <paramref name="currentElement"/>.
        /// </summary>
        /// <param name="currentElement">The element associated with the reader's current position.</param>
        private void DeserializeAttributes(IXliffDataConsumer currentElement)
        {
            if (this.reader.MoveToFirstAttribute())
            {
                IExtensible extensible;

                extensible = currentElement as IExtensible;
                do
                {
                    SetAttributeResult setResult;
                    XmlNameInfo name;

                    name = new XmlNameInfo(this.reader.Prefix, this.reader.NamespaceURI, this.reader.LocalName);
                    setResult = currentElement.TrySetAttributeValue(name, this.reader.Value);
                    if ((setResult == SetAttributeResult.InvalidAttribute) ||
                        ((setResult == SetAttributeResult.PossibleExtension) &&
                            (this.StoreAttributeExtension(extensible) == SetAttributeResult.InvalidAttribute)))
                    {
                        string message;

                        if (string.IsNullOrEmpty(name.Prefix))
                        {
                            message = name.LocalName;
                        }
                        else
                        {
                            message = string.Join(":", name.Prefix, name.LocalName);
                        }

                        message = string.Format(
                                                Properties.Resources.XliffReader_InvalidAttributeName_Format,
                                                message,
                                                currentElement.GetType().Name);
                        throw new NotSupportedException(message);
                    }
                }
                while (this.reader.MoveToNextAttribute());
            }
        }