Source for file XMLFileDataPartImporter.class.php

Documentation is available at XMLFileDataPartImporter.class.php

  1. <?php
  2. /**
  3. * @since 10/10/05
  4. * @package polyphony.importer
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: XMLFileDataPartImporter.class.php,v 1.16 2007/09/19 14:04:46 adamfranco Exp $
  10. */
  11. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLImporter.class.php");
  12.  
  13. /**
  14. * imports the filedata of a file, how interesting
  15. *
  16. * @since 10/10/05
  17. * @package polyphony.importer
  18. *
  19. * @copyright Copyright &copy; 2005, Middlebury College
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  21. *
  22. * @version $Id: XMLFileDataPartImporter.class.php,v 1.16 2007/09/19 14:04:46 adamfranco Exp $
  23. */
  24. class XMLFileDataPartImporter extends XMLImporter {
  25. /**
  26. * Constructor
  27. *
  28. *
  29. * @return object XMLFileDataPartImporter
  30. * @access public
  31. * @since 10/10/05
  32. */
  33. function XMLFileDataPartImporter ($existingArray) {
  34. parent::XMLImporter($existingArray);
  35. }
  36.  
  37. /**
  38. * Sets up importer's self-knowledge
  39. *
  40. * @access public
  41. * @since 10/10/05
  42. */
  43. function setupSelf () {
  44. $this->_childImporterList = NULL;
  45. $this->_childElementList = NULL;
  46. $this->_info = array();
  47. }
  48. /**
  49. * Filters nodes of incorrect type
  50. *
  51. * @param object DOMIT_Node
  52. * @return boolean
  53. * @static
  54. * @access public
  55. * @since 10/10/05
  56. */
  57. function isImportable ($element) {
  58. if ($element->nodeName == "filedatapart")
  59. return true;
  60. else
  61. return false;
  62. }
  63.  
  64. /**
  65. * Checks if the user is able to import underneath this level
  66. *
  67. * @param string $authZQString qualifier for authz checking
  68. * @access public
  69. * @since 11/3/05
  70. */
  71. function canImportBelow($authZQString) {
  72. return true;
  73. }
  74.  
  75. /**
  76. * Imports the current node's information
  77. *
  78. * @access public
  79. * @since 10/10/05
  80. */
  81. function importNode () {
  82. $idManager = Services::getService("Id");
  83.  
  84. $this->getNodeInfo();
  85.  
  86. if (in_array($this->_info['parentId']->getIdString(),
  87. $this->_existingArray) || ($this->_type == "update")) {
  88. $this->_myId =$this->_info['fileDataId'];
  89. $this->_object =$this->_parent->getPart($this->_myId);
  90. $this->_object2 =
  91. $this->_parent->getPart($this->_info['filenameId']);
  92. $this->update();
  93. } else {
  94. $this->_object =$this->_parent->createPart(
  95. $this->_info['partStructureId'],
  96. file_get_contents($this->_info['value']));
  97. $this->_myId =$this->_object->getId();
  98. $this->_object2 =$this->_parent->createPart(
  99. $this->_info['namePartStructureId'], $this->_info['filename']);
  100. }
  101. }
  102.  
  103. /**
  104. * Sets the node's internal information
  105. *
  106. * @access public
  107. * @since 10/10/05
  108. */
  109. function getNodeInfo () {
  110. $idManager = Services::getService("Id");
  111. $path = $this->_node->getText();
  112. if (!ereg("^([a-zA-Z]+://|[a-zA-Z]+:\\|/)", $path))
  113. $path = $this->_node->ownerDocument->xmlPath.$path;
  114. $this->_info['value'] = $path;
  115. $this->_info['partStructureId'] =$idManager->getId("FILE_DATA");
  116. $this->_info['namePartStructureId'] =$idManager->getId("FILE_NAME");
  117. $this->_info['filename'] = basename($this->_info['value']);
  118.  
  119. $this->_info['parentId'] = $this->_parent->getId();
  120. $this->_info['fileDataId'] =$idManager->getId(
  121. $this->_info['parentId']->getIdString()."-FILE_DATA");
  122. $this->_info['filenameId'] =$idManager->getId(
  123. $this->_info['parentId']->getIdString()."-FILE_NAME");
  124. }
  125. /**
  126. * Relegates Children to their classes
  127. *
  128. * @param object mixed $topImporter is the importer instance that parsed the XML
  129. * @access public
  130. * @since 10/10/05
  131. */
  132. function relegateChildren ($topImporter) {
  133. }
  134. /**
  135. * Looks for discrepencies between imported data and current data
  136. *
  137. * @access public
  138. * @since 10/10/05
  139. */
  140. function update () {
  141. if (isset($this->_info['value']) && !is_null($this->_info['value']) &&
  142. (file_get_contents($this->_info['value']) !=
  143. $this->_object->getValue()))
  144. $this->_object->updateValue(file_get_contents($this->_info['value']));
  145. if (isset($this->_info['filename']) && !is_null($this->_info['filename']) && ($this->_info['filename'] != $this->_object2->getValue()))
  146. $this->_object2->updateValue($this->_info['filename']);
  147. }
  148. }
  149.  
  150. ?>

Documentation generated on Wed, 19 Sep 2007 10:28:32 -0400 by phpDocumentor 1.3.0RC3