Source for file XMLRepositoryExporter.class.php

Documentation is available at XMLRepositoryExporter.class.php

  1. <?php
  2. /**
  3. * @since 10/17/05
  4. * @package polyphony.exporter
  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: XMLRepositoryExporter.class.php,v 1.13 2007/09/19 14:04:45 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Exporter/XMLExporter.class.php");
  13. require_once(POLYPHONY."/main/library/Exporter/XMLRecordStructureExporter.class.php");
  14. require_once(POLYPHONY."/main/library/Exporter/XMLAssetExporter.class.php");
  15.  
  16. /**
  17. * Exports into XML for use with the XML Importer
  18. *
  19. * @since 10/17/05
  20. * @package polyphony.exporter
  21. *
  22. * @copyright Copyright &copy; 2005, Middlebury College
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  24. *
  25. * @version $Id: XMLRepositoryExporter.class.php,v 1.13 2007/09/19 14:04:45 adamfranco Exp $
  26. */
  27. class XMLRepositoryExporter extends XMLExporter {
  28. /**
  29. * Constructor
  30. *
  31. * Maintains archive and repository directory.
  32. *
  33. * @param object Archive_Tar
  34. * @param string
  35. * @access public
  36. * @since 10/17/05
  37. */
  38. function XMLRepositoryExporter() {
  39. parent::XMLExporter();
  40. }
  41.  
  42. /**
  43. * Creates the child lists
  44. *
  45. * @access public
  46. * @since 10/31/05
  47. */
  48. function setupSelf() {
  49. $this->_childExporterList = array("XMLRecordStructureExporter",
  50. "XMLAssetExporter");
  51. $this->_childElementList = array("recordstructures", "assets");
  52. }
  53.  
  54. /**
  55. * Constructor for starting an export
  56. *
  57. * @param string
  58. * @param string
  59. * @access public
  60. * @since 10/31/05
  61. */
  62. function withCompression($compression, $class = 'XMLRepositoryExporter') {
  63. return parent::withCompression($compression, $class);
  64. }
  65.  
  66. /**
  67. * Constructor for in an export
  68. *
  69. * @param string
  70. * @param string
  71. * @access public
  72. * @since 10/31/05
  73. */
  74. function withDir($tmpDir, $class = 'XMLRepositoryExporter') {
  75. $exporter = new $class;
  76. $exporter->_tmpDir = $tmpDir;
  77. return $exporter;
  78. }
  79. /**
  80. * Exporter of Repository things
  81. *
  82. *
  83. * @param object HarmoniId
  84. * @access public
  85. * @since 10/17/05
  86. */
  87. function export ($repId) {
  88. // ===== CREATE THE DIRECTORY FOR THIS OBJECT ===== //
  89. $this->_repDir = $this->_tmpDir."/".$repId->getIdString();
  90. mkdir($this->_repDir);
  91.  
  92. // ===== SELF KNOWLEDGE ===== //
  93. $this->_myId =$repId;
  94. $rm = Services::getService("Repository");
  95. $this->_object =$rm->getRepository($this->_myId);
  96. $type =$this->_object->getType();
  97.  
  98. // ===== SELF EXPORT ===== //
  99. $this->setupXML($this->_repDir);
  100. fwrite($this->_xml,
  101. "<repository id=\"".$this->_myId->getIdString()."\">\n".
  102. "\t<name>".$this->_object->getDisplayName()."</name>\n".
  103. "\t<description><![CDATA[".$this->_object->getDescription()."]]></description>\n".
  104. "\t<type>\n".
  105. "\t\t<domain>".$type->getDomain()."</domain>\n".
  106. "\t\t<authority>".$type->getAuthority()."</authority>\n".
  107. "\t\t<keyword>".$type->getKeyword()."</keyword>\n");
  108. if ($type->getDescription() != "")
  109. fwrite($this->_xml,
  110. "\t\t<description><![CDATA[".$type->getDescription()."]]></description>\n");
  111. fwrite($this->_xml,
  112. "\t</type>\n");
  113. // ===== CHILD CLASSES ARE EXPORTED HERE ===== //
  114. foreach ($this->_childElementList as $child) {
  115. $exportFn = "export".ucfirst($child);
  116. if (method_exists($this, $exportFn)) {
  117. $this->$exportFn();
  118. }
  119. }
  120.  
  121. // ===== CLOSE SELF XML ===== //
  122. fwrite($this->_xml, "</repository>\n");
  123. fclose($this->_xml);
  124.  
  125. // ===== RETURN THE NAME OF THE ARCHIVE (important when top level) ===== //
  126. return $this->_tmpDir;
  127. }
  128.  
  129. /**
  130. * Exporter of recordstructures
  131. *
  132. * Adds recordstructure elements to the xml, which contain the necessary
  133. * information to create the same recordstructure.
  134. *
  135. * @access public
  136. * @since 10/17/05
  137. */
  138. function exportRecordstructures () {
  139. $children =$this->_object->getRecordStructures();
  140. while ($children->hasNext()) {
  141. $child =$children->next();
  142. $exporter = new XMLRecordStructureExporter($this->_xml);
  143. $exporter->export($child); // ????
  144. }
  145. unset($children, $child, $exporter);
  146. }
  147.  
  148. /**
  149. * Exporter of Assets
  150. *
  151. * @access public
  152. * @since 10/17/05
  153. */
  154. function exportAssets () {
  155. $hasRootSearch = FALSE;
  156. $rootSearchType = new HarmoniType("Repository",
  157. "edu.middlebury.harmoni", "RootAssets", "");
  158. $searchTypes =$this->_object->getSearchTypes();
  159. while ($searchTypes->hasNext()) {
  160. if ($rootSearchType->isEqual( $searchTypes->next() )) {
  161. $hasRootSearch = TRUE;
  162. break;
  163. }
  164. }
  165. if ($hasRootSearch) {
  166. $criteria = NULL;
  167. $children =$this->_object->getAssetsBySearch($criteria,
  168. $rootSearchType, $searchProperties = NULL);
  169. } else
  170. $children =$this->_object->getAssets();
  171. $this->_status = new StatusStars(str_replace('%1', $this->_object->getDisplayName(), _("Exporting all Assets in the Collection, '%1'")));
  172. $this->_status->initializeStatistics($children->count(), 100);
  173. while ($children->hasNext()) {
  174. $child =$children->next();
  175. $exporter = XMLAssetExporter::withDir($this->_xml, $this->_repDir);
  176. $exporter->export($child);
  177. $this->_status->updateStatistics();
  178. }
  179. unset($exporter);
  180. }
  181. }
  182. ?>

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