function openXML($file) { $doc = new DOMIT_Document(); if ($doc->loadXML(CONTENTDIR . $file)) { $xml =& $doc->documentElement; return $xml; } else { echo 'Could not open or read XML file: ' . $file . '<br />' . $doc->getErrorString(); return false; } }
/** * Constructor * * @param String $sourceDirectory * @param object $parentRepositoryImporter * @return object * @access public * @since 7/20/05 */ function XMLAssetIterator($srcDir, $parentRepositoryImporter) { $import = new DOMIT_Document(); if ($import->loadXML($srcDir . "metadata.xml")) { if (!$import->documentElement->hasChildNodes()) { $parentRepositoryImporter->addError("There are no assets to import in: " . $srcDir . "metadata.xml."); } $this->_assetList = $import->documentElement->childNodes; $this->_current = 0; } else { $parentRepositoryImporter->addError("XML parse failed: " . $srcDir . "metadata.xml does not exist or contains poorly formed XML."); } }
/** * get parameters for createRecord * * @param mixed input * @return array or false on fatal error * @access public * @since 7/20/05 */ function getSingleAssetRecordList($input) { if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Harmoni"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Error", "Events involving critical system errors."); } $idManager = Services::getService("Id"); $this->_fileStructureId = $idManager->getId("FILE"); $fileparts = array("File Name", "Thumbnail Data"); $this->_fileNamePartIds = $this->matchPartStructures($this->_destinationRepository->getRecordStructure($this->_fileStructureId), $fileparts); if (!isset($this->_structureId)) { $import = new DOMIT_Document(); if (!isset($this->_schemaPath)) { $this->_schemaPath = $this->getSchemaPath($this->_srcDir); if (!$this->_schemaPath) { $this->_schemaPath = DEFAULT_EXIF_SCHEMA; } } if ($import->loadXML($this->_schemaPath)) { if (!$import->documentElement->hasChildNodes()) { $this->addError("There are no schemas defined in : " . $this->_schemaPath); if (isset($log)) { $item = new AgentNodeEntryItem("ExifImporter Error", "There are no schemas defined in: " . $this->_schemaPath); $log->appendLogWithTypes($item, $formatType, $priorityType); } return false; } } else { $this->addError("XML parse failed: " . $this->_schemaPath . " does not exist or contains poorly formed XML."); if (isset($log)) { $item = new AgentNodeEntryItem("ExifImporter DOMIT Error", "XML parse failed: " . $this->_schemaPath . " does not exist or contains poorly formed XML."); $log->appendLogWithTypes($item, $formatType, $priorityType); } return false; } $istructuresList = $import->documentElement->childNodes; $this->_structureId = array(); $this->_partsFinal = array(); $this->_valuesFinal = array(); foreach ($istructuresList as $istructure) { $valuesPreFinal = array(); $partStructuresArray = array(); if ($istructure->nodeName == "recordStructure") { //match the structure $ipartStructures = $istructure->childNodes; if ($ipartStructures[0]->getText() != "") { $matchedSchema = $idManager->getId($ipartStructures[0]->getText()); } else { $matchedSchema = $this->matchSchema($ipartStructures[1]->getText(), $this->_destinationRepository); } if ($matchedSchema == false) { $this->addError("Schema: " . $ipartStructures[1]->getText() . " does not exist"); if (isset($log)) { $item = new AgentNodeEntryItem("ExifImporter \n\t\t\t\t\t\t\t\tError", "Schema: " . $ipartStructures[1]->getText() . " does not exist."); $log->appendLogWithTypes($item, $formatType, $priorityType); } return false; } else { $this->_structureId[] = $matchedSchema; } //match the partstructures foreach ($ipartStructures as $ipartStructure) { if ($ipartStructure->nodeName == "partStructure") { $ivaluesArray = $ipartStructure->childNodes; if ($ivaluesArray[0]->getText() != "") { $matchedId = $idManager->getId($ivaluesArray[0]->getText()); } else { $matchedId = $this->getPartIdByName($ivaluesArray[1]->getText(), $matchedSchema); } if ($matchedId == false) { $this->addError("Part " . $ivaluesArray[1]->getText() . " does not exist."); if (isset($log)) { $item = new AgentNodeEntryItem("ExifImporter Error", "Part " . $ivaluesArray[1] . " does not exist."); $log->appendLogWithTypes($item, $formatType, $priorityType); } return false; } $partStructuresArray[] = $matchedId; $repeatableValueArray = array(); foreach ($ivaluesArray as $ivalueField) { if ($ivalueField->nodeName == "value") { $valueArray = array(); $ivaluesChildren = $ivalueField->childNodes; foreach ($ivaluesChildren as $ivalue) { if ($ivalue->nodeName == "exifElement") { $valueArray[] = "exif::" . $ivalue->getText(); } if ($ivalue->nodeName == "text") { $valueArray[] = "text::" . $ivalue->getText(); } } $repeatableValueArray[] = $valueArray; } } $valuesPreFinal[$matchedId->getIdString()] = $repeatableValueArray; } $this->_valuesFinal[$matchedSchema->getIdString()] = $valuesPreFinal; } $this->_partsFinal[$matchedSchema->getIdString()] = $partStructuresArray; } } } $recordList = array(); $recordListElement = array(); $headerData = get_jpeg_header_data($input); $fileMetaData1 = $this->extractPhotoshopMetaData(); $fileMetaData2 = $this->extractExifMetaData($input); $fileMetaData = array_merge($fileMetaData1, $fileMetaData2); $recordListElement['structureId'] = $this->_fileStructureId; $recordListElement['partStructureIds'] = $this->_fileNamePartIds; $recordListElement['parts'] = array($input, ""); $recordList[] = $recordListElement; $recordListElement = array(); foreach ($this->_structureId as $structureId) { $parts = array(); $recordListElement['structureId'] = $structureId; $recordListElement['partStructureIds'] = $this->_partsFinal[$structureId->getIdString()]; $partValuesArray = $this->_valuesFinal[$structureId->getIdString()]; foreach ($partValuesArray as $key => $repeatablePartsArray) { $partValues = array(); foreach ($repeatablePartsArray as $partsComponentsArray) { // If we have a single entry in the value field, create // multiple part values for any repeated source values. if (count($partsComponentsArray) == 1) { $checkExifField = explode("::", $partsComponentsArray[0]); // An Exif Value if ($checkExifField[0] == "exif") { if (isset($fileMetaData[$checkExifField[1]])) { //multi-valued source values if (is_array($fileMetaData[$checkExifField[1]])) { foreach ($fileMetaData[$checkExifField[1]] as $sourceValue) { $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $sourceValue); } } else { $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $fileMetaData[$checkExifField[1]]); } } } else { $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $checkExifField[1]); } } else { $data = ""; foreach ($partsComponentsArray as $partComponent) { $checkExifField = explode("::", $partComponent); // An Exif Value if ($checkExifField[0] == "exif") { if (isset($fileMetaData[$checkExifField[1]])) { if (is_array($fileMetaData[$checkExifField[1]])) { $data .= implode(", ", $fileMetaData[$checkExifField[1]]); } else { $data .= $fileMetaData[$checkExifField[1]]; } } } else { $data .= $checkExifField[1]; } } $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $data); } } $parts[] = $partValues; } $recordListElement['parts'] = $parts; $recordList[] = $recordListElement; } // printpre($recordList); // exit; return $recordList; }
function moreGranulesFromXML() { if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Harmoni"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Error", "Events involving critical system errors."); } $moreXML = $this->_import->documentElement->getElementsByTagName("repositoryfile"); $granules = 0; for ($i = 0; $i < $moreXML->getLength(); $i++) { $element = $moreXML->item($i); $path = $element->getText(); if (!preg_match("#^([a-zA-Z]+://|[a-zA-Z]+:\\|/)#", $path)) { $path = $element->ownerDocument->xmlPath . $path; } $import = new DOMIT_Document(); // attempt to load (parse) the xml file if ($import->loadXML($path)) { if (!$import->documentElement->hasChildNodes()) { $this->addError("There are no Importables in this file"); // log error $item = new AgentNodeEntryItem("XMLImporter Error", "No Importables in the file: " . htmlspecialchars($path) . "."); if (isset($log)) { $log->appendLogWithTypes($item, $formatType, $priorityType); } } else { $nodes = $import->documentElement->getElementsByTagName($this->_granule); $granules += $nodes->getLength(); } } else { // any errors encountered by DOMIT in parsing handled here $this->addError("DOMIT error: " . $import->getErrorCode() . "<br/>\t meaning: " . $import->getErrorString() . "<br/>"); $item = new AgentNodeEntryItem("XMLImporter DOMIT Error", "Error Code: " . $import->getErrorCode() . ", meaning: " . $import->getErrorString() . "."); if (isset($log)) { $log->appendLogWithTypes($item, $formatType, $priorityType); } } } return $granules; }
function read_from_xml() { $tagcnt = array(); if (!file_exists(DIR_FS_CIP . '/' . $this->cip_name . '/' . CONFIG_FILENAME)) { $this->error(ERROR_COULD_NOT_OPEN_XML . $this->cip_name . '/' . CONFIG_FILENAME); return; } require_once DIR_FS_ADMIN_CLASSES . 'xml_domit_parser.php'; $xmlDoc = new DOMIT_Document(); //parse XML $xmlDoc->loadXML(DIR_FS_CIP . '/' . $this->cip_name . '/' . CONFIG_FILENAME); foreach ($xmlDoc->documentElement->childNodes as $id => $tag_data) { // ignore xml comments if ($tag_data->nodeName == '#comment') { continue; } if (array_key_exists($tag_data->nodeName, $tagcnt)) { $tagcnt[$tag_data->nodeName]++; } else { $tagcnt[$tag_data->nodeName] = 0; } if (strtolower($tag_data->nodeName) == 'php') { $this->count_php_tags++; } $clsname = 'Tc_' . strtolower($tag_data->nodeName); if (class_exists($clsname)) { $this->contrib_data[] = new $clsname($this, $tagcnt[$tag_data->nodeName], $tag_data); } else { $this->error('Tag' . $tag_data->nodeName . ' is not supported. Class ' . $clsname . ' does NOT exist.'); return; } if (strtoupper($tag_data->nodeName) == 'DESCRIPTION') { $this->description_id = key($this->contrib_data); } } }