Source for file XMLPartStructureImporter.class.php

Documentation is available at XMLPartStructureImporter.class.php

  1. <?php
  2. /**
  3. * @since 10/6/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: XMLPartStructureImporter.class.php,v 1.23 2007/09/19 14:04:47 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLImporter.class.php");
  13.  
  14. /**
  15. * XMLPartStructureImporter imports a PartStructure via delegation to
  16. * subclasses
  17. *
  18. * @since 10/6/05
  19. * @package polyphony.importer
  20. *
  21. * @copyright Copyright &copy; 2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  23. *
  24. * @version $Id: XMLPartStructureImporter.class.php,v 1.23 2007/09/19 14:04:47 adamfranco Exp $
  25. */
  26. class XMLPartStructureImporter extends XMLImporter {
  27. /**
  28. * Constructor; parses XML if passed file
  29. *
  30. *
  31. * @return object XMLPartStructureImporter
  32. * @access public
  33. * @since 10/6/05
  34. */
  35. function XMLPartStructureImporter ($existingArray) {
  36. parent::XMLImporter($existingArray);
  37. }
  38.  
  39. /**
  40. * Sets up importer's self-knowledge
  41. *
  42. * @access public
  43. * @since 10/6/05
  44. */
  45. function setupSelf () {
  46. $this->_childImporterList = NULL;
  47. $this->_childElementList = NULL;
  48. $this->_info = array();
  49. }
  50.  
  51. /**
  52. * Filters nodes of incorrect type
  53. *
  54. * @param object DOMIT_Node
  55. * @return boolean
  56. * @static
  57. * @access public
  58. * @since 10/6/05
  59. */
  60. function isImportable ($element) {
  61. if($element->nodeName == "partstructure")
  62. return true;
  63. else
  64. return false;
  65. }
  66. /**
  67. * Checks if the user is able to import underneath this level
  68. *
  69. * @param string $authZQString qualifier for authz checking
  70. * @access public
  71. * @since 11/3/05
  72. */
  73. function canImportBelow($authZQString) {
  74. return true;
  75. }
  76.  
  77. /**
  78. * Checks this node for any changes to make to this
  79. *
  80. * @access public
  81. * @since 10/6/05
  82. */
  83. function importNode () {
  84. $idManager = Services::getService("IdManager");
  85. $this->getNodeInfo();
  86.  
  87. $hasId = $this->_node->hasAttribute("id");
  88. if ($hasId && (in_array($this->_node->getAttribute("id"),
  89. $this->_existingArray) || $this->_type == "update")) {
  90. $this->_myId =$idManager->getId($this->_node->getAttribute("id"));
  91. $this->_object =$this->_parent->getPartStructure($this->_myId);
  92. $this->update();
  93. } else if ($this->validate($this->_info['type'])) {
  94. // If we an id specified for this global Record Structure make use
  95. // it. This is to allow for pre-defined ids of important RecordStructures
  96. // like Dublin Core
  97. if ($this->_node->hasAttribute("id") && $this->_node->getAttribute("id")) {
  98. $parentId =$this->_parent->getId();
  99. // Escape any regular expression special characters
  100. $parentIdStringTerm = preg_replace('/[\/()\[\]\.\+\?\^\$]/',
  101. '\\\\$0', $parentId->getIdString());
  102. // If the id already is prepended with the record structure
  103. // Id, strip off the record structure id as it will be appended
  104. // later.
  105. if (preg_match('/^'.$parentIdStringTerm.'\.(.+)$/',
  106. $this->_node->getAttribute("id"), $matches))
  107. {
  108. $id = $idManager->getId($matches[1]);
  109. }
  110. // use the specified Id.
  111. else {
  112. $id = $idManager->getId($this->_node->getAttribute("id"));
  113. }
  114. } else
  115. $id = null;
  116. $this->_object =
  117. $this->_parent->createPartStructure(
  118. $this->_info['name'], $this->_info['description'],
  119. $this->_info['type'],
  120. (($this->_info['isMandatory'] == "TRUE")?true:false),
  121. (($this->_info['isRepeatable'] == "TRUE")?true:false),
  122. (($this->_info['isPopulated'] == "TRUE")?true:false),
  123. $id);
  124. $this->_myId =$this->_object->getId();
  125. }
  126. else {
  127. $this->addError("bad PartStructure data Type");
  128. if (Services::serviceRunning("Logging")) {
  129. $loggingManager = Services::getService("Logging");
  130. $log =$loggingManager->getLogForWriting("Harmoni");
  131. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  132. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  133. $priorityType = new Type("logging", "edu.middlebury", "Error",
  134. "Events involving critical system errors.");
  135. $item = new AgentNodeEntryItem("PartStructure Importer", "Bad PartStructure DataType: ".$this->_info['type']->getKeyword()." undefined");
  136. $log->appendLogWithTypes($item, $formatType, $priorityType);
  137. }
  138. }
  139. }
  140. /**
  141. * Makes sure partstructures are of a valid type by checking them
  142. *
  143. * @param string $type the type for the partstructure that wants to be imported
  144. * @return boolean
  145. * @since 12/31/05
  146. */
  147. function validate($type) {
  148. // get a set of valid types from the DM
  149. $dm = Services::getService("DataTypeManager");
  150. $validTypes = $dm->getRegisteredTypes();
  151. if (in_array($type->getKeyword(), $validTypes))
  152. return true;
  153. else
  154. return false;
  155. }
  156. /**
  157. * Does what is necessary to the temporary table for internal id association
  158. *
  159. * @access public
  160. * @since 10/6/05
  161. */
  162. function doIdMatrix () {
  163. $dbHandler = Services::getService("DBHandler");
  164. // $dbIndexConcerto =$dbHandler->addDatabase(new
  165. // MySQLDatabase("localhost", "whitey_concerto", "test", "test"));
  166. $query = new InsertQuery;
  167. $query->setTable("xml_id_matrix");
  168. $query->setColumns(array("xml_id", "conc_id"));
  169. $xmlid = $this->_node->getAttribute("xml:id");
  170. $query->addRowOfValues(array("'".addslashes($xmlid)."'", "'".addslashes(
  171. $this->_myId->getIdString())."'"));
  172. //$dbHandler->connect($dbIndexConcerto);
  173. $dbHandler->query($query, IMPORTER_CONNECTION);
  174. }
  175. /**
  176. * sets the node's info
  177. *
  178. * @access public
  179. * @since 10/6/05
  180. */
  181. function getNodeInfo () {
  182. parent::getNodeInfo();
  183. if ($this->_node->hasAttribute("isMandatory"))
  184. $this->_info['isMandatory'] = $this->_node->getAttribute(
  185. "isMandatory");
  186. else $this->_info['isMandatory'] = FALSE;
  187. if ($this->_node->hasAttribute("isRepeatable"))
  188. $this->_info['isRepeatable'] = $this->_node->getAttribute(
  189. "isRepeatable");
  190. else $this->_info['isRepeatable'] = FALSE;
  191. if ($this->_node->hasAttribute("isPopulated"))
  192. $this->_info['isPopulated'] = $this->_node->getAttribute(
  193. "isPopulated");
  194. else $this->_info['isPopulated'] = FALSE;
  195. }
  196.  
  197. /**
  198. * Looks for discrepencies between imported data and current data
  199. *
  200. * @access public
  201. * @since 10/6/05
  202. */
  203. function update () {
  204. if (isset($this->_info['name']) && !is_null($this->_info['name']) && ($this->_info['name'] != $this->_object->getDisplayName()))
  205. $this->_object->updateDisplayName($this->_info['name']);
  206. }
  207. }
  208.  
  209. ?>

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