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.FOAF
30: { 31: /// <summary>
32: /// Container of an individual's information
33: /// </summary>
34: public class Person
35: { 36: #region Constructors
37: /// <summary>
38: /// Constructor
39: /// </summary>
40: public Person()
41: { 42: }
43:
44: /// <summary>
45: /// Constructor
46: /// </summary>
47: /// <param name="Element">Element containing the proper information</param>
48: public Person(XmlElement Element)
49: { 50: if (Element.Name.Equals("foaf:Person", StringComparison.CurrentCultureIgnoreCase)) 51: { 52: foreach (XmlNode Child in Element.ChildNodes)
53: { 54: if (Child.Name.Equals("foaf:name", StringComparison.CurrentCultureIgnoreCase)) 55: { 56: Name = Child.InnerText;
57: }
58: else if (Child.Name.Equals("foaf:title", StringComparison.CurrentCultureIgnoreCase)) 59: { 60: Title = Child.InnerText;
61: }
62: else if (Child.Name.Equals("foaf:givenname", StringComparison.CurrentCultureIgnoreCase)) 63: { 64: GivenName = Child.InnerText;
65: }
66: else if (Child.Name.Equals("foaf:family_name", StringComparison.CurrentCultureIgnoreCase)) 67: { 68: FamilyName = Child.InnerText;
69: }
70: else if (Child.Name.Equals("foaf:mbox_sha1sum", StringComparison.CurrentCultureIgnoreCase) || Child.Name.Equals("foaf:mbox", StringComparison.CurrentCultureIgnoreCase)) 71: { 72: Email.Add(Child.InnerText);
73: }
74: else if (Child.Name.Equals("foaf:homepage", StringComparison.CurrentCultureIgnoreCase)) 75: { 76: if (Child.Attributes["rdf:resource"] != null)
77: { 78: Homepage.Add(Child.Attributes["rdf:resource"].Value);
79: }
80: }
81: else if (Child.Name.Equals("foaf:depiction", StringComparison.CurrentCultureIgnoreCase)) 82: { 83: if (Child.Attributes["rdf:resource"] != null)
84: { 85: Depiction.Add(Child.Attributes["rdf:resource"].Value);
86: }
87: }
88: else if (Child.Name.Equals("foaf:phone", StringComparison.CurrentCultureIgnoreCase)) 89: { 90: if (Child.Attributes["rdf:resource"] != null)
91: { 92: Phone.Add(Child.Attributes["rdf:resource"].Value);
93: }
94: }
95: else if (Child.Name.Equals("foaf:workplacehomepage", StringComparison.CurrentCultureIgnoreCase)) 96: { 97: if (Child.Attributes["rdf:resource"] != null)
98: { 99: WorkplaceHomepage = Child.Attributes["rdf:resource"].Value;
100: }
101: }
102: else if (Child.Name.Equals("foaf:workinfohomepage", StringComparison.CurrentCultureIgnoreCase)) 103: { 104: if (Child.Attributes["rdf:resource"] != null)
105: { 106: WorkInfoHomepage = Child.Attributes["rdf:resource"].Value;
107: }
108: }
109: else if (Child.Name.Equals("foaf:schoolhomepage", StringComparison.CurrentCultureIgnoreCase)) 110: { 111: if (Child.Attributes["rdf:resource"] != null)
112: { 113: SchoolHomepage = Child.Attributes["rdf:resource"].Value;
114: }
115: }
116: else if (Child.Name.Equals("foaf:knows", StringComparison.CurrentCultureIgnoreCase)) 117: { 118: foreach (XmlNode Child2 in Child.ChildNodes)
119: { 120: PeopleKnown.Add(new Person((XmlElement)Child2));
121: }
122: }
123: else if (Child.Name.Equals("rdfs:seeAlso", StringComparison.CurrentCultureIgnoreCase)) 124: { 125: if (Child.Attributes["rdf:resource"] != null)
126: { 127: SeeAlso = Child.Attributes["rdf:resource"].Value;
128: }
129: }
130: }
131: }
132: }
133: #endregion
134:
135: #region Public Properties
136: private string _SeeAlso = "";
137: private string _Name = "";
138: private string _Title = "";
139: private string _GivenName = "";
140: private string _FamilyName = "";
141: private string _NickName = "";
142: private List<string> _Email = new List<string>();
143: private List<string> _Homepage = new List<string>();
144: private List<string> _Depiction = new List<string>();
145: private List<string> _Phone = new List<string>();
146: private string _WorkplaceHomepage = "";
147: private string _WorkInfoHomepage = "";
148: private string _SchoolHomepage = "";
149: private List<Person> _PeopleKnown = new List<Person>();
150:
151: /// <summary>
152: /// Points to a person's FOAF file
153: /// </summary>
154: public string SeeAlso
155: { 156: get { return _SeeAlso; } 157: set { _SeeAlso = value; } 158: }
159:
160: /// <summary>
161: /// Name of the individual
162: /// </summary>
163: public string Name
164: { 165: get { return _Name; } 166: set { _Name = value; } 167: }
168:
169: /// <summary>
170: /// Title (such as Mr, Ms., etc.)
171: /// </summary>
172: public string Title
173: { 174: get { return _Title; } 175: set { _Title = value; } 176: }
177:
178: /// <summary>
179: /// Their given name
180: /// </summary>
181: public string GivenName
182: { 183: get { return _GivenName; } 184: set { _GivenName = value; } 185: }
186:
187: /// <summary>
188: /// Last name/Family name
189: /// </summary>
190: public string FamilyName
191: { 192: get { return _FamilyName; } 193: set { _FamilyName = value; } 194: }
195:
196: /// <summary>
197: /// Any sort of nick name
198: /// </summary>
199: public string NickName
200: { 201: get { return _NickName; } 202: set { _NickName = value; } 203: }
204:
205: /// <summary>
206: /// Their home pages
207: /// </summary>
208: public List<string> Homepage
209: { 210: get { return _Homepage; } 211: set { _Homepage = value; } 212: }
213:
214: /// <summary>
215: /// Image of the person
216: /// </summary>
217: public List<string> Depiction
218: { 219: get { return _Depiction; } 220: set { _Depiction = value; } 221: }
222:
223: /// <summary>
224: /// Their phone number
225: /// </summary>
226: public List<string> Phone
227: { 228: get { return _Phone; } 229: set { _Phone = value; } 230: }
231:
232: /// <summary>
233: /// Workplace home page
234: /// </summary>
235: public string WorkplaceHomepage
236: { 237: get { return _WorkplaceHomepage; } 238: set { _WorkplaceHomepage = value; } 239: }
240:
241: /// <summary>
242: /// Information about what the person does (link to it)
243: /// </summary>
244: public string WorkInfoHomepage
245: { 246: get { return _WorkInfoHomepage; } 247: set { _WorkInfoHomepage = value; } 248: }
249:
250: /// <summary>
251: /// Link to the school they went/currently going to
252: /// </summary>
253: public string SchoolHomepage
254: { 255: get { return _SchoolHomepage; } 256: set { _SchoolHomepage = value; } 257: }
258:
259: /// <summary>
260: /// Email addresses associated with the person (may be SHA1 hashes)
261: /// </summary>
262: public List<string> Email
263: { 264: get { return _Email; } 265: set { _Email = value; } 266: }
267:
268: /// <summary>
269: /// People that this person knows
270: /// </summary>
271: public List<Person> PeopleKnown
272: { 273: get { return _PeopleKnown; } 274: set { _PeopleKnown = value; } 275: }
276: #endregion
277:
278: #region Public Overridden Functions
279: /// <summary>
280: /// Outputs the person's information
281: /// </summary>
282: /// <returns>An rdf/xml formatted string of the person's info</returns>
283: public override string ToString()
284: { 285: StringBuilder Builder = new StringBuilder();
286: if(!string.IsNullOrEmpty(Name))
287: Builder.Append("<foaf:name>" + Name + "</foaf:name>"); 288: if(!string.IsNullOrEmpty(Title))
289: Builder.Append("<foaf:title>" + Title + "</foaf:title>"); 290: if(!string.IsNullOrEmpty(GivenName))
291: Builder.Append("<foaf:givenname>" + GivenName + "</foaf:givenname>"); 292: if(!string.IsNullOrEmpty(FamilyName))
293: Builder.Append("<foaf:family_name>" + FamilyName + "</foaf:family_name>"); 294: if(!string.IsNullOrEmpty(NickName))
295: Builder.Append("<foaf:nick>" + NickName + "</foaf:nickname>"); 296: foreach (string CurrentEmail in Email)
297: { 298: if (!string.IsNullOrEmpty(CurrentEmail))
299: { 300: if (CurrentEmail.Contains("@")) 301: { 302: Builder.Append("<foaf:mbox>" + CurrentEmail + "</foaf:mbox>"); 303: }
304: else
305: { 306: Builder.Append("<foaf:mbox_sha1sum>" + CurrentEmail + "</foaf:mbox_sha1sum>"); 307: }
308: }
309: }
310: foreach (string CurrentHomePage in Homepage)
311: { 312: if(!string.IsNullOrEmpty(CurrentHomePage))
313: Builder.Append("<foaf:homepage rdf:resource=\"" + CurrentHomePage + "\" />"); 314: }
315: foreach (string CurrentDepiction in Depiction)
316: { 317: if(!string.IsNullOrEmpty(CurrentDepiction))
318: Builder.Append("<foaf:depiction rdf:resource=\"" + CurrentDepiction + "\" />"); 319: }
320: foreach (string CurrentPhone in Phone)
321: { 322: if(!string.IsNullOrEmpty(CurrentPhone))
323: Builder.Append("<foaf:phone rdf:resource=\"" + CurrentPhone + "\" />"); 324: }
325: if(!string.IsNullOrEmpty(WorkplaceHomepage))
326: Builder.Append("<foaf:workplaceHomepage rdf:resource=\"" + WorkplaceHomepage + "\" />"); 327: if(!string.IsNullOrEmpty(WorkInfoHomepage))
328: Builder.Append("<foaf:workInfoHomepage rdf:resource=\"" + WorkInfoHomepage + "\" />"); 329: if(!string.IsNullOrEmpty(SchoolHomepage))
330: Builder.Append("<foaf:schoolHomepage rdf:resource=\"" + SchoolHomepage + "\" />"); 331: foreach (Person CurrentPerson in PeopleKnown)
332: { 333: if (CurrentPerson != null)
334: { 335: Builder.Append("<foaf:knows><foaf:Person>"); 336: Builder.Append(CurrentPerson.ToString());
337: Builder.Append("</foaf:Person></foaf:knows>"); 338: }
339: }
340: if(!string.IsNullOrEmpty(SeeAlso))
341: Builder.Append("<rdfs:seeAlso rdf:resource=\"" + SeeAlso + "\"/>"); 342: return Builder.ToString();
343: }
344: #endregion
345: }
346: }