Source for file XMLImporter.class.php

Documentation is available at XMLImporter.class.php

  1. <?php
  2. /**
  3. * @since 10/5/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: XMLImporter.class.php,v 1.31 2007/09/19 14:04:47 adamfranco Exp $
  10. *
  11. * @author Christopher W. Shubert
  12. */
  13.  
  14. require_once(HARMONI."/utilities/Dearchiver.class.php");
  15. require_once(DOMIT);
  16. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLRepositoryImporter.class.php");
  17. require_once(POLYPHONY."/main/library/Importer/XMLImporters/XMLRepositoryFileImporter.class.php");
  18. require_once(HARMONI."/utilities/StatusStars.class.php");
  19.  
  20. /**
  21. * This class and its children provide the ability to import objects into a
  22. * Harmoni Based Application
  23. *
  24. * @since 10/5/05
  25. * @package polyphony.importer
  26. *
  27. * @copyright Copyright &copy; 2005, Middlebury College
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  29. *
  30. * @version $Id: XMLImporter.class.php,v 1.31 2007/09/19 14:04:47 adamfranco Exp $
  31. */
  32. class XMLImporter {
  33.  
  34. /*******************************************************
  35. * CONSTRUCTORS AND INITIALIZATION
  36. *********************************************************/
  37.  
  38.  
  39. /**
  40. * Constructor
  41. *
  42. * @param array $existingArray contains the idStrings of any objects that
  43. * may be in the xml file but are not to be created.
  44. * @return object XMLImporter
  45. * @access public
  46. * @since 10/5/05
  47. */
  48. function XMLImporter ($existingArray) {
  49. $this->setupSelf(); // gives the importer knowledge about itself
  50. $this->_errors = array(); // end-user friendly error handling
  51. $this->_existingArray =$existingArray;
  52. $this->_parent = null; // A parent for the child importers to use other
  53. // than our object.
  54. }
  55.  
  56. /**
  57. * Constructor with XML File to parse
  58. *
  59. * @param array $existingArray contains the idStrings of any objects that
  60. * may be in the xml file but are not to be created.
  61. * @param string $filepath path to the xml file with importable data
  62. * @param string $type type of the import (update/insert)
  63. * @param string $class class of the importer to instantiate
  64. * @return object mixed
  65. * @access public
  66. * @since 10/11/05
  67. */
  68. function withFile ($existingArray, $filepath, $type, $class = 'XMLImporter') {
  69. if (!(strtolower($class) == strtolower('XMLImporter')
  70. || is_subclass_of(new $class($existingArray), 'XMLImporter')))
  71. {
  72. throwError(new Error ("Class, '$class', is not a subclass of 'XMLImporter'.", "XMLImporter"));
  73. }
  74. eval('$importer = new '.$class.'($existingArray);');
  75. $importer->_xmlFile = $filepath;
  76. $importer->_type = $type;
  77.  
  78. return $importer;
  79. }
  80. /**
  81. * Constructor with XMLFile and starting object
  82. *
  83. * @param array $existingArray contains the idStrings of any objects that
  84. * may be in the xml file but are not to be created.
  85. * @param object mixed $object the object underneath which importer acts
  86. * @param string $filepath path to the xml data file
  87. * @param string $type type of the import (update/insert)
  88. * @param string $class class of the import to instantiate
  89. * @return object mixed
  90. * @access public
  91. * @since 10/11/05
  92. */
  93. function withObject ($existingArray, $object, $filepath, $type, $class = 'XMLImporter') {
  94. if (!(strtolower($class) == strtolower('XMLImporter')
  95. || is_subclass_of(new $class($existingArray), 'XMLImporter')))
  96. {
  97. throwError(new Error ("Class, '$class', is not a subclass of 'XMLImporter'.", "XMLImporter"));
  98. }
  99. eval('$importer = '.$class.'::withFile($existingArray, $filepath, $type, $class);');
  100.  
  101. // this object is already existant; the imported objects will go under
  102. $importer->_object =$object;
  103. $importer->_myId =$importer->_object->getId();
  104. return $importer;
  105. }
  106.  
  107. /**
  108. * Sets up importer's self-knowledge
  109. *
  110. * This knowledge is a list of importers that are available below this and
  111. * the xml elements that correspond to these importers.
  112. * @access public
  113. * @since 10/5/05
  114. */
  115. function setupSelf () {
  116. $this->_childImporterList = array("XMLRepositoryImporter", "XMLRepositoryFileImporter");/*, "XMLSetImporter", "XMLHierarchyImporter", "XMLGroupImporter", "XMLAgentImporter");*/
  117. $this->_childElementList = array("repository", "repositoryfile", "set",
  118. "hierarchy", "group", "agent");
  119. $this->_info = array(); // stores information about importing element
  120.  
  121. }
  122. /**
  123. * Set the parent of the child objects to be imported if it will be different
  124. * from our object. This is used in importing assets into a repository, but
  125. * under an asset in that repository
  126. *
  127. * @param object $parent
  128. * @return void
  129. * @access public
  130. * @since 4/3/07
  131. */
  132. function setParent ( $parent ) {
  133. $this->_parent =$parent;
  134. }
  135.  
  136. /*******************************************************
  137. * ACTIVE IMPORT FUNCTIONS
  138. *********************************************************/
  139.  
  140.  
  141. /**
  142. * Creates the DOMIT Document and Imports the data below the target
  143. *
  144. * This is used to import data underneath an object that already exists
  145. * in the system.
  146. * @param string $granule the xml element to count for status
  147. * @param int $detail the number of divisions for status
  148. * @access public
  149. * @since 10/5/05
  150. */
  151. function parseAndImportBelow ($granule, $detail = 50) {
  152. if (Services::serviceRunning("Logging")) {
  153. $loggingManager = Services::getService("Logging");
  154. $log =$loggingManager->getLogForWriting("Harmoni");
  155. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  156. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  157. $priorityType = new Type("logging", "edu.middlebury", "Error",
  158. "Events involving critical system errors.");
  159. }
  160. $this->_import = new DOMIT_Document();
  161. // attempt to load (parse) the xml file
  162. if ($this->_import->loadXML($this->_xmlFile)) {
  163. // xmlPath is used for finding files tared up with the import
  164. $this->_import->xmlPath = dirname($this->_xmlFile)."/";
  165. // @todo check the xml structure against what is expected
  166. if (!$this->_checkXMLStructure()) {
  167. $this->addError("This file can not be handled by this importer");
  168. // log error
  169. $item = new AgentNodeEntryItem("XMLImporter Error",
  170. "Improper Import Format: ".$this->_xmlFile.".");
  171. if (isset($log))
  172. $log->appendLogWithTypes($item, $formatType, $priorityType);
  173. }
  174. else if (!($this->_import->documentElement->hasChildNodes())) {
  175. $this->addError("There are no Importables in this file");
  176. // log error
  177. $item = new AgentNodeEntryItem("XMLImporter Error",
  178. "No Importables in the file: ".$this->_xmlFile.".");
  179. if (isset($log))
  180. $log->appendLogWithTypes($item, $formatType, $priorityType);
  181. } else {
  182. // the parsing importer is responsible for the docElement
  183. $this->_node =$this->_import->documentElement;
  184. $this->setupStatusBar($granule, $detail);
  185. if (isset($this->_myId))
  186. $this->importBelow($this, $this->_myId->getIdString());
  187. else
  188. $this->importBelow($this,
  189. "edu.middlebury.authorization.root");
  190. }
  191. }
  192. else {
  193. // any errors encountered by DOMIT in parsing handled here
  194. $this->addError("DOMIT error: ".$this->_import->getErrorCode().
  195. "<br/>\t meaning: ".$this->_import->getErrorString()."<br/>");
  196. $item = new AgentNodeEntryItem("XMLImporter DOMIT Error",
  197. "Error Code: ".$this->_import->getErrorCode().", meaning: ".
  198. $this->_import->getErrorString().".");
  199. if (isset($log))
  200. $log->appendLogWithTypes($item, $formatType, $priorityType);
  201. }
  202. }
  203. /**
  204. * Creates the DOMIT Document and Imports the data including the top target
  205. *
  206. * @param string $granule the xml element to count for status
  207. * @param int $detail the number of divisions for status
  208. * @access public
  209. * @since 10/5/05
  210. */
  211. function parseAndImport ($granule, $detail = 50) {
  212. if (Services::serviceRunning("Logging")) {
  213. $loggingManager = Services::getService("Logging");
  214. $log =$loggingManager->getLogForWriting("Harmoni");
  215. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  216. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  217. $priorityType = new Type("logging", "edu.middlebury", "Error",
  218. "Events involving critical system errors.");
  219. }
  220. $this->_import = new DOMIT_Document();
  221. // attempt to load (parse) XML file
  222. if ($this->_import->loadXML($this->_xmlFile)) {
  223. // path for finding files associated with import
  224. $this->_import->xmlPath = dirname($this->_xmlFile)."/";
  225. // check the xml structure against what is expected
  226. if (!$this->_checkXMLStructure()) {
  227. $this->addError("This file can not be handled by this importer");
  228. // log error
  229. $item = new AgentNodeEntryItem("XMLImporter Error",
  230. "Improper Import Format: ".$this->_xmlFile.".");
  231. if (isset($log))
  232. $log->appendLogWithTypes($item, $formatType, $priorityType);
  233. }
  234. else if (!($this->_import->documentElement->hasChildNodes())) {
  235. $this->addError("There are no Importables in this file");
  236. // log error
  237. $item = new AgentNodeEntryItem("XMLImporter Error",
  238. "No Importables in the file: ".$this->_xmlFile.".");
  239. if (isset($log))
  240. $log->appendLogWithTypes($item, $formatType, $priorityType);
  241. } else {
  242. // the parsing importer is responsible for the docElement
  243. $this->_node =$this->_import->documentElement;
  244. $this->setupStatusBar($granule, $detail);
  245. $null = null;
  246. $this->import($this, $this->_node, $this->_type, $null);
  247. }
  248. }
  249. else {
  250. // any errors encountered by DOMIT in parsing handled here
  251. $this->addError("DOMIT error: ".$this->_import->getErrorCode().
  252. "<br/>\t meaning: ".$this->_import->getErrorString()."<br/>");
  253. $item = new AgentNodeEntryItem("XMLImporter DOMIT Error",
  254. "Error Code: ".$this->_import->getErrorCode().", meaning: ".
  255. $this->_import->getErrorString().".");
  256. if (isset($log))
  257. $log->appendLogWithTypes($item, $formatType, $priorityType);
  258. }
  259. }
  260. /**
  261. * Starts an import below the qualifier passed
  262. *
  263. * @param object mixed $topImporter is the importer instance that parsed the XML
  264. * @param string $authZQString string of the qualifier for the object
  265. * @return object HarmoniId
  266. * @access public
  267. * @since 10/11/05
  268. */
  269. function importBelow ($topImporter, $authZQString = null) {
  270. if (!$this->canImportBelow($authZQString))
  271. return;
  272. // some importables need to map ids
  273. if (isset($this->_myId)) {
  274. $this->doIdMatrix();
  275. }
  276. // send the child elements (XML) to the appropriate importers
  277. $this->relegateChildren($topImporter);
  278. // done with id mapping
  279. $this->dropIdMatrix();
  280. if (isset($this->_myId)) {
  281. return $this->_myId;
  282. }
  283. }
  284. /**
  285. * Checks if the user is able to import underneath this level
  286. *
  287. * @todo the authorizations could not keep up with the importer
  288. * @param string $authZQString qualifier for authz checking
  289. * @access public
  290. * @since 11/3/05
  291. */
  292. function canImportBelow($authZQString) {
  293. // $authZ = Services::getService("AuthZ");
  294. // $idManager = Services::getService("Id");
  295. //
  296. // if (!$authZ->isUserAuthorized(
  297. // $idManager->getId("edu.middlebury.authorization.add_children"),
  298. // $idManager->getId($authZQString))) {
  299. // $this->addError("No Authorization to Import under ".
  300. // get_class($this).": ".$authZQString);
  301. // return false;
  302. // }
  303. return true;
  304. }
  305. /**
  306. * Organizes the import
  307. *
  308. * @param object mixed $topImporter is the importer instance that parsed the XML
  309. * @param object DOMIT_Node $node domit node for importing
  310. * @param string $type type of import (update/insert)
  311. * @param object mixed $parent parent of object to be imported
  312. * @return object HarmoniId
  313. * @access public
  314. * @since 10/5/05
  315. */
  316. function import ($topImporter, $node, $type, $parent) {
  317. $this->_node =$node; // xml element representing datastructure
  318. $this->_type = $type; // type of import (currently unimportant)
  319. $this->_parent =$parent; // xml element parent
  320.  
  321. $bottom = $this->importNode(); // bottom says do not import below me
  322. unset($this->_info); // don't need anymore
  323. if ($bottom === true)
  324. return;
  325. if (isset($this->_myId)) {
  326. return $this->importBelow($topImporter,
  327. $this->_myId->getIdString());
  328. } else {
  329. return $this->importBelow($topImporter);
  330. }
  331. }
  332.  
  333. /**
  334. * Does what is necessary to the temporary table for internal id association
  335. *
  336. * @access public
  337. * @since 10/6/05
  338. */
  339. function doIdMatrix () {
  340. /* only implemented where needed */
  341. }
  342. /**
  343. * Drops the temporary table for internal id association
  344. *
  345. * @access public
  346. * @since 10/6/05
  347. */
  348. function dropIdMatrix () {
  349. /* only implemented where needed */
  350. }
  351. /**
  352. * Imports the node itself
  353. *
  354. * @access public
  355. * @since 10/5/05
  356. */
  357. function importNode () {
  358. $this->_object = null;
  359. }
  360. /**
  361. * Relegates child XML elements to their importer classes
  362. *
  363. * By matching the xml elements with their importers the importer hierachy
  364. * is able to import each element with much customization (detail) making it
  365. * easier to handle new elements with new child classes. This function also
  366. * passes any errors encountered in a child importer back up until the
  367. * errors reach the top importer where they get printed at the end of the
  368. * import
  369. * @param object mixed $topImporter is the importer instance that parsed the XML
  370. * @access public
  371. * @since 10/5/05
  372. */
  373. function relegateChildren ($topImporter) {
  374. foreach ($this->_node->childNodes as $element) {
  375. if (is_array($this->_childImporterList)) {
  376. foreach ($this->_childImporterList as $importer) {
  377. if (!is_subclass_of(new $importer($this->_existingArray),
  378. 'XMLImporter')) {
  379. $this->addError("Class, '$class', is not a subclass of 'XMLImporter'.");
  380. // log error
  381. if (Services::serviceRunning("Logging")) {
  382. $loggingManager = Services::getService("Logging");
  383. $log =$loggingManager->getLogForWriting("Harmoni");
  384. $formatType = new Type("logging", "edu.middlebury",
  385. "AgentsAndNodes",
  386. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  387. $priorityType = new Type("logging", "edu.middlebury",
  388. "Error","Events involving critical system errors.");
  389. $item = new AgentNodeEntryItem("XMLImporter Error",
  390. "Class, '$class' is not a subclass of 'XMLImporter'.");
  391. $log->appendLogWithTypes($item, $formatType,
  392. $priorityType);
  393. }
  394. break;
  395. }
  396. eval('$result = '.$importer.'::isImportable($element);');
  397. if ($result) {
  398. $imp = new $importer($this->_existingArray);
  399. $imp->import($topImporter, $element, $this->_type, $this->getParentForImporter($importer));
  400. // used for bubbling errors to the top...
  401. if ($imp->hasErrors())
  402. foreach($imp->getErrors() as $error)
  403. $this->addError($error);
  404. unset($imp);
  405. }
  406. }
  407. }
  408. if ($topImporter->_granule == $element->nodeName)
  409. $topImporter->_status->updateStatistics();
  410. }
  411. }
  412. /**
  413. * Answer the parent for the importer. This allows importers such as the
  414. * XMLRepositoryImporter to switch and import assets underneith another asset
  415. * rather than just under themselves.
  416. *
  417. * @param string $importerClass
  418. * @return object
  419. * @access public
  420. * @since 4/3/07
  421. */
  422. function getParentForImporter ( $importer) {
  423. $parent =$this->_object;
  424. return $parent;
  425. }
  426. /**
  427. * Populates _info array with data from the xml file
  428. *
  429. * Retrieves all the necessary information to build the object that the
  430. * current xml element represents.
  431. * @access public
  432. * @since 10/5/05
  433. */
  434. function getNodeInfo () {
  435. foreach ($this->_node->childNodes as $element) {
  436. if (is_null($this->_childElementList) ||
  437. !in_array($element->nodeName, $this->_childElementList)) {
  438. $helper = "build".ucfirst($element->nodeName);
  439. if (method_exists($this, $helper))
  440. $this->$helper($element);
  441. else {
  442. $this->addError($helper."() does not exist");
  443. // log error
  444. if (Services::serviceRunning("Logging")) {
  445. $loggingManager = Services::getService("Logging");
  446. $log =$loggingManager->getLogForWriting("Harmoni");
  447. $formatType = new Type("logging", "edu.middlebury",
  448. "AgentsAndNodes",
  449. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  450. $priorityType = new Type("logging", "edu.middlebury",
  451. "Error","Events involving critical system errors.");
  452. $item = new AgentNodeEntryItem("XMLImporter Error",
  453. "Function, '$helper' does not exist");
  454. $log->appendLogWithTypes($item, $formatType,
  455. $priorityType);
  456. }
  457. }
  458. }
  459. }
  460. }
  461. /**
  462. * Update
  463. *
  464. * @access public
  465. * @since 10/10/05
  466. */
  467. function update () {
  468. /* no update */
  469. }
  470.  
  471. /*******************************************************
  472. * HELPER FUNCTIONS FOR GETTING NODE INFO
  473. *********************************************************/
  474.  
  475.  
  476. /**
  477. * Builds a type object from a type import node
  478. *
  479. * @param object DOMIT_Node
  480. * @access public
  481. * @since 9/12/05
  482. */
  483. function buildType ($element) {
  484. $pieces = $element->childNodes;
  485. $type = array();
  486. foreach ($pieces as $piece)
  487. $type[$piece->nodeName] = $piece->getText();
  488. if (isset($type['description']))
  489. $this->_info['type'] = new Type($type['domain'],
  490. $type['authority'], $type['keyword'], $type['description']);
  491. else
  492. $this->_info['type'] = new Type($type['domain'],
  493. $type['authority'], $type['keyword']);
  494. }
  495.  
  496. /**
  497. * Builds a dimensions object from a type import node
  498. *
  499. * @param object DOMIT_Node
  500. * @access public
  501. * @since 10/10/05
  502. */
  503. function buildDimensions ($element) {
  504. $pieces = $element->childNodes;
  505. $dim = array();
  506. foreach ($pieces as $piece)
  507. $dim[$piece->nodeName] = $piece->getText();
  508. $this->_info['value'] = array($dim['width'], $dim['height']);
  509. }
  510. /* Helper function for XML elements
  511. *
  512. * @param object DOMIT_Node
  513. * @access public
  514. * @since 9/13/05
  515. */
  516. function buildName ($element) {
  517. $this->_info['name'] = $element->getText();
  518. }
  519. /**
  520. * Helper function for XML elements
  521. *
  522. * @param object DOMIT_Node
  523. * @access public
  524. * @since 9/13/05
  525. */
  526. function buildDescription ($element) {
  527. $this->_info['description'] = $element->getText();
  528. }
  529.  
  530. /**
  531. * Helper function for XML elements
  532. *
  533. * @param object DOMIT_Node
  534. * @access public
  535. * @since 9/13/05
  536. */
  537. function buildFormat ($element) {
  538. $this->_info['format'] = $element->getText();
  539. }
  540. /**
  541. * Helper function for XML elements
  542. *
  543. * @param object DOMIT_Node
  544. * @access public
  545. * @since 9/13/05
  546. */
  547. function buildEffectivedate ($element) {
  548. $this->_info['effectivedate'] = $element->getText();
  549. }
  550. /**
  551. * Helper function for XML elements
  552. *
  553. * @param object DOMIT_Node
  554. * @access public
  555. * @since 9/13/05
  556. */
  557. function buildExpirationdate ($element) {
  558. $this->_info['expirationdate'] = $element->getText();
  559. }
  560. /**
  561. *
  562. *
  563. * @return string
  564. * @access public
  565. * @since 7/20/05
  566. */
  567. function decompress ($filepath) {
  568. $dearchiver = new Dearchiver();
  569. $worked = $dearchiver->uncompressFile($filepath,
  570. dirname($filepath));
  571. if ($worked == false) {
  572. $this->addError("Failed to decompress file: ".$filepath.
  573. ". Unsupported archive extension.");
  574. // log error
  575. if (Services::serviceRunning("Logging")) {
  576. $loggingManager = Services::getService("Logging");
  577. $log =$loggingManager->getLogForWriting("Harmoni");
  578. $formatType = new Type("logging", "edu.middlebury",
  579. "AgentsAndNodes",
  580. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  581. $priorityType = new Type("logging", "edu.middlebury", "Error",
  582. "Events involving critical system errors.");
  583. $item = new AgentNodeEntryItem("XMLImporter Dearchiver Error",
  584. "Failed to decompress file: $filepath. Unsupported archive extension.");
  585. $log->appendLogWithTypes($item, $formatType, $priorityType);
  586. }
  587. }
  588. unset($dearchiver);
  589. return dirname($filepath);
  590. }
  591.  
  592. /*******************************************************
  593. * ERROR HANDLING FOR THE IMPORTERS
  594. *********************************************************/
  595.  
  596.  
  597. /**
  598. * This function determines the structure wanted and makes sure it is so
  599. *
  600. * sub-classes that can start an import should overwrite this function
  601. * @access public
  602. * @since 2/23/06
  603. */
  604. function _checkXMLStructure () {
  605. return ($this->_import->documentElement->nodeName == "import");
  606. }
  607.  
  608.  
  609. /**
  610. * Print the AssetIds for Assets created properly by the importer
  611. *
  612. * @param array $goodAssetIds
  613. * @since 7/29/05
  614. */
  615. function printErrorMessages() {
  616. print "<div style='color:#FF0000;'>";
  617. foreach ($this->_errors as $errorString) {
  618. print("Error: ".$errorString."<br />");
  619. }
  620. print 'Please, Cancel this wizard and investigate other import options. See Help.';
  621. print '</div>';
  622. }
  623.  
  624. /**
  625. * gets error array
  626. *
  627. * @return array
  628. * @access public
  629. * @since 7/26/05
  630. */
  631. function getErrors() {
  632. return $this->_errors;
  633. }
  634. /**
  635. * checks for errors
  636. *
  637. * @return boolean
  638. * @access public
  639. * @since 7/26/05
  640. */
  641. function hasErrors() {
  642. return (count($this->_errors) > 0);
  643. }
  644.  
  645. /**
  646. * adds an error to the error array
  647. *
  648. * @param String $error
  649. * @access public
  650. * @since 7/26/05
  651. */
  652. function addError($error) {
  653. if (!isset($this->_errors))
  654. $this->_errors = array();
  655. if (isset($this->_myId))
  656. $this->_errors[] = $this->_myId->getIdString()."::".$error;
  657. else
  658. $this->_errors[] = $error;
  659. }
  660. /*******************************************************
  661. * STATUS BAR UTILITY
  662. *********************************************************/
  663.  
  664.  
  665. function moreGranulesFromXML () {
  666. if (Services::serviceRunning("Logging")) {
  667. $loggingManager = Services::getService("Logging");
  668. $log =$loggingManager->getLogForWriting("Harmoni");
  669. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  670. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  671. $priorityType = new Type("logging", "edu.middlebury", "Error",
  672. "Events involving critical system errors.");
  673. }
  674. $moreXML =$this->_import->documentElement->getElementsByTagName(
  675. "repositoryfile");
  676. $granules = 0;
  677. for ($i = 0; $i < $moreXML->getLength(); $i++) {
  678. $element =$moreXML->item($i);
  679. $path = $element->getText();
  680. if (!ereg("^([a-zA-Z]+://|[a-zA-Z]+:\\|/)", $path))
  681. $path = $element->ownerDocument->xmlPath.$path;
  682. $import = new DOMIT_Document();
  683. // attempt to load (parse) the xml file
  684. if ($import->loadXML($path)) {
  685. if (!($import->documentElement->hasChildNodes())) {
  686. $this->addError("There are no Importables in this file");
  687. // log error
  688. $item = new AgentNodeEntryItem("XMLImporter Error",
  689. "No Importables in the file: ".$path.".");
  690. if (isset($log))
  691. $log->appendLogWithTypes($item, $formatType, $priorityType);
  692. } else {
  693. $nodes =$import->documentElement->getElementsByTagName(
  694. $this->_granule);
  695. $granules += $nodes->getLength();
  696. }
  697. }
  698. else {
  699. // any errors encountered by DOMIT in parsing handled here
  700. $this->addError("DOMIT error: ".$import->getErrorCode().
  701. "<br/>\t meaning: ".$import->getErrorString()."<br/>");
  702. $item = new AgentNodeEntryItem("XMLImporter DOMIT Error",
  703. "Error Code: ".$import->getErrorCode().", meaning: ".
  704. $import->getErrorString().".");
  705. if (isset($log))
  706. $log->appendLogWithTypes($item, $formatType, $priorityType);
  707. }
  708. }
  709. return $granules;
  710. }
  711.  
  712. /**
  713. * Sets up the status bar with appropriate granule
  714. *
  715. * @param string $granule the xml element for status bar granule
  716. * @param int $detail the number of divisions for the status bar
  717. * @access public
  718. * @since 2/27/06
  719. */
  720. function setupStatusBar ($granule, $detail) {
  721. // @todo allow for array parameter so that multiple granules are used!
  722. $this->_granule = $granule;
  723. $this->_status = new StatusStars();
  724. $granules = 0;
  725. $nodes =$this->_import->documentElement->getElementsByTagName(
  726. $granule);
  727. $granules += $nodes->getLength();
  728. // $granules += $this->moreGranulesFromXML();
  729.  
  730. $this->_status->initializeStatistics($granules, $detail);
  731. }
  732.  
  733. /*******************************************************
  734. * ASSET ID TRACKING FOR DEVELOPMENT
  735. *********************************************************/
  736.  
  737. // /**
  738. // * Print the AssetIds for Assets created properly by the importer
  739. // *
  740. // * @param array $goodAssetIds
  741. // * @since 7/29/05
  742. // */
  743. // function printGoodAssetIds() {
  744. // foreach ($this->_goodAssetIds as $id) {
  745. // print("Asset: ".$id->getIdString()."<br />");
  746. // }
  747. // }
  748. //
  749. // /**
  750. // * gets created assset ids array
  751. // *
  752. // * @return array
  753. // * @access public
  754. // * @since 7/26/05
  755. // */
  756. // function getGoodAssetIds() {
  757. // return $this->_goodAssetIds;
  758. // }
  759. //
  760. // /**
  761. // * checks for built Assets
  762. // *
  763. // * @return boolean
  764. // * @access public
  765. // * @since 7/26/05
  766. // */
  767. // function hasAssets() {
  768. // return (count($this->_goodAssetIds) > 0);
  769. // }
  770. //
  771. // /**
  772. // * adds an error to the error array
  773. // *
  774. // * @param String $error
  775. // * @access public
  776. // * @since 7/26/05
  777. // */
  778. // function addGoodAssetId($goodAssetId) {
  779. // if (!isset($this->_errors))
  780. // $this->_errors = array();
  781. // $this->_goodAssetIds[] = $goodAssetId;
  782. // }
  783.  
  784. }
  785.  
  786. ?>

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