/**
  * @param string $xml
  * @param string $xsdPath
  * @param string $xslPath
  * @return bool:string false if failed, xml text if succeed
  */
 public static function transformXmlData($xml, $xsdPath, $xslPath)
 {
     $from = new KDOMDocument();
     $from->loadXML($xml);
     $xsl = new KDOMDocument();
     $xsl->load($xslPath);
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     $output = $proc->transformToXML($from);
     $to = new KDOMDocument();
     $to->loadXML($output);
     if (!$to->schemaValidate($xsdPath)) {
         return false;
     }
     return $output;
 }
Exemple #2
0
 /**
  * @param array<CuePoint> $cuePoints
  * @return string xml
  */
 public static function generateXml(array $cuePoints)
 {
     $schemaType = CuePointPlugin::getApiValue(CuePointSchemaType::SERVE_API);
     $xsdUrl = "http://" . kConf::get('cdn_host') . "/api_v3/service/schema/action/serve/type/{$schemaType}";
     $scenes = new SimpleXMLElement('<scenes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="' . $xsdUrl . '" />');
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaCuePointXmlParser');
     foreach ($cuePoints as $cuePoint) {
         $scene = null;
         foreach ($pluginInstances as $pluginInstance) {
             $scene = $pluginInstance->generateXml($cuePoint, $scenes, $scene);
         }
     }
     $xmlContent = $scenes->asXML();
     $xml = new KDOMDocument();
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     if (!$xml->loadXML($xmlContent)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xmlContent);
         throw new kCuePointException("XML is invalid:\n{$errorMessage}", kCuePointException::XML_INVALID);
     }
     $xsdPath = SchemaService::getSchemaPath($schemaType);
     libxml_clear_errors();
     if (!$xml->schemaValidate($xsdPath)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xmlContent);
         throw new kCuePointException("XML is invalid:\n{$errorMessage}", kCuePointException::XML_INVALID);
     }
     return $xmlContent;
 }
 /**
  * Validates that the xml is valid using the XSD
  *@return bool - if the validation is ok
  */
 protected function validate()
 {
     if (!file_exists($this->data->filePath)) {
         throw new KalturaBatchException("File doesn't exist [{$this->data->filePath}]", KalturaBatchJobAppErrors::BULK_FILE_NOT_FOUND);
     }
     libxml_use_internal_errors(true);
     $this->loadXslt();
     $xdoc = new KDOMDocument();
     $xmlContent = $this->xslTransform($this->data->filePath);
     libxml_clear_errors();
     if (!$xdoc->loadXML($xmlContent)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xmlContent);
         KalturaLog::debug("Could not load xml");
         throw new KalturaBatchException("Could not load xml [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     //Validate the XML file against the schema
     libxml_clear_errors();
     if (!$xdoc->schemaValidate($this->xsdFilePath)) {
         $errorMessage = kXml::getLibXmlErrorDescription($xmlContent);
         KalturaLog::debug("XML is invalid:\n{$errorMessage}");
         throw new KalturaBatchException("Validate files failed on job [{$this->job->id}], {$errorMessage}", KalturaBatchJobAppErrors::BULK_VALIDATION_FAILED);
     }
     return true;
 }