PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/pkp/classes/metadata/CrosswalkFilter.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 93 lines | 28 code | 11 blank | 54 comment | 4 complexity | 7720108a54f5d7ad61de14869f14ac05 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @file classes/metadata/CrosswalkFilter.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 CrosswalkFilter
  9. * @ingroup metadata
  10. * @see MetadataDescription
  11. *
  12. * @brief Class that provides methods to convert one type of
  13. * meta-data description into another. This is an abstract template
  14. * class that should be sub-classed by specific cross-walk
  15. * implementations.
  16. */
  17. // $Id$
  18. import('filter.Filter');
  19. class CrosswalkFilter extends Filter {
  20. /** @var string */
  21. var $_fromSchema;
  22. /** @var string */
  23. var $_toSchema;
  24. /**
  25. * Constructor
  26. * @param $fromSchema string
  27. * @param $toSchema string
  28. */
  29. function CrosswalkFilter($fromSchema, $toSchema) {
  30. assert(class_exists($fromSchema) && class_exists($toSchema));
  31. $this->_fromSchema = $fromSchema;
  32. $this->_toSchema = $toSchema;
  33. }
  34. //
  35. // Getters and setters
  36. //
  37. /**
  38. * Get the source meta-data schema class name
  39. * @return string
  40. */
  41. function getFromSchema() {
  42. return $this->_fromSchema;
  43. }
  44. /**
  45. * Get the target meta-data schema class name
  46. * @return MetadataSchema
  47. */
  48. function getToSchema() {
  49. return $this->_toSchema;
  50. }
  51. //
  52. // Implement template methods from Filter
  53. //
  54. /**
  55. * @see Filter::supports()
  56. * @param $input mixed
  57. * @param $output mixed
  58. */
  59. function supports(&$input, &$output) {
  60. // Validate input
  61. if (!$this->_complies($input, $this->getFromSchema())) return false;
  62. // Validate output
  63. if (is_null($output)) return true;
  64. return $this->_complies($output, $this->getToSchema());
  65. }
  66. //
  67. // Private helper methods
  68. //
  69. /**
  70. * Checks whether a given description complies
  71. * with a given meta-data schema class name.
  72. * @param $metadataDescription MetadataDescription
  73. * @param $schemaClassName string
  74. * @return boolean
  75. */
  76. function _complies(&$metadataDescription, $schemaClassName) {
  77. if (!is_a($metadataDescription, 'MetadataDescription')) return false;
  78. $descriptionSchema =& $metadataDescription->getMetadataSchema();
  79. return (is_a($descriptionSchema, $schemaClassName));
  80. }
  81. }
  82. ?>