2
0

Entry.php 4.3 KB

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