Entry.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Gdata
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata
  24. */
  25. require_once 'Zend/Gdata.php';
  26. /**
  27. * @see Zend_Gdata_App_MediaEntry
  28. */
  29. require_once 'Zend/Gdata/App/MediaEntry.php';
  30. /**
  31. * Represents the Gdata flavor of an Atom entry
  32. *
  33. * @category Zend
  34. * @package Zend_Gdata
  35. * @subpackage Gdata
  36. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Gdata_Entry extends Zend_Gdata_App_MediaEntry
  40. {
  41. protected $_entryClassName = 'Zend_Gdata_Entry';
  42. public function __construct($element = null)
  43. {
  44. $this->registerAllNamespaces(Zend_Gdata::$namespaces);
  45. parent::__construct($element);
  46. }
  47. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  48. {
  49. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  50. // ETags are special. We only support them in protocol >= 2.X.
  51. // This will be duplicated by the HTTP ETag header.
  52. if ($majorVersion >= 2) {
  53. if ($this->_etag != null) {
  54. $element->setAttributeNS($this->lookupNamespace('gd'),
  55. 'gd:etag',
  56. $this->_etag);
  57. }
  58. }
  59. return $element;
  60. }
  61. protected function takeChildFromDOM($child)
  62. {
  63. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  64. switch ($absoluteNodeName) {
  65. case $this->lookupNamespace('atom') . ':' . 'content':
  66. $content = new Zend_Gdata_App_Extension_Content();
  67. $content->transferFromDOM($child);
  68. $this->_content = $content;
  69. break;
  70. case $this->lookupNamespace('atom') . ':' . 'published':
  71. $published = new Zend_Gdata_App_Extension_Published();
  72. $published->transferFromDOM($child);
  73. $this->_published = $published;
  74. break;
  75. case $this->lookupNamespace('atom') . ':' . 'source':
  76. $source = new Zend_Gdata_App_Extension_Source();
  77. $source->transferFromDOM($child);
  78. $this->_source = $source;
  79. break;
  80. case $this->lookupNamespace('atom') . ':' . 'summary':
  81. $summary = new Zend_Gdata_App_Extension_Summary();
  82. $summary->transferFromDOM($child);
  83. $this->_summary = $summary;
  84. break;
  85. case $this->lookupNamespace('app') . ':' . 'control':
  86. $control = new Zend_Gdata_App_Extension_Control();
  87. $control->transferFromDOM($child);
  88. $this->_control = $control;
  89. break;
  90. default:
  91. parent::takeChildFromDOM($child);
  92. break;
  93. }
  94. }
  95. /**
  96. * Given a DOMNode representing an attribute, tries to map the data into
  97. * instance members. If no mapping is defined, the name and value are
  98. * stored in an array.
  99. *
  100. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  101. */
  102. protected function takeAttributeFromDOM($attribute)
  103. {
  104. switch ($attribute->localName) {
  105. case 'etag':
  106. // ETags are special, since they can be conveyed by either the
  107. // HTTP ETag header or as an XML attribute.
  108. $etag = $attribute->nodeValue;
  109. if ($this->_etag === null) {
  110. $this->_etag = $etag;
  111. }
  112. elseif ($this->_etag != $etag) {
  113. require_once('Zend/Gdata/App/IOException.php');
  114. throw new Zend_Gdata_App_IOException("ETag mismatch");
  115. }
  116. break;
  117. default:
  118. parent::takeAttributeFromDOM($attribute);
  119. break;
  120. }
  121. }
  122. }