1: /*
2: Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>
3:
4: Permission is hereby granted, free of charge, to any person obtaining a copy
5: of this software and associated documentation files (the "Software"), to deal
6: in the Software without restriction, including without limitation the rights
7: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8: copies of the Software, and to permit persons to whom the Software is
9: furnished to do so, subject to the following conditions:
10:
11: The above copyright notice and this permission notice shall be included in
12: all copies or substantial portions of the Software.
13:
14: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20: THE SOFTWARE.*/
21:
22: #region Usings
23: using System;
24: using System.Collections.Generic;
25: using System.Text;
26: using System.Xml;
27: #endregion
28:
29: namespace Utilities.FileFormats.OPMLHelper
30: {
31: /// <summary>
32: /// Outline class
33: /// </summary>
34: public class Outline
35: {
36: #region Constructors
37:
38: /// <summary>
39: /// Constructor
40: /// </summary>
41: public Outline()
42: {
43: Outlines = new List<Outline>();
44: }
45:
46: /// <summary>
47: /// Constructors
48: /// </summary>
49: /// <param name="Element">Element containing outline information</param>
50: public Outline(XmlElement Element)
51: {
52: if (Element.Name.Equals("outline", StringComparison.CurrentCultureIgnoreCase))
53: {
54: if (Element.Attributes["text"] != null)
55: {
56: Text = Element.Attributes["text"].Value;
57: }
58: else if (Element.Attributes["description"] != null)
59: {
60: Description = Element.Attributes["description"].Value;
61: }
62: else if (Element.Attributes["htmlUrl"] != null)
63: {
64: HTMLUrl = Element.Attributes["htmlUrl"].Value;
65: }
66: else if (Element.Attributes["type"] != null)
67: {
68: Type = Element.Attributes["type"].Value;
69: }
70: else if (Element.Attributes["language"] != null)
71: {
72: Language = Element.Attributes["language"].Value;
73: }
74: else if (Element.Attributes["title"] != null)
75: {
76: Title = Element.Attributes["title"].Value;
77: }
78: else if (Element.Attributes["version"] != null)
79: {
80: Version = Element.Attributes["version"].Value;
81: }
82: else if (Element.Attributes["xmlUrl"] != null)
83: {
84: XMLUrl = Element.Attributes["xmlUrl"].Value;
85: }
86: foreach (XmlNode Child in Element.ChildNodes)
87: {
88: try
89: {
90: if (Child.Name.Equals("outline", StringComparison.CurrentCultureIgnoreCase))
91: {
92: Outlines.Add(new Outline((XmlElement)Child));
93: }
94: }
95: catch { }
96: }
97: }
98: }
99:
100: #endregion
101:
102: #region Properties
103:
104: /// <summary>
105: /// Outline list
106: /// </summary>
107: public List<Outline> Outlines { get; set; }
108:
109: /// <summary>
110: /// Url of the XML file
111: /// </summary>
112: public string XMLUrl { get; set; }
113:
114: /// <summary>
115: /// Version number
116: /// </summary>
117: public string Version { get; set; }
118:
119: /// <summary>
120: /// Title of the item
121: /// </summary>
122: public string Title { get; set; }
123:
124: /// <summary>
125: /// Language used
126: /// </summary>
127: public string Language { get; set; }
128:
129: /// <summary>
130: /// Type
131: /// </summary>
132: public string Type { get; set; }
133:
134: /// <summary>
135: /// HTML Url
136: /// </summary>
137: public string HTMLUrl { get; set; }
138:
139: /// <summary>
140: /// Text
141: /// </summary>
142: public string Text { get; set; }
143:
144: /// <summary>
145: /// Description
146: /// </summary>
147: public string Description { get; set; }
148:
149: #endregion
150:
151: #region Overridden Functions
152:
153: public override string ToString()
154: {
155: StringBuilder OutlineString = new StringBuilder();
156: OutlineString.Append("<outline text=\"" + Text + "\"");
157: if (!string.IsNullOrEmpty(XMLUrl))
158: {
159: OutlineString.Append(" xmlUrl=\"" + XMLUrl + "\"");
160: }
161: if (!string.IsNullOrEmpty(Version))
162: {
163: OutlineString.Append(" version=\"" + Version + "\"");
164: }
165: if (!string.IsNullOrEmpty(Title))
166: {
167: OutlineString.Append(" title=\"" + Title + "\"");
168: }
169: if (!string.IsNullOrEmpty(Language))
170: {
171: OutlineString.Append(" language=\"" + Language + "\"");
172: }
173: if (!string.IsNullOrEmpty(Type))
174: {
175: OutlineString.Append(" type=\"" + Type + "\"");
176: }
177: if (!string.IsNullOrEmpty(HTMLUrl))
178: {
179: OutlineString.Append(" htmlUrl=\"" + HTMLUrl + "\"");
180: }
181: if (!string.IsNullOrEmpty(Text))
182: {
183: OutlineString.Append(" text=\"" + Text + "\"");
184: }
185: if (!string.IsNullOrEmpty(Description))
186: {
187: OutlineString.Append(" description=\"" + Description + "\"");
188: }
189: if (Outlines.Count > 0)
190: {
191: OutlineString.Append(">\r\n");
192: foreach (Outline Outline in Outlines)
193: {
194: OutlineString.Append(Outline.ToString());
195: }
196: OutlineString.Append("</outline>\r\n");
197: }
198: else
199: {
200: OutlineString.Append(" />\r\n");
201: }
202: return OutlineString.ToString();
203: }
204:
205: #endregion
206: }
207: }