|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | + |
| 6 | +namespace DocumentFormat.OpenXml |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Represents the mc:AlternateContent element of markup |
| 10 | + /// compatibility. |
| 11 | + /// </summary> |
| 12 | + public class AlternateContent : OpenXmlCompositeElement |
| 13 | + { |
| 14 | + private static string _mcNamespace = @"http://schemas.openxmlformats.org/markup-compatibility/2006"; |
| 15 | + private static byte _mcNamespaceId = byte.MaxValue; |
| 16 | + |
| 17 | + private static string tagName = "AlternateContent"; |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Initializes a new instance of the AlternateContent |
| 21 | + /// class. |
| 22 | + /// </summary> |
| 23 | + public AlternateContent() |
| 24 | + : base() |
| 25 | + { |
| 26 | + } |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Initializes a new instance of the AlternateContent |
| 30 | + /// class by using the supplied IEnumerable elements. |
| 31 | + /// </summary> |
| 32 | + /// <param name="childElements"> |
| 33 | + /// Represents all child elements. |
| 34 | + /// </param> |
| 35 | + public AlternateContent(IEnumerable<OpenXmlElement> childElements) |
| 36 | + : base(childElements) |
| 37 | + { |
| 38 | + } |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Initializes a new instance of the AlternateContent |
| 42 | + /// class by using the supplied OpenXmlElement elements. |
| 43 | + /// </summary> |
| 44 | + /// <param name="childElements"> |
| 45 | + /// Represents all child elements. |
| 46 | + /// </param> |
| 47 | + public AlternateContent(params OpenXmlElement[] childElements) |
| 48 | + : base(childElements) |
| 49 | + { |
| 50 | + } |
| 51 | + |
| 52 | + /// <param name="outerXml">The outer XML of the element. |
| 53 | + /// </param> |
| 54 | + /// <summary> |
| 55 | + /// Initializes a new instance of the AlternateContent |
| 56 | + /// class by using the supplied string. |
| 57 | + /// </summary> |
| 58 | + public AlternateContent(string outerXml) |
| 59 | + : base(outerXml) |
| 60 | + { |
| 61 | + } |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Gets a value that represents the markup compatibility |
| 65 | + /// namespace. |
| 66 | + /// </summary> |
| 67 | + public static string MarkupCompatibilityNamespace |
| 68 | + { |
| 69 | + get { return _mcNamespace; } |
| 70 | + } |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Gets a value that represents the markup compatibility |
| 74 | + /// namespace ID. |
| 75 | + /// </summary> |
| 76 | + public static byte MarkupCompatibilityNamespaceId |
| 77 | + { |
| 78 | + get |
| 79 | + { |
| 80 | + if (_mcNamespaceId == byte.MaxValue) |
| 81 | + { |
| 82 | + _mcNamespaceId = NamespaceIdMap.GetNamespaceId(_mcNamespace); |
| 83 | + } |
| 84 | + |
| 85 | + return _mcNamespaceId; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Gets a value that represents the tag name of the |
| 91 | + /// AlternateContent element. |
| 92 | + /// </summary> |
| 93 | + public static string TagName |
| 94 | + { |
| 95 | + get { return tagName; } |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Gets a value that represents the local name of the |
| 100 | + /// AlternateContent element. |
| 101 | + /// </summary> |
| 102 | + public override string LocalName |
| 103 | + { |
| 104 | + get { return tagName; } |
| 105 | + } |
| 106 | + |
| 107 | + internal override byte NamespaceId |
| 108 | + { |
| 109 | + get { return MarkupCompatibilityNamespaceId; } |
| 110 | + } |
| 111 | + |
| 112 | + private static string[] attributeTagNames = { }; |
| 113 | + private static byte[] attributeNamespaceIds = { }; |
| 114 | + |
| 115 | + internal override string[] AttributeTagNames |
| 116 | + { |
| 117 | + get |
| 118 | + { |
| 119 | + return attributeTagNames; |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + internal override byte[] AttributeNamespaceIds |
| 124 | + { |
| 125 | + get |
| 126 | + { |
| 127 | + return attributeNamespaceIds; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + internal override OpenXmlElement ElementFactory(byte namespaceId, string name) |
| 132 | + { |
| 133 | + if (MarkupCompatibilityNamespaceId == namespaceId && AlternateContentChoice.TagName == name) |
| 134 | + return new AlternateContentChoice(); |
| 135 | + |
| 136 | + if (MarkupCompatibilityNamespaceId == namespaceId && AlternateContentFallback.TagName == name) |
| 137 | + return new AlternateContentFallback(); |
| 138 | + |
| 139 | + return null; |
| 140 | + } |
| 141 | + |
| 142 | + /// <summary> |
| 143 | + /// Appends a new child of type T:DocumentFormat.OpenXml.AlternateContentChoice |
| 144 | + /// to the current element. |
| 145 | + /// </summary> |
| 146 | + /// <returns> |
| 147 | + /// </returns> |
| 148 | + public AlternateContentChoice AppendNewAlternateContentChoice() |
| 149 | + { |
| 150 | + AlternateContentChoice child = new AlternateContentChoice(); |
| 151 | + this.AppendChild(child); |
| 152 | + return child; |
| 153 | + } |
| 154 | + /// <summary> |
| 155 | + /// Appends a new child of type T:DocumentFormat.OpenXml.AlternateContentFallback |
| 156 | + /// to the current element. |
| 157 | + /// </summary> |
| 158 | + /// <returns> |
| 159 | + /// </returns> |
| 160 | + public AlternateContentFallback AppendNewAlternateContentFallback() |
| 161 | + { |
| 162 | + AlternateContentFallback child = new AlternateContentFallback(); |
| 163 | + this.AppendChild(child); |
| 164 | + return child; |
| 165 | + } |
| 166 | + |
| 167 | + internal override OpenXmlSimpleType AttributeFactory(byte namespaceId, string name) |
| 168 | + { |
| 169 | + return null; |
| 170 | + } |
| 171 | + |
| 172 | + /// <returns>The cloned node. </returns> |
| 173 | + /// <summary> |
| 174 | + /// When a node is overridden in a derived class, |
| 175 | + /// CloneNode creates a duplicate of the node. |
| 176 | + /// </summary> |
| 177 | + /// <param name="deep"> |
| 178 | + /// True to recursively clone the subtree under |
| 179 | + /// the specified node; False to clone only the node |
| 180 | + /// itself. |
| 181 | + /// </param> |
| 182 | + public override OpenXmlElement CloneNode(bool deep) |
| 183 | + { |
| 184 | + return CloneImp<AlternateContent>(deep); |
| 185 | + } |
| 186 | + |
| 187 | + /// <summary> |
| 188 | + /// The type ID of the element. |
| 189 | + /// </summary> |
| 190 | + internal override int ElementTypeId |
| 191 | + { |
| 192 | + get { return ReservedElementTypeIds.AlternateContentId; } |
| 193 | + } |
| 194 | + |
| 195 | + /// <summary> |
| 196 | + /// Indicates whether this element is available in a specific version of an Office Application. |
| 197 | + /// Always returns true since AlternateContent is allowed |
| 198 | + /// in every version. |
| 199 | + /// </summary> |
| 200 | + /// <param name="version">The Office file format version.</param> |
| 201 | + /// <returns>Returns true if the element is defined in the specified version.</returns> |
| 202 | + internal override bool IsInVersion(FileFormatVersions version) |
| 203 | + { |
| 204 | + return true; |
| 205 | + } |
| 206 | + } |
| 207 | +} |
0 commit comments