1 // Copyright 2008, Google Inc. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are met: 5 // 6 // 1. Redistributions of source code must retain the above copyright notice, 7 // this list of conditions and the following disclaimer. 8 // 2. Redistributions in binary form must reproduce the above copyright notice, 9 // this list of conditions and the following disclaimer in the documentation 10 // and/or other materials provided with the distribution. 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be 12 // used to endorse or promote products derived from this software without 13 // specific prior written permission. 14 // 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26 // This file contains the declaration of Atom elements used in KML. 27 // See: http://atompub.org/rfc4287.html. 28 29 #ifndef KML_DOM_ATOM_H__ 30 #define KML_DOM_ATOM_H__ 31 32 #include "kml/dom/element.h" 33 34 namespace kmldom { 35 36 // <atom:author>, RFC 4287 4.2.1, and 3.2 (atomPersonConstruct) 37 class AtomAuthor : public BasicElement<Type_AtomAuthor> { 38 public: 39 virtual ~AtomAuthor(); 40 41 // <atom:name> get_name()42 const string& get_name() const { return name_; } has_name()43 bool has_name() const { return has_name_; } set_name(const string & value)44 void set_name(const string& value) { 45 name_ = value; 46 has_name_ = true; 47 } clear_name()48 void clear_name() { 49 name_.clear(); 50 has_name_ = false; 51 } 52 53 // <atom:uri>, RFC 3987 get_uri()54 const string& get_uri() const { return uri_; } has_uri()55 bool has_uri() const { return has_uri_; } set_uri(const string & value)56 void set_uri(const string& value) { 57 uri_ = value; 58 has_uri_ = true; 59 } clear_uri()60 void clear_uri() { 61 uri_.clear(); 62 has_uri_ = false; 63 } 64 65 // <atom:email>, RFC 2822 get_email()66 const string& get_email() const { return email_; } has_email()67 bool has_email() const { return has_email_; } set_email(const string & value)68 void set_email(const string& value) { 69 email_ = value; 70 has_email_ = true; 71 } clear_email()72 void clear_email() { 73 email_.clear(); 74 has_email_ = false; 75 } 76 77 private: 78 bool has_name_; 79 string name_; 80 bool has_uri_; 81 string uri_; 82 bool has_email_; 83 string email_; 84 friend class KmlFactory; 85 AtomAuthor(); 86 friend class KmlHandler; 87 virtual void AddElement(const ElementPtr& element); 88 friend class Serializer; 89 virtual void Serialize(Serializer& serializer) const; 90 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomAuthor); 91 }; 92 93 // Elements common to <atom:feed> and <atom:entry>. 94 class AtomCommon : public Element { 95 public: 96 // <atom:id> get_id()97 const string& get_id() const { return id_; } has_id()98 bool has_id() const { return has_id_; } set_id(const string & value)99 void set_id(const string& value) { 100 id_ = value; 101 has_id_ = true; 102 } clear_id()103 void clear_id() { 104 id_.clear(); 105 has_id_ = false; 106 } 107 108 // <atom:title> get_title()109 const string& get_title() const { return title_; } has_title()110 bool has_title() const { return has_title_; } set_title(const string & value)111 void set_title(const string& value) { 112 title_ = value; 113 has_title_ = true; 114 } clear_title()115 void clear_title() { 116 title_.clear(); 117 has_title_ = false; 118 } 119 120 // <atom:updated> get_updated()121 const string& get_updated() const { return updated_; } has_updated()122 bool has_updated() const { return has_updated_; } set_updated(const string & value)123 void set_updated(const string& value) { 124 updated_ = value; 125 has_updated_ = true; 126 } clear_updated()127 void clear_updated() { 128 updated_.clear(); 129 has_updated_ = false; 130 } 131 132 // <atom:category>... 133 void add_category(const AtomCategoryPtr& entry); get_category_array_size()134 size_t get_category_array_size() const { 135 return category_array_.size(); 136 } get_category_array_at(size_t index)137 const AtomCategoryPtr& get_category_array_at(size_t index) const { 138 return category_array_[index]; 139 } 140 141 // <atom:link>... 142 void add_link(const AtomLinkPtr& entry); get_link_array_size()143 size_t get_link_array_size() const { 144 return link_array_.size(); 145 } get_link_array_at(size_t index)146 const AtomLinkPtr& get_link_array_at(size_t index) const { 147 return link_array_[index]; 148 } 149 150 protected: 151 AtomCommon(); 152 void AddElement(const ElementPtr& element); 153 virtual void Serialize(Serializer& serializer) const; 154 155 private: 156 friend class KmlFactory; 157 friend class KmlHandler; 158 friend class Serializer; 159 bool has_id_; 160 string id_; 161 bool has_title_; 162 string title_; 163 bool has_updated_; 164 string updated_; 165 std::vector<AtomCategoryPtr> category_array_; 166 std::vector<AtomLinkPtr> link_array_; 167 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomCommon); 168 }; 169 170 // <atom:category scheme="..." term="..." label=..."/>, RFC 4287 4.2.2 171 // NOTE: This element is not part of the OGC KML 2.2 standard. 172 class AtomCategory : public BasicElement<Type_AtomCategory> { 173 public: 174 virtual ~AtomCategory(); 175 176 // term= get_term()177 const string& get_term() const { return term_; } has_term()178 bool has_term() const { return has_term_; } set_term(const string & value)179 void set_term(const string& value) { 180 term_ = value; 181 has_term_ = true; 182 } clear_term()183 void clear_term() { 184 term_.clear(); 185 has_term_ = false; 186 } 187 188 // scheme= get_scheme()189 const string& get_scheme() const { return scheme_; } has_scheme()190 bool has_scheme() const { return has_scheme_; } set_scheme(const string & value)191 void set_scheme(const string& value) { 192 scheme_ = value; 193 has_scheme_ = true; 194 } clear_scheme()195 void clear_scheme() { 196 scheme_.clear(); 197 has_scheme_ = false; 198 } 199 200 // label= get_label()201 const string& get_label() const { return label_; } has_label()202 bool has_label() const { return has_label_; } set_label(const string & value)203 void set_label(const string& value) { 204 label_ = value; 205 has_label_ = true; 206 } clear_label()207 void clear_label() { 208 label_.clear(); 209 has_label_ = false; 210 } 211 212 private: 213 friend class KmlFactory; 214 AtomCategory(); 215 friend class KmlHandler; 216 virtual void AddElement(const ElementPtr& element); 217 virtual void ParseAttributes(kmlbase::Attributes* attributes); 218 friend class Serializer; 219 virtual void Serialize(Serializer& serializer) const; 220 virtual void SerializeAttributes(kmlbase::Attributes* attributes) const; 221 bool has_term_; 222 string term_; 223 bool has_scheme_; 224 string scheme_; 225 bool has_label_; 226 string label_; 227 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomCategory); 228 }; 229 230 // <atom:content src="..." type="...">, RFC 4287 4.1.3 231 // NOTE: This element is not part of the OGC KML 2.2 standard. 232 class AtomContent : public BasicElement<Type_AtomContent> { 233 public: 234 virtual ~AtomContent(); 235 236 // src= get_src()237 const string& get_src() const { return src_; } has_src()238 bool has_src() const { return has_src_; } set_src(const string & value)239 void set_src(const string& value) { 240 src_ = value; 241 has_src_ = true; 242 } clear_src()243 void clear_src() { 244 src_.clear(); 245 has_src_ = false; 246 } 247 248 // type= get_type()249 const string& get_type() const { return type_; } has_type()250 bool has_type() const { return has_type_; } set_type(const string & value)251 void set_type(const string& value) { 252 type_ = value; 253 has_type_ = true; 254 } clear_type()255 void clear_type() { 256 type_.clear(); 257 has_type_ = false; 258 } 259 260 private: 261 friend class KmlFactory; 262 AtomContent(); 263 friend class KmlHandler; 264 void ParseAttributes(kmlbase::Attributes* attributes); 265 void SerializeAttributes(kmlbase::Attributes* attributes) const; 266 friend class Serializer; 267 virtual void Serialize(Serializer& serializer) const; 268 bool has_src_; 269 string src_; 270 bool has_type_; 271 string type_; 272 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomContent); 273 }; 274 275 // <atom:entry>, RFC 4287 4.1.2 276 // NOTE: This element is not part of the OGC KML 2.2 standard. 277 class AtomEntry : public AtomCommon { 278 public: 279 virtual ~AtomEntry(); Type()280 virtual KmlDomType Type() const { return Type_AtomEntry; } IsA(KmlDomType type)281 virtual bool IsA(KmlDomType type) const { 282 return type == Type_AtomEntry; 283 } 284 // This static method makes the class useable with ElementCast. ElementType()285 static KmlDomType ElementType() { 286 return static_cast<KmlDomType>(Type_AtomEntry); 287 } 288 289 // <atom:summary> get_summary()290 const string& get_summary() const { return summary_; } has_summary()291 bool has_summary() const { return has_summary_; } set_summary(const string & value)292 void set_summary(const string& value) { 293 summary_ = value; 294 has_summary_ = true; 295 } clear_summary()296 void clear_summary() { 297 summary_.clear(); 298 has_summary_ = false; 299 } 300 301 // <atom:content> get_content()302 const AtomContentPtr& get_content() const { return content_; } has_content()303 bool has_content() const { return content_ != NULL; } set_content(const AtomContentPtr & content)304 void set_content(const AtomContentPtr& content) { 305 SetComplexChild(content, &content_); 306 } clear_content()307 void clear_content() { 308 set_content(NULL); 309 } 310 311 private: 312 friend class KmlFactory; 313 AtomEntry(); 314 friend class KmlHandler; 315 virtual void AddElement(const ElementPtr& element); 316 friend class Serializer; 317 virtual void Serialize(Serializer& serializer) const; 318 bool has_summary_; 319 string summary_; 320 AtomContentPtr content_; 321 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomEntry); 322 }; 323 324 // <atom:feed>, RFC 4287 4.1.1 325 // NOTE: This element is not part of the OGC KML 2.2 standard. 326 class AtomFeed : public AtomCommon { 327 public: 328 virtual ~AtomFeed(); Type()329 virtual KmlDomType Type() const { return Type_AtomFeed; } IsA(KmlDomType type)330 virtual bool IsA(KmlDomType type) const { 331 return type == Type_AtomFeed; 332 } 333 // This static method makes the class useable with ElementCast. ElementType()334 static KmlDomType ElementType() { 335 return static_cast<KmlDomType>(Type_AtomFeed); 336 } 337 338 // <atom:entry>... 339 void add_entry(const AtomEntryPtr& entry); get_entry_array_size()340 size_t get_entry_array_size() const { 341 return entry_array_.size(); 342 } get_entry_array_at(size_t index)343 const AtomEntryPtr& get_entry_array_at(size_t index) const { 344 return entry_array_[index]; 345 } 346 347 private: 348 friend class KmlFactory; 349 AtomFeed(); 350 friend class Serializer; 351 virtual void Serialize(Serializer& serializer) const; 352 friend class KmlHandler; 353 virtual void AddElement(const ElementPtr& element); 354 std::vector<AtomEntryPtr> entry_array_; 355 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomFeed); 356 }; 357 358 // <atom:link>, RFC 4287 4.2.7 359 class AtomLink : public BasicElement<Type_AtomLink> { 360 public: 361 virtual ~AtomLink(); 362 363 // href=, RFC 4287 4.2.7.1, RFC 3987 get_href()364 const string& get_href() const { return href_; } has_href()365 bool has_href() const { return has_href_; } set_href(const string & value)366 void set_href(const string& value) { 367 href_ = value; 368 has_href_ = true; 369 } clear_href()370 void clear_href() { 371 href_.clear(); 372 has_href_ = false; 373 } 374 375 // rel=, RFC 4287 4.2.7.2, RFC 3987 get_rel()376 const string& get_rel() const { return rel_; } has_rel()377 bool has_rel() const { return has_rel_; } set_rel(const string & value)378 void set_rel(const string& value) { 379 rel_ = value; 380 has_rel_ = true; 381 } clear_rel()382 void clear_rel() { 383 rel_.clear(); 384 has_rel_ = false; 385 } 386 387 // type=, RFC 4287 4.2.7.3, MIME get_type()388 const string& get_type() const { return type_; } has_type()389 bool has_type() const { return has_type_; } set_type(const string & value)390 void set_type(const string& value) { 391 type_ = value; 392 has_type_ = true; 393 } clear_type()394 void clear_type() { 395 type_.clear(); 396 has_type_ = false; 397 } 398 399 // hreflang=, RFC 4287 4.2.7.4, RFC 3066 get_hreflang()400 const string& get_hreflang() const { return hreflang_; } has_hreflang()401 bool has_hreflang() const { return has_hreflang_; } set_hreflang(const string & value)402 void set_hreflang(const string& value) { 403 hreflang_ = value; 404 has_hreflang_ = true; 405 } clear_hreflang()406 void clear_hreflang() { 407 hreflang_.clear(); 408 has_hreflang_ = false; 409 } 410 411 // title=, RFC 4287 4.2.7.5 get_title()412 const string& get_title() const { return title_; } has_title()413 bool has_title() const { return has_title_; } set_title(const string & value)414 void set_title(const string& value) { 415 title_ = value; 416 has_title_ = true; 417 } clear_title()418 void clear_title() { 419 title_.clear(); 420 has_title_ = false; 421 } 422 423 // length=, RFC 4287 4.2.7.6 get_length()424 int get_length() const { return length_; } has_length()425 bool has_length() const { return has_length_; } set_length(const int value)426 void set_length(const int value) { 427 length_ = value; 428 has_length_ = true; 429 } clear_length()430 void clear_length() { 431 length_ = 0; 432 has_length_ = false; 433 } 434 435 private: 436 bool has_href_; 437 string href_; 438 bool has_rel_; 439 string rel_; 440 bool has_type_; 441 string type_; 442 bool has_hreflang_; 443 string hreflang_; 444 bool has_title_; 445 string title_; 446 bool has_length_; 447 int length_; 448 friend class KmlFactory; 449 AtomLink(); 450 friend class KmlHandler; 451 virtual void AddElement(const ElementPtr& element); 452 void ParseAttributes(kmlbase::Attributes* attributes); 453 void SerializeAttributes(kmlbase::Attributes* attributes) const; 454 friend class Serializer; 455 virtual void Serialize(Serializer& serializer) const; 456 LIBKML_DISALLOW_EVIL_CONSTRUCTORS(AtomLink); 457 }; 458 459 } // end namespace kmldom 460 461 #endif // KML_DOM_ATOM_H__ 462