Esempio n. 1
0
File: wiki.php Progetto: bmdevel/ezc
 /**
  * Validate the input string
  *
  * Validate the input string against the specification of the current
  * document format.
  *
  * Returns true, if the validation succeded, and an array with
  * ezcDocumentValidationError objects otherwise.
  *
  * @param string $string
  * @return mixed
  */
 public function validateString($string)
 {
     $tokenizer = $this->options->tokenizer;
     $parser = new ezcDocumentWikiParser();
     // Only halt on parse errors, and collect all other errors.
     $parser->options->errorReporting = E_PARSE;
     $errors = array();
     $ast = null;
     try {
         // Try to parse the document and keep the parse tree for evetual
         // checking for decoration errors
         $ast = $parser->parse($tokenizer->tokenizeString($string));
     } catch (ezcDocumentParserException $e) {
         $errors[] = $e;
     }
     // Get errors and notices from parsed document
     $errors = array_merge($errors, $parser->errors);
     // If we had no parse error until now, we also try to decorate the
     // document, which may leed to another class of errors.
     if ($ast !== null) {
         $oldErrorReporting = $this->options->errorReporting;
         $this->options->errorReporting = E_PARSE;
         try {
             $visitor = new ezcDocumentWikiDocbookVisitor($this, $this->path);
             $visitor->visit($ast, $this->path);
             // Get errors and notices from parsed document
             $errors = array_merge($errors, $visitor->getErrors());
         } catch (ezcDocumentVisitException $e) {
             $errors[] = $e;
         }
         // Reset error reporting
         $this->options->errorReporting = $oldErrorReporting;
     }
     if (count($errors) === 0) {
         // If no problem could be found, jsut return true
         return true;
     } else {
         // Transform aggregated errors into validation errors
         foreach ($errors as $nr => $error) {
             $errors[$nr] = ezcDocumentValidationError::createFromException($error);
         }
         return $errors;
     }
 }
Esempio n. 2
0
File: odt.php Progetto: bmdevel/ezc
 /**
  * Performs the actual validation on the given $document.
  *
  * Returns true on success, an array of errors otherwise.
  * 
  * @param DOMDocument $document 
  * @return array(ezcDocumentValidationError)|true
  */
 private function performValidation(DOMDocument $document)
 {
     $document->relaxNGValidate(dirname(__FILE__) . '/odt/data/odf_1.2.rng');
     // Get all errors
     $xmlErrors = libxml_get_errors();
     $errors = array();
     foreach ($xmlErrors as $error) {
         $errors[] = ezcDocumentValidationError::createFromLibXmlError($error);
     }
     libxml_clear_errors();
     return count($errors) ? $errors : true;
 }
Esempio n. 3
0
 /**
  * Validate the input string
  *
  * Validate the input string against the specification of the current
  * document format.
  *
  * Returns true, if the validation succeded, and an array with
  * ezcDocumentValidationError objects otherwise.
  *
  * @param string $string
  * @return mixed
  */
 public function validateString($string)
 {
     $oldSetting = libxml_use_internal_errors(true);
     libxml_clear_errors();
     $document = new DOMDocument();
     $document->loadXml($string);
     $document->relaxNGValidate($this->options->relaxNgSchema);
     // Get all errors
     $xmlErrors = libxml_get_errors();
     $errors = array();
     foreach ($xmlErrors as $error) {
         $errors[] = ezcDocumentValidationError::createFromLibXmlError($error);
     }
     libxml_clear_errors();
     libxml_use_internal_errors($oldSetting);
     return count($errors) ? $errors : true;
 }
Esempio n. 4
0
 /**
  * Validate the input string
  *
  * Validate the input string against the specification of the current
  * document format.
  *
  * Returns true, if the validation succeded, and an array with
  * ezcDocumentValidationError objects otherwise.
  *
  * @param string $string
  * @return mixed
  */
 public function validateString($string)
 {
     $oldSetting = libxml_use_internal_errors(true);
     libxml_clear_errors();
     $document = new DOMDocument();
     $document->loadXml($string);
     $document->schemaValidate(dirname(__FILE__) . '/xhtml/schema/xhtml1-transitional.xsd');
     // Get all errors
     $xmlErrors = libxml_get_errors();
     $errors = array();
     foreach ($xmlErrors as $error) {
         $errors[] = ezcDocumentValidationError::createFromLibXmlError($error);
     }
     libxml_clear_errors();
     libxml_use_internal_errors($oldSetting);
     return count($errors) ? $errors : true;
 }