1
/* Copyright (c) 2006 Google Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
15
#region Using directives
21
using System.Globalization;
25
//////////////////////////////////////////////////////////////////////
26
// <summary>Contains AtomLink, an object to represent the atom:link
28
//////////////////////////////////////////////////////////////////////
29
namespace Google.GData.Client
32
//////////////////////////////////////////////////////////////////////
33
/// <summary>AtomLink represents an atom:link element
34
/// atomLink = element atom:link {
35
/// atomCommonAttributes,
36
/// attribute href { atomUri },
37
/// attribute rel { atomNCName | atomUri }?,
38
/// attribute type { atomMediaType }?,
39
/// attribute hreflang { atomLanguageTag }?,
40
/// attribute title { text }?,
41
/// attribute length { text }?,
44
//////////////////////////////////////////////////////////////////////
45
public class AtomLink : AtomBase
47
/// <summary>property holder exposed over get/set</summary>
49
/// <summary>property holder exposed over get/set</summary>
51
/// <summary>property holder exposed over get/set</summary>
53
/// <summary>property holder exposed over get/set</summary>
54
private string hreflang;
55
/// <summary>property holder exposed over get/set</summary>
57
/// <summary>property holder exposed over get/set</summary>
61
/// <summary>HTML Link Type</summary>
62
public const string HTML_TYPE = "text/html";
64
/// <summary>ATOM Link Type</summary>
65
public const string ATOM_TYPE = "application/atom+xml";
67
//////////////////////////////////////////////////////////////////////
68
/// <summary>default empty constructor</summary>
69
//////////////////////////////////////////////////////////////////////
73
/////////////////////////////////////////////////////////////////////////////
76
//////////////////////////////////////////////////////////////////////
77
/// <summary>public AtomLink(string uri)</summary>
78
/// <param name="link">the uri for the link </param>
79
//////////////////////////////////////////////////////////////////////
80
public AtomLink(string link)
82
this.HRef = new AtomUri(link);
85
/// constructor used in atomfeed to create new links
87
/// <param name="type">the type of link to create</param>
88
/// <param name="rel">the rel value</param>
89
public AtomLink(string type, string rel)
95
//////////////////////////////////////////////////////////////////////
96
/// <summary>accessor method public Uri HRef</summary>
97
/// <returns> </returns>
98
//////////////////////////////////////////////////////////////////////
101
get {return this.href;}
102
set {this.Dirty = true; this.href = value;}
104
/////////////////////////////////////////////////////////////////////////////
106
//////////////////////////////////////////////////////////////////////
107
/// <summary>public string AbsoluteUri</summary>
108
//////////////////////////////////////////////////////////////////////
109
public string AbsoluteUri
113
if (this.HRef != null)
114
return GetAbsoluteUri(this.HRef.ToString());
118
/////////////////////////////////////////////////////////////////////////////
122
//////////////////////////////////////////////////////////////////////
123
/// <summary>accessor method public string Rel</summary>
124
/// <returns> </returns>
125
//////////////////////////////////////////////////////////////////////
128
get {return this.rel;}
129
set {this.Dirty = true; this.rel = value;}
131
/////////////////////////////////////////////////////////////////////////////
133
//////////////////////////////////////////////////////////////////////
134
/// <summary>accessor method public string Type</summary>
135
/// <returns> </returns>
136
//////////////////////////////////////////////////////////////////////
139
get {return this.type;}
140
set {this.Dirty = true; this.type = value;}
142
/////////////////////////////////////////////////////////////////////////////
144
//////////////////////////////////////////////////////////////////////
145
/// <summary>accessor method public string HrefLang</summary>
146
/// <returns> </returns>
147
//////////////////////////////////////////////////////////////////////
148
public string HRefLang
150
get {return this.hreflang;}
151
set {this.Dirty = true; this.hreflang = value;}
153
/////////////////////////////////////////////////////////////////////////////
156
//////////////////////////////////////////////////////////////////////
157
/// <summary>accessor method public int Lenght</summary>
158
/// <returns> </returns>
159
//////////////////////////////////////////////////////////////////////
162
get {return this.length;}
163
set {this.Dirty = true; this.length = value;}
165
/////////////////////////////////////////////////////////////////////////////
167
//////////////////////////////////////////////////////////////////////
168
/// <summary>accessor method public string Title</summary>
169
/// <returns> </returns>
170
//////////////////////////////////////////////////////////////////////
173
get {return this.title;}
174
set {this.Dirty = true; this.title = value;}
176
/////////////////////////////////////////////////////////////////////////////
179
#region Persistence overloads
180
//////////////////////////////////////////////////////////////////////
181
/// <summary>Returns the constant representing this XML element.</summary>
182
//////////////////////////////////////////////////////////////////////
183
public override string XmlName
185
get { return AtomParserNameTable.XmlLinkElement; }
187
/////////////////////////////////////////////////////////////////////////////
190
//////////////////////////////////////////////////////////////////////
191
/// <summary>overridden to save attributes for this(XmlWriter writer)</summary>
192
/// <param name="writer">the xmlwriter to save into </param>
193
//////////////////////////////////////////////////////////////////////
194
protected override void SaveXmlAttributes(XmlWriter writer)
196
WriteEncodedAttributeString(writer, AtomParserNameTable.XmlAttributeHRef, this.HRef);
197
WriteEncodedAttributeString(writer, AtomParserNameTable.XmlAttributeHRefLang, this.HRefLang);
198
WriteEncodedAttributeString(writer, AtomParserNameTable.XmlAttributeRel, this.Rel);
199
WriteEncodedAttributeString(writer, AtomParserNameTable.XmlAttributeType, this.Type);
203
WriteEncodedAttributeString(writer, AtomParserNameTable.XmlAttributeLength, this.Length.ToString(CultureInfo.InvariantCulture));
205
WriteEncodedAttributeString(writer, AtomParserNameTable.XmlTitleElement, this.Title);
206
base.SaveXmlAttributes(writer);
209
/////////////////////////////////////////////////////////////////////////////
212
//////////////////////////////////////////////////////////////////////
213
/// <summary>figures out if this object should be persisted</summary>
214
/// <returns> true, if it's worth saving</returns>
215
//////////////////////////////////////////////////////////////////////
216
public override bool ShouldBePersisted()
218
if (base.ShouldBePersisted() == true)
222
if (Utilities.IsPersistable(this.href))
226
if (Utilities.IsPersistable(this.hreflang))
230
if (Utilities.IsPersistable(this.rel))
234
if (Utilities.IsPersistable(this.type))
238
if (Utilities.IsPersistable(this.Length))
243
if (Utilities.IsPersistable(this.title))
249
/////////////////////////////////////////////////////////////////////////////
258
/////////////////////////////////////////////////////////////////////////////
260
} /////////////////////////////////////////////////////////////////////////////