PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/codes-php/phpjakarta/WindowsAzure/Common/Internal/Atom/Content.php

http://bukuphpjs.codeplex.com
PHP | 181 lines | 68 code | 19 blank | 94 comment | 1 complexity | 570e8b7109e0b96bda8913031c209536 MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1
  1. <?php
  2. /**
  3. * LICENSE: 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
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package WindowsAzure\Common\Internal\Atom
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/WindowsAzure/azure-sdk-for-php
  22. */
  23. namespace WindowsAzure\Common\Internal\Atom;
  24. use WindowsAzure\Common\Internal\Resources;
  25. use WindowsAzure\Common\Internal\Utilities;
  26. use WindowsAzure\Common\Internal\Validate;
  27. /**
  28. * The content class of ATOM standard.
  29. *
  30. * @category Microsoft
  31. * @package WindowsAzure\Common\Internal\Atom
  32. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  33. * @copyright 2012 Microsoft Corporation
  34. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  35. * @version Release: @package_version@
  36. * @link https://github.com/WindowsAzure/azure-sdk-for-php
  37. */
  38. class Content extends AtomBase
  39. {
  40. /**
  41. * The text of the content.
  42. *
  43. * @var string
  44. */
  45. protected $text;
  46. /**
  47. * The type of the content.
  48. *
  49. * @var string
  50. */
  51. protected $type;
  52. /**
  53. * Creates a Content instance with specified text.
  54. *
  55. * @param string $text The text of the content.
  56. *
  57. * @return none
  58. */
  59. public function __construct($text = null)
  60. {
  61. $this->text = $text;
  62. }
  63. /**
  64. * Creates an ATOM CONTENT instance with specified xml string.
  65. *
  66. * @param string $xmlString an XML based string of ATOM CONTENT.
  67. *
  68. * @return none
  69. */
  70. public function parseXml($xmlString)
  71. {
  72. Validate::notNull($xmlString, 'xmlString');
  73. Validate::isString($xmlString, 'xmlString');
  74. $contentXml = simplexml_load_string($xmlString);
  75. Validate::notNull($contentXml, 'contentXml');
  76. $attributes = $contentXml->attributes();
  77. if (!empty($attributes['type'])) {
  78. $this->content = (string)$attributes['type'];
  79. }
  80. $text = '';
  81. foreach ($contentXml->children() as $child) {
  82. $text .= $child->asXML();
  83. }
  84. $this->text = $text;
  85. }
  86. /**
  87. * Gets the text of the content.
  88. *
  89. * @return string
  90. */
  91. public function getText()
  92. {
  93. return $this->text;
  94. }
  95. /**
  96. * Sets the text of the content.
  97. *
  98. * @param string $text The text of the content.
  99. *
  100. * @return none
  101. */
  102. public function setText($text)
  103. {
  104. $this->text = $text;
  105. }
  106. /**
  107. * Gets the type of the content.
  108. *
  109. * @return string
  110. */
  111. public function getType()
  112. {
  113. return $this->type;
  114. }
  115. /**
  116. * Sets the type of the content.
  117. *
  118. * @param string $type The type of the content.
  119. *
  120. * @return none
  121. */
  122. public function setType($type)
  123. {
  124. $this->type = $type;
  125. }
  126. /**
  127. * Writes an XML representing the content.
  128. *
  129. * @param \XMLWriter $xmlWriter The XML writer.
  130. *
  131. * @return none
  132. */
  133. public function writeXml($xmlWriter)
  134. {
  135. Validate::notNull($xmlWriter, 'xmlWriter');
  136. $xmlWriter->startElementNS(
  137. 'atom',
  138. 'content',
  139. Resources::ATOM_NAMESPACE
  140. );
  141. $this->writeOptionalAttribute(
  142. $xmlWriter,
  143. 'type',
  144. $this->type
  145. );
  146. $this->writeInnerXml($xmlWriter);
  147. $xmlWriter->endElement();
  148. }
  149. /**
  150. * Writes an inner XML representing the content.
  151. *
  152. * @param \XMLWriter $xmlWriter The XML writer.
  153. *
  154. * @return none
  155. */
  156. public function writeInnerXml($xmlWriter)
  157. {
  158. Validate::notNull($xmlWriter, 'xmlWriter');
  159. $xmlWriter->writeRaw($this->text);
  160. }
  161. }
  162. ?>