Skip to content

Commit cc73f83

Browse files
authored
Separate AlternateContent into own files (#350)
1 parent 9b0b78a commit cc73f83

12 files changed

+1199
-1140
lines changed
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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+
}
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
/// Defines an mc:Choice element in mc:AlternateContent.
10+
/// </summary>
11+
public class AlternateContentChoice : OpenXmlCompositeElement
12+
{
13+
private static string tagName = "Choice";
14+
15+
/// <summary>
16+
/// Initializes a new instance of the
17+
/// AlternateContentChoice class.
18+
/// </summary>
19+
public AlternateContentChoice()
20+
: base()
21+
{
22+
}
23+
24+
/// <summary>
25+
/// Initializes a new instance of the
26+
/// AlternateContentChoice class by using the supplied
27+
/// IEnumerable elements.
28+
/// </summary>
29+
/// <param name="childElements">
30+
/// Represents all child elements.
31+
/// </param>
32+
public AlternateContentChoice(IEnumerable<OpenXmlElement> childElements)
33+
: base(childElements)
34+
{
35+
}
36+
37+
/// <summary>
38+
/// Initializes a new instance of the
39+
/// AlternateContentChoice class by using the supplied
40+
/// OpenXmlElement elements.
41+
/// </summary>
42+
/// <param name="childElements">
43+
/// Represents all child elements.
44+
/// </param>
45+
public AlternateContentChoice(params OpenXmlElement[] childElements)
46+
: base(childElements)
47+
{
48+
}
49+
50+
/// <param name="outerXml">
51+
/// The outer XML of the element.
52+
/// </param>
53+
/// <summary>
54+
/// Initializes a new instance of the
55+
/// AlternateContentChoice class by using the supplied
56+
/// string.
57+
/// </summary>
58+
public AlternateContentChoice(string outerXml)
59+
: base(outerXml)
60+
{
61+
}
62+
63+
/// <summary>
64+
/// Gets a value that represents the tag name of the
65+
/// Choice element.
66+
/// </summary>
67+
public static string TagName
68+
{
69+
get { return tagName; }
70+
}
71+
/// <summary>
72+
/// Gets the local name of the Choice element.
73+
/// </summary>
74+
public override string LocalName
75+
{
76+
get { return tagName; }
77+
}
78+
79+
internal override byte NamespaceId
80+
{
81+
get { return AlternateContent.MarkupCompatibilityNamespaceId; }
82+
}
83+
84+
private static string[] attributeTagNames = { "Requires" };
85+
private static byte[] attributeNamespaceIds = { 0 };
86+
87+
internal override string[] AttributeTagNames
88+
{
89+
get
90+
{
91+
return attributeTagNames;
92+
}
93+
}
94+
95+
internal override byte[] AttributeNamespaceIds
96+
{
97+
get
98+
{
99+
return attributeNamespaceIds;
100+
}
101+
}
102+
103+
internal override OpenXmlSimpleType AttributeFactory(byte namespaceId, string name)
104+
{
105+
if (0 == namespaceId && "Requires" == name)
106+
return new StringValue();
107+
return null;
108+
}
109+
110+
/// <summary>
111+
/// <para>Gets or sets a whitespace-delimited list of namespace prefixes that identify the
112+
/// namespaces a markup consumer needs in order to understand and select that
113+
/// Choice and process the content.</para>
114+
/// <para> Represents the attribute in a schema. </para>
115+
/// </summary>
116+
public StringValue Requires
117+
{
118+
get { return (StringValue)Attributes[0]; }
119+
set { Attributes[0] = value; }
120+
}
121+
122+
internal override OpenXmlElement ElementFactory(byte namespaceId, string name)
123+
{
124+
OpenXmlElement newElement = null;
125+
126+
if (this.Parent != null &&
127+
this.Parent is AlternateContent)
128+
{
129+
OpenXmlElement parentsParentElemnt = this.Parent.Parent;
130+
if (parentsParentElemnt != null)
131+
{
132+
newElement = parentsParentElemnt.ElementFactory(namespaceId, name);
133+
if (newElement == null)
134+
{
135+
newElement = parentsParentElemnt.AlternateContentElementFactory(namespaceId, name);
136+
}
137+
}
138+
}
139+
140+
return newElement;
141+
}
142+
143+
/// <returns>The cloned node. </returns>
144+
/// <summary>
145+
/// When a node is overridden in a derived class, CloneNode creates a duplicate
146+
/// of the node.
147+
/// </summary>
148+
/// <param name="deep">
149+
/// True to recursively clone the subtree under the specified node; False
150+
/// to clone only the node itself.
151+
/// </param>
152+
public override OpenXmlElement CloneNode(bool deep)
153+
{
154+
return CloneImp<AlternateContentChoice>(deep);
155+
}
156+
157+
/// <summary>
158+
/// The type ID of the element.
159+
/// </summary>
160+
internal override int ElementTypeId
161+
{
162+
get { return ReservedElementTypeIds.AlternateContentChoiceId; }
163+
}
164+
165+
/// <summary>
166+
/// Indicates whether this element is available in a specific version of an Office Application.
167+
/// This method always returns true since AlternateContentFallback is available in every version.
168+
/// </summary>
169+
/// <param name="version">The Office file format version.</param>
170+
/// <returns>Returns true if the element is defined in the specified version.</returns>
171+
internal override bool IsInVersion(FileFormatVersions version)
172+
{
173+
return true;
174+
}
175+
}
176+
}

0 commit comments

Comments
 (0)