PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/pkp/classes/webservice/XmlWebService.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 84 lines | 37 code | 14 blank | 33 comment | 8 complexity | 7a525379e7ee1bca6d846cd81075f0e7 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/citation/XmlWebService.inc.php
  4. *
  5. * Copyright (c) 2000-2012 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class XmlWebService
  9. * @ingroup webservice
  10. *
  11. * @brief A web service that returns XML data.
  12. */
  13. // $Id$
  14. import('webservice.WebService');
  15. class XmlWebService extends WebService {
  16. /** @var integer */
  17. var $_returnType;
  18. /**
  19. * Constructor
  20. */
  21. function XmlWebService() {
  22. if (checkPhpVersion('5.0.0') && extension_loaded('dom')) {
  23. $this->_returnType = XSL_TRANSFORMER_DOCTYPE_DOM;
  24. } else {
  25. $this->_returnType = XSL_TRANSFORMER_DOCTYPE_STRING;
  26. }
  27. }
  28. /**
  29. * Get the return type
  30. * @return integer
  31. */
  32. function getReturnType() {
  33. return $this->_returnType;
  34. }
  35. /**
  36. * Set the return type
  37. * @param $returnType integer
  38. */
  39. function setReturnType($returnType) {
  40. if ($returnType == XSL_TRANSFORMER_DOCTYPE_DOM) {
  41. assert(checkPhpVersion('5.0.0') && extension_loaded('dom'));
  42. }
  43. $this->_returnType = $returnType;
  44. }
  45. /**
  46. * @see WebService::call()
  47. * @param $webServiceRequest WebServiceRequest
  48. * @return DOMDocument|string the result of the web service or null in case of an error.
  49. */
  50. function &call(&$webServiceRequest) {
  51. // Call the web service
  52. $xmlResult = parent::call($webServiceRequest);
  53. // Catch web service errors
  54. if (is_null($xmlResult)) return $xmlResult;
  55. switch ($this->_returnType) {
  56. case XSL_TRANSFORMER_DOCTYPE_DOM:
  57. // Create DOM document
  58. $resultDOM = new DOMDocument('1.0', Config::getVar('i18n', 'client_charset'));
  59. // Try to handle non-well-formed responses
  60. $resultDOM->recover = true;
  61. $resultDOM->loadXML($xmlResult);
  62. return $resultDOM;
  63. case XSL_TRANSFORMER_DOCTYPE_STRING:
  64. return $xmlResult;
  65. default:
  66. assert(false);
  67. }
  68. }
  69. }
  70. ?>